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.
 
 
 
 
 
 

107 lines
3.0 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. $nav = $sections.find('[data-label="'+d._label+'"]');
  37. if(!$sections.find('[data-label="'+d._label+'"]').length) {
  38. $nav = $('<li><a><i class="'+d.icon+'"></i> '
  39. + wn._(d.label)+'</a></li>')
  40. .attr("data-label", d._label)
  41. .appendTo($sections);
  42. $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. $list = $('<ul class="list-group">').appendTo($content);
  49. }
  50. // add items
  51. $.each(d.items, function(i, item) {
  52. if((item.type==="doctype" && wn.model.can_read(item.name))
  53. || (item.type==="page" && wn.boot.page_info[item.name])) {
  54. if(!item.label) {
  55. item.label = item.name;
  56. }
  57. if(item.type==="doctype") {
  58. item.icon = wn.boot.doctype_icons[item.name];
  59. }
  60. $list_item = $($r('<li class="list-group-item">\
  61. <div class="row">\
  62. <div class="col-xs-4"><a><i class="%(icon)s"></i> %(label)s</a></div>\
  63. <div class="col-xs-8 text-muted">%(description)s</div>\
  64. </div>\
  65. </li>', item)).appendTo($list);
  66. $list_item.find("a")
  67. .attr("data-type", item.type)
  68. .attr("data-name", item.name)
  69. .on("click", function() {
  70. if($(this).attr("data-type")==="doctype") {
  71. wn.set_route("List", $(this).attr("data-name"))
  72. }
  73. else if($(this).attr("data-type")==="page") {
  74. wn.set_route($(this).attr("data-name"))
  75. }
  76. });
  77. }
  78. })
  79. })
  80. // section selection (can't use tab api - routing)
  81. $sections.find('a').click(function (e) {
  82. e.preventDefault();
  83. if($(this).parent().hasClass("active")) {
  84. return;
  85. }
  86. $(this).parents("ul:first").find("li.active").removeClass("active");
  87. $(this).parent().addClass("active");
  88. wrapper.find(".panel").toggle(false);
  89. $("#" + $(this).parent().attr("data-label")).toggle(true);
  90. });
  91. $sections.find('a:first').trigger("click");
  92. }
  93. }