Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

265 рядки
7.7 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.module_page");
  5. wn.home_page = "desktop";
  6. wn.views.moduleview.make = function(wrapper, module) {
  7. wrapper.module_view = new wn.views.moduleview.ModuleView(wrapper, module);
  8. wrapper.refresh = function() {
  9. // remake on refresh
  10. if((new Date() - wrapper.module_view.created_on) > (180 * 1000)) {
  11. wrapper.module_view = new wn.views.moduleview.ModuleView(wrapper, module);
  12. }
  13. }
  14. }
  15. wn.views.show_open_count_list = function(element) {
  16. var doctype = $(element).attr("data-doctype");
  17. var condition = wn.boot.notification_info.conditions[doctype];
  18. if(condition) {
  19. wn.route_options = condition;
  20. var route = wn.get_route()
  21. if(route[0]==="List" && route[1]===doctype) {
  22. wn.pages["List/" + doctype].doclistview.refresh();
  23. } else {
  24. wn.set_route("List", doctype);
  25. }
  26. }
  27. }
  28. wn.views.moduleview.ModuleView = Class.extend({
  29. init: function(wrapper, module) {
  30. this.doctypes = [];
  31. this.top_item_total = {};
  32. this.top_item_open = {};
  33. $(wrapper).empty();
  34. wn.ui.make_app_page({
  35. parent: wrapper,
  36. single_column: true,
  37. title: wn._(wn.modules[module] && wn.modules[module].label || module)
  38. });
  39. wrapper.appframe.add_module_icon(module);
  40. this.wrapper = wrapper;
  41. this.module = module;
  42. this.make_body();
  43. this.render_static();
  44. this.render_dynamic();
  45. this.created_on = new Date();
  46. var me = this;
  47. $(document).on("notification-update", function() {
  48. me.update_open_count();
  49. });
  50. },
  51. make_body: function() {
  52. var wrapper = this.wrapper;
  53. // make columns
  54. $(wrapper).find(".layout-main").html("<div class='row module-top'></div>\
  55. <div class='row'>\
  56. <div class='col col-lg-6 main-section'></div>\
  57. <div class='col col-lg-6 side-section'></div>\
  58. </div>")
  59. $(wrapper).on("click", ".badge-important", function() {
  60. wn.views.show_open_count_list(this);
  61. });
  62. $(wrapper).on("click", ".badge-count", function() {
  63. var doctype = $(this).attr("data-doctype-count");
  64. wn.set_route("List", doctype);
  65. });
  66. },
  67. add_section: function(section) {
  68. section._title = wn._(section.title);
  69. if(section.top) {
  70. var module_top = $(this.wrapper).find(".module-top");
  71. var list_group = $('<div>')
  72. .appendTo(module_top);
  73. $('<div class="col col-lg-12"><hr /></div>').appendTo(module_top);
  74. } else {
  75. var list_group = $('<ul class="list-group">\
  76. <li class="list-group-item" style="background-color: #eee">\
  77. <h4 class="list-group-item-heading" style="margin-bottom: 0px;">\
  78. <i class="text-muted '+ section.icon+'"></i> '
  79. + wn._(section.title) +'</h4>\
  80. </li>\
  81. </ul>"').appendTo(section.right
  82. ? $(this.wrapper).find(".side-section")
  83. : $(this.wrapper).find(".main-section"));
  84. }
  85. section.list_group = list_group;
  86. },
  87. add_item: function(item, section) {
  88. if(!item.description) item.description = "";
  89. if(item.count==null) item.count = "";
  90. if(!item.icon) item.icon = "";
  91. if(section.top) {
  92. var $parent = $(repl('<div class="col col-lg-4">\
  93. <div class="alert alert-badge"></div></div>'))
  94. .appendTo(section.list_group)
  95. .find(".alert");
  96. this.top_item_total[item.doctype] = 0;
  97. } else {
  98. var $parent = $('<li class="list-group-item">').appendTo(section.list_group);
  99. }
  100. $(repl('%(icon)s<span' +
  101. ((item.doctype && item.description)
  102. ? " data-doctype='"+item.doctype+"'"
  103. : "") + ">%(link)s</span>"
  104. + ((item.description && !section.top)
  105. ? " <span class='text-muted small'>%(description)s</span>"
  106. : "")
  107. + ((section.right || !item.doctype)
  108. ? ''
  109. : '<span data-doctype-count="%(doctype)s" style="margin-left: 2px;"></span>'), item))
  110. .appendTo($parent);
  111. if(!section.top) {
  112. $('<span class="clearfix"></span>').appendTo($parent);
  113. }
  114. },
  115. set_top_item_count: function(doctype, count, open_count) {
  116. return;
  117. var me = this;
  118. if(this.top_item_total[doctype]!=null) {
  119. if(count!=null)
  120. this.top_item_total[doctype] = count;
  121. if(open_count!=null)
  122. this.top_item_open[doctype] = open_count;
  123. var maxtop = Math.max.apply(this, values(this.top_item_total));
  124. $.each(this.top_item_total, function(doctype, item_count) {
  125. $(me.wrapper).find(".module-item-progress[data-doctype='"+ doctype +"']")
  126. .find(".module-item-progress-total")
  127. .css("width", cint(flt(item_count)/maxtop*100) + "%")
  128. })
  129. $.each(this.top_item_open, function(doctype, item_count) {
  130. $(me.wrapper).find(".module-item-progress[data-doctype='"+ doctype +"']")
  131. .find(".module-item-progress-open")
  132. .css("width", cint(flt(item_count)/me.top_item_total[doctype]*100) + "%")
  133. })
  134. }
  135. },
  136. render_static: function() {
  137. // render sections
  138. var me = this;
  139. $.each(wn.module_page[this.module], function(i, section) {
  140. me.add_section(section);
  141. $.each(section.items, function(i, item) {
  142. if(item.doctype) {
  143. me.doctypes.push(item.doctype);
  144. item.icon = '<i class="icon-fixed-width '+ wn.boot.doctype_icons[item.doctype] + '"></i> ';
  145. }
  146. if(item.doctype && !item.route) {
  147. item.route = "List/" + encodeURIComponent(item.doctype);
  148. }
  149. if(item.page && !item.route) {
  150. item.route = item.page;
  151. }
  152. if(item.page) {
  153. item.icon = '<i class="icon-fixed-width '+ wn.boot.doctype_icons[item.page] + '"></i> ';
  154. }
  155. // link
  156. item.link = repl("<a href='#%(route)s'>%(label)s</a>", item);
  157. // doctype permissions
  158. if(item.doctype && !wn.model.can_read(item.doctype)) {
  159. //item.link = item.label;
  160. return;
  161. }
  162. // page permissions
  163. if(item.page && !in_list(wn.boot.allowed_pages, item.page)) {
  164. //item.link = item.label;
  165. return;
  166. }
  167. if((item.country && wn.boot.control_panel.country==item.country)
  168. || !item.country)
  169. me.add_item(item, section)
  170. });
  171. if(section.list_group.find("li").length==1) {
  172. section.list_group.toggle(false);
  173. }
  174. });
  175. },
  176. render_dynamic: function() {
  177. // render reports
  178. var me = this;
  179. wn.call({
  180. method: "webnotes.widgets.moduleview.get_data",
  181. args: {
  182. module: me.module,
  183. doctypes: me.doctypes
  184. },
  185. callback: function(r) {
  186. if(r.message) {
  187. // reports
  188. if(r.message.reports.length) {
  189. var section = {
  190. title: wn._("Custom Reports"),
  191. right: true,
  192. icon: "icon-list",
  193. }
  194. me.add_section(section);
  195. $.each(r.message.reports, function(i, item) {
  196. if(wn.model.can_read(item.doctype)) {
  197. if(item.is_query_report) {
  198. item.link = repl("<a href=\"#query-report/%(name)s\">%(name)s</a>",
  199. item);
  200. } else {
  201. item.link = repl("<a href=\"#Report/%(doctype)s/%(name)s\">\
  202. %(name)s</a>", item);
  203. }
  204. me.add_item(item, section);
  205. }
  206. })
  207. }
  208. // counts
  209. if(r.message.item_count) {
  210. $.each(r.message.item_count, function(doctype, count) {
  211. $(me.wrapper).find("[data-doctype-count='"+doctype+"']")
  212. .html(count)
  213. .addClass("badge badge-count pull-right")
  214. .css({cursor:"pointer"});
  215. me.set_top_item_count(doctype, count)
  216. })
  217. }
  218. // open-counts
  219. me.update_open_count();
  220. }
  221. }
  222. });
  223. },
  224. update_open_count: function() {
  225. var me = this;
  226. $(me.wrapper).find(".badge-important").remove();
  227. if(wn.boot.notification_info.open_count_doctype) {
  228. $.each(wn.boot.notification_info.open_count_doctype, function(doctype, count) {
  229. if(in_list(me.doctypes, doctype)) {
  230. me.set_top_item_count(doctype, null, count);
  231. $('<span>')
  232. .css({
  233. "cursor": "pointer",
  234. "margin-right": "0px"
  235. })
  236. .addClass("badge badge-important pull-right")
  237. .html(count)
  238. .attr("data-doctype", doctype)
  239. .insertAfter($(me.wrapper)
  240. .find("[data-doctype-count='"+doctype+"']"));
  241. }
  242. })
  243. }
  244. }
  245. });