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

273 рядки
8.7 KiB

  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. wn.ui.toolbar.Toolbar = Class.extend({
  23. init: function() {
  24. this.make();
  25. //this.make_modules();
  26. this.make_file();
  27. wn.ui.toolbar.recent = new wn.ui.toolbar.RecentDocs();
  28. wn.ui.toolbar.bookmarks = new wn.ui.toolbar.Bookmarks();
  29. this.make_tools();
  30. this.set_user_name();
  31. this.make_logout();
  32. this.make_notification();
  33. $('.dropdown-toggle').dropdown();
  34. $(document).trigger('toolbar_setup');
  35. // clear all custom menus on page change
  36. $(document).on("page-change", function() {
  37. $("header .navbar .custom-menu").remove();
  38. })
  39. },
  40. make: function() {
  41. $('header').append('<div class="navbar navbar-fixed-top navbar-inverse" style="min-height: 50px;">\
  42. <div class="container">\
  43. <button type="button" class="navbar-toggle" data-toggle="collapse" \
  44. data-target=".navbar-responsive-collapse">\
  45. <span class="icon-bar"></span>\
  46. <span class="icon-bar"></span>\
  47. <span class="icon-bar"></span>\
  48. </button>\
  49. <a class="navbar-brand" href="#"></a>\
  50. <div class="nav-collapse collapse navbar-responsive-collapse">\
  51. <ul class="nav navbar-nav">\
  52. </ul>\
  53. <img src="lib/images/ui/spinner.gif" id="spinner"/>\
  54. <ul class="nav navbar-nav pull-right">\
  55. <li class="dropdown">\
  56. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  57. onclick="return false;" id="toolbar-user-link"></a>\
  58. <ul class="dropdown-menu" id="toolbar-user">\
  59. </ul>\
  60. </li>\
  61. </ul>\
  62. </div>\
  63. </div>\
  64. </div>');
  65. },
  66. make_home: function() {
  67. $('.navbar-brand').attr('href', "#");
  68. },
  69. make_notification: function() {
  70. $('.navbar .pull-right').append('<li class="dropdown">\
  71. <a class="dropdown-toggl" href="#" data-toggle="dropdown"\
  72. title="'+wn._("Unread Messages")+'"\
  73. onclick="return false;"><span class="navbar-new-comments">0</span></a>\
  74. <ul class="dropdown-menu" id="navbar-notification">\
  75. </ul>\
  76. </li>');
  77. $(document).on("notification-update", function() {
  78. wn.ui.toolbar.update_notifications();
  79. })
  80. },
  81. // make_modules: function() {
  82. // $('<li class="dropdown">\
  83. // <a class="dropdown-toggle" data-toggle="dropdown" href="#"\
  84. // title="'+wn._("Modules")+'"\
  85. // onclick="return false;">'+wn._("Modules")+'</a>\
  86. // <ul class="dropdown-menu modules">\
  87. // </ul>\
  88. // </li>').prependTo('.navbar .nav:first');
  89. //
  90. // var modules_list = wn.user.get_desktop_items().sort();
  91. // var menu_list = $(".navbar .modules");
  92. //
  93. // var _get_list_item = function(m) {
  94. // args = {
  95. // module: m,
  96. // module_page: wn.modules[m].link,
  97. // module_label: wn._(wn.modules[m].label || m),
  98. // icon: wn.modules[m].icon
  99. // }
  100. //
  101. // return repl('<li><a href="#%(module_page)s" \
  102. // data-module="%(module)s"><i class="%(icon)s" style="display: inline-block; \
  103. // width: 21px; margin-top: -2px; margin-left: -7px;"></i>\
  104. // %(module_label)s</a></li>', args);
  105. // }
  106. //
  107. // // desktop
  108. // $('<li><a href="#desktop"><i class="icon-th"></i> '
  109. // + wn._("Desktop") + '</a></li>\
  110. // <li class="divider"></li>').appendTo(menu_list)
  111. //
  112. // // add to dropdown
  113. // $.each(modules_list,function(i, m) {
  114. // if(m!='Setup') {
  115. // menu_list.append(_get_list_item(m));
  116. // }
  117. // })
  118. //
  119. // // setup for system manager
  120. // if(user_roles.indexOf("System Manager")!=-1) {
  121. // menu_list.append('<li class="divider">' + _get_list_item("Setup"));
  122. // }
  123. //
  124. // },
  125. make_file: function() {
  126. wn.ui.toolbar.new_dialog = new wn.ui.toolbar.NewDialog();
  127. wn.ui.toolbar.search = new wn.ui.toolbar.Search();
  128. wn.ui.toolbar.report = new wn.ui.toolbar.Report();
  129. $('.navbar .nav:first').append('<li class="dropdown">\
  130. <a class="dropdown-toggle" href="#" data-toggle="dropdown"\
  131. title="'+wn._("File")+'"\
  132. onclick="return false;">'+wn._("File")+'</a>\
  133. <ul class="dropdown-menu" id="navbar-file">\
  134. <li><a href="#" onclick="return wn.ui.toolbar.new_dialog.show();">\
  135. <i class="icon-plus"></i> '+wn._('New')+'...</a></li>\
  136. <li><a href="#" onclick="return wn.ui.toolbar.search.show();">\
  137. <i class="icon-search"></i> '+wn._('Search')+'...</a></li>\
  138. <li><a href="#" onclick="return wn.ui.toolbar.report.show();">\
  139. <i class="icon-list"></i> '+wn._('Report')+'...</a></li>\
  140. </ul>\
  141. </li>');
  142. },
  143. make_tools: function() {
  144. $('.navbar .nav:first').append('<li class="dropdown">\
  145. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  146. title="'+wn._("Tools")+'"\
  147. onclick="return false;">'+wn._("Tools")+'</a>\
  148. <ul class="dropdown-menu" id="toolbar-tools">\
  149. <li><a href="#" onclick="return wn.ui.toolbar.clear_cache();">'
  150. +wn._('Clear Cache & Refresh')+'</a></li>\
  151. <li><a href="#" onclick="return wn.ui.toolbar.show_about();">'
  152. +wn._('About')+'</a></li>\
  153. <li><a href="#attributions">'
  154. +wn._('Attributions')+'</a></li>\
  155. </ul>\
  156. </li>');
  157. if(has_common(user_roles,['Administrator','System Manager'])) {
  158. $('#toolbar-tools').append('<li><a href="#" \
  159. onclick="return wn.ui.toolbar.download_backup();">'
  160. +wn._('Download Backup')+'</a></li>');
  161. }
  162. },
  163. set_user_name: function() {
  164. var fn = user_fullname;
  165. if(fn.length > 15) fn = fn.substr(0,12) + '...';
  166. $('#toolbar-user-link').html(fn + '<b class="caret"></b>');
  167. },
  168. make_logout: function() {
  169. // logout
  170. $('#toolbar-user').append('<li><a href="#" onclick="return wn.app.logout();">'
  171. +wn._('Logout')+'</a></li>');
  172. }
  173. });
  174. wn.ui.toolbar.update_notifications = function() {
  175. var total = 0;
  176. var doctypes = keys(wn.boot.notification_info.open_count_doctype).sort();
  177. var modules = keys(wn.boot.notification_info.open_count_module).sort();
  178. $("#navbar-notification").empty();
  179. $.each(modules, function(i, module) {
  180. var count = wn.boot.notification_info.open_count_module[module];
  181. if(count) {
  182. $(repl('<li><a>\
  183. <span class="badge pull-right">\
  184. %(count)s</span> \
  185. <i class="icon-fixed-width %(icon)s"></i> %(module)s </a></li>', {
  186. module: module,
  187. count: count,
  188. icon: wn.modules[module].icon
  189. }))
  190. .appendTo("#navbar-notification")
  191. .find("a")
  192. .attr("data-module", module)
  193. .css({"min-width":"200px"})
  194. .on("click", function() {
  195. wn.set_route(wn.modules[$(this).attr("data-module")].link);
  196. });
  197. total += count;
  198. }
  199. });
  200. if(total) {
  201. $('<li class="divider"></li>').appendTo("#navbar-notification");
  202. }
  203. $.each(doctypes, function(i, doctype) {
  204. var count = wn.boot.notification_info.open_count_doctype[doctype];
  205. if(count) {
  206. $(repl('<li><a>\
  207. <span class="badge pull-right">\
  208. %(count)s</span> \
  209. <i class="icon-fixed-width %(icon)s"></i> %(doctype)s </a></li>', {
  210. doctype: doctype,
  211. icon: wn.boot.doctype_icons[doctype],
  212. count: count
  213. }))
  214. .appendTo("#navbar-notification")
  215. .find("a")
  216. .attr("data-doctype", doctype)
  217. .css({"min-width":"200px"})
  218. .on("click", function() {
  219. wn.views.show_open_count_list(this);
  220. });
  221. total += count;
  222. }
  223. });
  224. $(".navbar-new-comments")
  225. .html(total)
  226. .toggleClass("navbar-new-comments-true", total ? true : false);
  227. }
  228. wn.ui.toolbar.clear_cache = function() {
  229. localStorage && localStorage.clear();
  230. $c('webnotes.sessions.clear',{},function(r,rt){
  231. if(!r.exc) {
  232. show_alert(r.message);
  233. location.reload();
  234. }
  235. });
  236. return false;
  237. }
  238. wn.ui.toolbar.download_backup = function() {
  239. msgprint(wn._("Your download is being built, this may take a few moments..."));
  240. $c('webnotes.utils.backups.get_backup',{},function(r,rt) {});
  241. return false;
  242. }
  243. wn.ui.toolbar.show_about = function() {
  244. try {
  245. wn.ui.misc.about();
  246. } catch(e) {
  247. console.log(e);
  248. }
  249. return false;
  250. }