選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

205 行
5.9 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_module_icon(module);
  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='col-span-6 main-section'></div>\
  39. <div class='col-span-6 side-section'></div>\
  40. </div>")
  41. $(wrapper).on("click", ".badge-important", function() {
  42. var doctype = $(this).parent().find("[data-doctype]").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 list_group = $('<ul class="list-group">\
  56. <li class="list-group-item">\
  57. <h4 class="list-group-item-heading"><i class="'
  58. + section.icon+'"></i> '
  59. + wn._(section.title) +'</h4>\
  60. </li>\
  61. </ul>"').appendTo(section.right
  62. ? $(this.wrapper).find(".side-section")
  63. : $(this.wrapper).find(".main-section"));
  64. section.list_group = list_group;
  65. },
  66. add_item: function(item, section) {
  67. if(!item.description) item.description = "";
  68. if(item.count==null) item.count = "";
  69. $(repl('<li class="list-group-item">\
  70. <span' +
  71. ((item.doctype && item.description)
  72. ? " data-doctype='"+item.doctype+"'"
  73. : "") + ">%(link)s</span>"
  74. + (item.description
  75. ? " <span class='text-muted small'>%(description)s</span>"
  76. : "")
  77. + ((section.right || !item.doctype)
  78. ? ''
  79. : '<span data-doctype-count="%(doctype)s" style="margin-left: 17px;"></span>')
  80. + "</li>", item))
  81. .appendTo(section.list_group);
  82. },
  83. render_static: function() {
  84. // render sections
  85. var me = this;
  86. $.each(wn.module_page[this.module], function(i, section) {
  87. me.add_section(section);
  88. $.each(section.items, function(i, item) {
  89. if(item.doctype)
  90. me.doctypes.push(item.doctype);
  91. if(item.doctype && !item.route) {
  92. item.route = "List/" + encodeURIComponent(item.doctype);
  93. }
  94. if(item.page && !item.route) {
  95. item.route = item.page;
  96. }
  97. // link
  98. item.link = repl("<a href='#%(route)s'>%(label)s</a>", item);
  99. // doctype permissions
  100. if(item.doctype && !wn.model.can_read(item.doctype)) {
  101. //item.link = item.label;
  102. return;
  103. }
  104. // page permissions
  105. if(item.page && !in_list(wn.boot.allowed_pages, item.page)) {
  106. //item.link = item.label;
  107. return;
  108. }
  109. if((item.country && wn.boot.control_panel.country==item.country)
  110. || !item.country)
  111. me.add_item(item, section)
  112. });
  113. if(section.list_group.find("li").length==1) {
  114. section.list_group.toggle(false);
  115. }
  116. });
  117. },
  118. render_dynamic: function() {
  119. // render reports
  120. var me = this;
  121. wn.call({
  122. method: "webnotes.widgets.moduleview.get_data",
  123. args: {
  124. module: me.module,
  125. doctypes: me.doctypes
  126. },
  127. callback: function(r) {
  128. if(r.message) {
  129. // reports
  130. if(r.message.reports.length) {
  131. var section = {
  132. title: wn._("Custom Reports"),
  133. right: true,
  134. icon: "icon-list",
  135. }
  136. me.add_section(section);
  137. $.each(r.message.reports, function(i, item) {
  138. if(wn.model.can_read(item.doctype)) {
  139. if(item.is_query_report) {
  140. item.link = repl("<a href=\"#query-report/%(name)s\">%(name)s</a>",
  141. item);
  142. } else {
  143. item.link = repl("<a href=\"#Report2/%(doctype)s/%(name)s\">\
  144. %(name)s</a>", item);
  145. }
  146. me.add_item(item, section);
  147. }
  148. })
  149. }
  150. // search criteria
  151. if(r.message.search_criteria.length) {
  152. var section = {
  153. title: wn._("Old Style Reports"),
  154. right: true,
  155. icon: "icon-list-alt",
  156. }
  157. me.add_section(section);
  158. $.each(r.message.search_criteria, function(i, item) {
  159. item.criteria_name_enc = encodeURIComponent(item.criteria_name);
  160. if(wn.model.can_read(item.parent_doctype || item.doctype)) {
  161. item.link = repl(
  162. "<a href=\"#Report/%(doctype)s/%(criteria_name_enc)s\">\
  163. %(criteria_name)s</a>", item);
  164. me.add_item(item, section);
  165. }
  166. })
  167. }
  168. // counts
  169. if(r.message.item_count) {
  170. $.each(r.message.item_count, function(doctype, count) {
  171. $(me.wrapper).find("[data-doctype-count='"+doctype+"']")
  172. .html(count)
  173. .addClass("badge badge-count")
  174. .css({cursor:"pointer"});
  175. })
  176. }
  177. // counts
  178. if(r.message.open_count) {
  179. $.extend(wn.model.open_count_conditions, r.message.conditions);
  180. $.each(r.message.open_count, function(doctype, count) {
  181. $(me.wrapper).find("[data-doctype='"+doctype+"']")
  182. .parent()
  183. .append(" <span class='badge badge-important'\
  184. style='cursor:pointer; background-color: #b94a48'>" + count + "</span>");
  185. })
  186. }
  187. }
  188. }
  189. });
  190. }
  191. });