您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

202 行
5.8 KiB

  1. // Copyright 2013 Web Notes Technologies Pvt Ltd
  2. // MIT Licensed. See license.txt
  3. wn.provide("wn.views.moduleview");
  4. wn.provide("wn.model.open_count_conditions");
  5. wn.provide("wn.module_page");
  6. wn.home_page = "desktop";
  7. wn.views.moduleview.make = function(wrapper, module) {
  8. wrapper.module_view = new wn.views.moduleview.ModuleView(wrapper, module);
  9. wrapper.refresh = function() {
  10. // remake on refresh
  11. if((new Date() - wrapper.module_view.created_on) > (180 * 1000)) {
  12. wrapper.module_view = new wn.views.moduleview.ModuleView(wrapper, module);
  13. }
  14. }
  15. }
  16. wn.views.moduleview.ModuleView = Class.extend({
  17. init: function(wrapper, module) {
  18. this.doctypes = [];
  19. $(wrapper).empty();
  20. wn.ui.make_app_page({
  21. parent: wrapper,
  22. single_column: true,
  23. title: wn._(wn.modules[module].label || module)
  24. });
  25. wrapper.appframe.add_home_breadcrumb();
  26. wrapper.appframe.add_breadcrumb(wn.modules[module].icon);
  27. this.wrapper = wrapper;
  28. this.module = module;
  29. this.make_body();
  30. this.render_static();
  31. this.render_dynamic();
  32. this.created_on = new Date();
  33. },
  34. make_body: function() {
  35. var wrapper = this.wrapper;
  36. // make columns
  37. $(wrapper).find(".layout-main").html("<div class='row'>\
  38. <div class='span6 main-section'></div>\
  39. <div class='span5 side-section'></div>\
  40. </div>")
  41. $(wrapper).on("click", ".badge-important", function() {
  42. var doctype = $(this).parent().attr("data-doctype");
  43. var condition = wn.model.open_count_conditions[doctype];
  44. if(condition) {
  45. wn.set_route("List", doctype, wn.utils.get_url_from_dict(condition));
  46. }
  47. });
  48. $(wrapper).on("click", ".badge-count", function() {
  49. var doctype = $(this).attr("data-doctype-count");
  50. wn.set_route("List", doctype);
  51. });
  52. },
  53. add_section: function(section) {
  54. section._title = wn._(section.title);
  55. var table = $(repl("<table class='table table-bordered'>\
  56. <thead><tr>\
  57. <th style='font-size: 120%;'><i class='%(icon)s'></i> %(_title)s</th></tr></thead>\
  58. <tbody></tbody>\
  59. </table>", section)).appendTo(section.right
  60. ? $(this.wrapper).find(".side-section")
  61. : $(this.wrapper).find(".main-section"));
  62. section.table = table;
  63. },
  64. add_item: function(item, section) {
  65. if(!item.description) item.description = "";
  66. if(item.count==null) item.count = "";
  67. $(repl("<tr><td><div class='row'>\
  68. <span"+
  69. ((item.doctype && item.description)
  70. ? " data-doctype='"+item.doctype+"'" : "")
  71. +" class='"+(section.right ? 'spanf4' : 'span2')
  72. +"'>%(link)s</span>\
  73. <span class='help "+(section.right ? 'span4' : 'span3')
  74. +"'>%(description)s</span>"
  75. + ((section.right || !item.doctype)
  76. ? ''
  77. : '<span data-doctype-count="%(doctype)s"></span>')
  78. + "</div></td></tr>", item))
  79. .appendTo(section.table.find("tbody"));
  80. },
  81. render_static: function() {
  82. // render sections
  83. var me = this;
  84. $.each(wn.module_page[this.module], function(i, section) {
  85. me.add_section(section);
  86. $.each(section.items, function(i, item) {
  87. if(item.doctype)
  88. me.doctypes.push(item.doctype);
  89. if(item.doctype && !item.route) {
  90. item.route = "List/" + encodeURIComponent(item.doctype);
  91. }
  92. if(item.page && !item.route) {
  93. item.route = item.page;
  94. }
  95. // link
  96. item.link = repl("<a href='#%(route)s'>%(label)s</a>", item);
  97. // doctype permissions
  98. if(item.doctype && !wn.model.can_read(item.doctype)) {
  99. //item.link = item.label;
  100. return;
  101. }
  102. // page permissions
  103. if(item.page && !in_list(wn.boot.allowed_pages, item.page)) {
  104. //item.link = item.label;
  105. return;
  106. }
  107. if((item.country && wn.boot.control_panel.country==item.country)
  108. || !item.country)
  109. me.add_item(item, section)
  110. });
  111. if(section.table.find("tr").length==1) {
  112. section.table.toggle(false);
  113. }
  114. });
  115. },
  116. render_dynamic: function() {
  117. // render reports
  118. var me = this;
  119. wn.call({
  120. method: "webnotes.widgets.moduleview.get_data",
  121. args: {
  122. module: me.module,
  123. doctypes: me.doctypes
  124. },
  125. callback: function(r) {
  126. if(r.message) {
  127. // reports
  128. if(r.message.reports.length) {
  129. var section = {
  130. title: wn._("Custom Reports"),
  131. right: true,
  132. icon: "icon-list",
  133. }
  134. me.add_section(section);
  135. $.each(r.message.reports, function(i, item) {
  136. if(wn.model.can_read(item.doctype)) {
  137. if(item.is_query_report) {
  138. item.link = repl("<a href=\"#query-report/%(name)s\">%(name)s</a>",
  139. item);
  140. } else {
  141. item.link = repl("<a href=\"#Report2/%(doctype)s/%(name)s\">\
  142. %(name)s</a>", item);
  143. }
  144. me.add_item(item, section);
  145. }
  146. })
  147. }
  148. // search criteria
  149. if(r.message.search_criteria.length) {
  150. var section = {
  151. title: wn._("Old Style Reports"),
  152. right: true,
  153. icon: "icon-list-alt",
  154. }
  155. me.add_section(section);
  156. $.each(r.message.search_criteria, function(i, item) {
  157. item.criteria_name_enc = encodeURIComponent(item.criteria_name);
  158. if(wn.model.can_read(item.parent_doctype || item.doctype)) {
  159. item.link = repl(
  160. "<a href=\"#Report/%(doctype)s/%(criteria_name_enc)s\">\
  161. %(criteria_name)s</a>", item);
  162. me.add_item(item, section);
  163. }
  164. })
  165. }
  166. // counts
  167. if(r.message.item_count) {
  168. $.each(r.message.item_count, function(doctype, count) {
  169. $(me.wrapper).find("[data-doctype-count='"+doctype+"']")
  170. .html(count)
  171. .addClass("badge badge-count")
  172. .css({cursor:"pointer"});
  173. })
  174. }
  175. // counts
  176. if(r.message.open_count) {
  177. $.extend(wn.model.open_count_conditions, r.message.conditions);
  178. $.each(r.message.open_count, function(doctype, count) {
  179. $(me.wrapper).find("[data-doctype='"+doctype+"']")
  180. .append(" <span class='badge badge-important pull-right'\
  181. style='cursor:pointer'>" + count + "</span>");
  182. })
  183. }
  184. }
  185. }
  186. });
  187. }
  188. });