You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

110 lines
3.2 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. wn.pages['Setup'].onload = function(wrapper) {
  4. if(msg_dialog && msg_dialog.display) msg_dialog.hide();
  5. wn.ui.make_app_page({
  6. parent: wrapper,
  7. title: wn._('Setup'),
  8. single_column: true
  9. });
  10. wrapper.appframe.add_module_icon("Setup");
  11. wrapper.appframe.set_title_right(wn._("Refresh"), function() {
  12. wn.setup.make(wrapper);
  13. });
  14. wn.setup.make(wrapper);
  15. }
  16. wn.setup = {
  17. make: function(wrapper) {
  18. wn.call({
  19. method: "webnotes.core.page.setup.setup.get",
  20. callback: function(r) {
  21. wn.setup.render(r.message, $(wrapper).find(".layout-main").empty())
  22. }
  23. })
  24. },
  25. render: function(data, wrapper) {
  26. $('<div class="row">\
  27. <div class="col-sm-3">\
  28. <ul class="nav nav-pills nav-stacked"></ul>\
  29. </div>\
  30. <div class="col-sm-9 contents">\
  31. </div>\
  32. </div>').appendTo(wrapper);
  33. var $sections = wrapper.find(".nav-pills");
  34. $.each(data, function(i, d) {
  35. d._label = d.label.toLowerCase().replace(/ /g, "_");
  36. var $nav = $sections.find('[data-label="'+d._label+'"]');
  37. if(!$sections.find('[data-label="'+d._label+'"]').length) {
  38. $nav = $('<li><a><i class="'+d.icon+' icon-fixed-width"></i> '
  39. + wn._(d.label)+'</a></li>')
  40. .attr("data-label", d._label)
  41. .appendTo($sections);
  42. var $content = $('<div class="panel panel-default"></div>')
  43. .toggle(false)
  44. .attr("id", d._label)
  45. .appendTo(wrapper.find(".contents"))
  46. $('<div class="panel-heading">').appendTo($content).html('<i class="'+d.icon+'"></i> '
  47. + d.label);
  48. var $list = $('<ul class="list-group">').appendTo($content);
  49. } else {
  50. var $content = $("#" + d._label);
  51. var $list = $content.find(".list-group");
  52. }
  53. // add items
  54. $.each(d.items, function(i, item) {
  55. if((item.type==="doctype" && wn.model.can_read(item.name))
  56. || (item.type==="page" && wn.boot.page_info[item.name])) {
  57. if(!item.label) {
  58. item.label = item.name;
  59. }
  60. if(item.type==="doctype") {
  61. item.icon = wn.boot.doctype_icons[item.name];
  62. }
  63. $list_item = $($r('<li class="list-group-item">\
  64. <div class="row">\
  65. <div class="col-xs-4"><a><i class="%(icon)s icon-fixed-width"></i> %(label)s</a></div>\
  66. <div class="col-xs-8 text-muted">%(description)s</div>\
  67. </div>\
  68. </li>', item)).appendTo($list);
  69. $list_item.find("a")
  70. .attr("data-type", item.type)
  71. .attr("data-name", item.link || item.name)
  72. .on("click", function() {
  73. if($(this).attr("data-type")==="doctype") {
  74. wn.set_route("List", $(this).attr("data-name"))
  75. }
  76. else if($(this).attr("data-type")==="page") {
  77. wn.set_route($(this).attr("data-name"))
  78. }
  79. });
  80. }
  81. })
  82. })
  83. // section selection (can't use tab api - routing)
  84. $sections.find('a').click(function (e) {
  85. e.preventDefault();
  86. if($(this).parent().hasClass("active")) {
  87. return;
  88. }
  89. $(this).parents("ul:first").find("li.active").removeClass("active");
  90. $(this).parent().addClass("active");
  91. wrapper.find(".panel").toggle(false);
  92. $("#" + $(this).parent().attr("data-label")).toggle(true);
  93. });
  94. $sections.find('a:first').trigger("click");
  95. }
  96. }