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.
 
 
 
 
 
 

214 line
6.9 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_erpnext();
  26. this.make_file();
  27. this.make_view();
  28. //this.make_actions();
  29. wn.ui.toolbar.recent = new wn.ui.toolbar.RecentDocs();
  30. wn.ui.toolbar.bookmarks = new wn.ui.toolbar.Bookmarks();
  31. this.make_tools();
  32. this.set_user_name();
  33. this.make_logout();
  34. $('.dropdown-toggle').dropdown();
  35. $(document).trigger('toolbar_setup');
  36. // clear all custom menus on page change
  37. $(document).on("page-change", function() {
  38. $("header .navbar .custom-menu").remove();
  39. })
  40. },
  41. make: function() {
  42. $('header').append('<div class="navbar navbar-fixed-top navbar-inverse">\
  43. <div class="container">\
  44. <button type="button" class="navbar-toggle" data-toggle="collapse" \
  45. data-target=".navbar-responsive-collapse">\
  46. <span class="icon-bar"></span>\
  47. <span class="icon-bar"></span>\
  48. <span class="icon-bar"></span>\
  49. </button>\
  50. <div class="nav-collapse collapse navbar-responsive-collapse">\
  51. <ul class="nav">\
  52. </ul>\
  53. <img src="lib/images/ui/spinner.gif" id="spinner"/>\
  54. <ul class="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_erpnext: function() {
  70. $('<li class="dropdown">\
  71. <a class="dropdown-toggle" data-toggle="dropdown" href="#"\
  72. title="'+wn._("ERPNext")+'"\
  73. onclick="return false;"><b>ERPNext</b></a>\
  74. <ul class="dropdown-menu modules">\
  75. </ul>\
  76. </li>').prependTo('.navbar .nav:first');
  77. var modules_list = wn.user.get_desktop_items().sort();
  78. var menu_list = $(".navbar .modules");
  79. var _get_list_item = function(m) {
  80. args = {
  81. module: m,
  82. module_page: wn.modules[m].link,
  83. module_label: wn._(wn.modules[m].label || m),
  84. icon: wn.modules[m].icon
  85. }
  86. return repl('<li><a href="#%(module_page)s" \
  87. data-module="%(module)s"><i class="%(icon)s" style="display: inline-block; \
  88. width: 21px; margin-top: -2px; margin-left: -7px;"></i>\
  89. %(module_label)s</a></li>', args);
  90. }
  91. // desktop
  92. $('<li><a href="#desktop"><i class="icon-th"></i> '
  93. + wn._("Desktop") + '</a></li>\
  94. <li class="divider"></li>').appendTo(menu_list)
  95. // add to dropdown
  96. $.each(modules_list,function(i, m) {
  97. if(m!='Setup') {
  98. menu_list.append(_get_list_item(m));
  99. }
  100. })
  101. // setup for system manager
  102. if(user_roles.indexOf("System Manager")!=-1) {
  103. menu_list.append('<li class="divider">' + _get_list_item("Setup"));
  104. }
  105. },
  106. make_file: function() {
  107. wn.ui.toolbar.new_dialog = new wn.ui.toolbar.NewDialog();
  108. wn.ui.toolbar.search = new wn.ui.toolbar.Search();
  109. wn.ui.toolbar.report = new wn.ui.toolbar.Report();
  110. $('.navbar .nav:first').append('<li class="dropdown">\
  111. <a class="dropdown-toggle" href="#" data-toggle="dropdown"\
  112. title="'+wn._("File")+'"\
  113. onclick="return false;">'+wn._("File")+'</a>\
  114. <ul class="dropdown-menu" id="navbar-file">\
  115. <li><a href="#" onclick="return wn.ui.toolbar.new_dialog.show();">\
  116. <i class="icon-plus"></i> '+wn._('New')+'...</a></li>\
  117. <li><a href="#" onclick="return wn.ui.toolbar.search.show();">\
  118. <i class="icon-search"></i> '+wn._('Search')+'...</a></li>\
  119. <li><a href="#" onclick="return wn.ui.toolbar.report.show();">\
  120. <i class="icon-list"></i> '+wn._('Report')+'...</a></li>\
  121. </ul>\
  122. </li>');
  123. },
  124. make_view: function() {
  125. $('.navbar .nav:first').append('<li class="dropdown">\
  126. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  127. title="'+wn._("View")+'"\
  128. onclick="return false;">'+wn._("View")+'</a>\
  129. <ul class="dropdown-menu" id="navbar-view">\
  130. </ul>\
  131. </li>');
  132. },
  133. // make_actions: function() {
  134. // $('.navbar .nav:first').append('<li class="dropdown">\
  135. // <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  136. // title="'+wn._("Actions")+'"\
  137. // onclick="return false;">'+wn._("Actions")+'</a>\
  138. // <ul class="dropdown-menu" id="navbar-actions">\
  139. // </ul>\
  140. // </li>');
  141. // },
  142. make_tools: function() {
  143. $('.navbar .nav:first').append('<li class="dropdown">\
  144. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  145. title="'+wn._("Tools")+'"\
  146. onclick="return false;">Tools</a>\
  147. <ul class="dropdown-menu" id="toolbar-tools">\
  148. <li><a href="#" onclick="return wn.ui.toolbar.clear_cache();">'
  149. +wn._('Clear Cache & Refresh')+'</a></li>\
  150. <li><a href="#" onclick="return wn.ui.toolbar.show_about();">'
  151. +wn._('About')+'</a></li>\
  152. </ul>\
  153. </li>');
  154. if(has_common(user_roles,['Administrator','System Manager'])) {
  155. $('#toolbar-tools').append('<li><a href="#" \
  156. onclick="return wn.ui.toolbar.download_backup();">'
  157. +wn._('Download Backup')+'</a></li>');
  158. }
  159. },
  160. set_user_name: function() {
  161. var fn = user_fullname;
  162. if(fn.length > 15) fn = fn.substr(0,12) + '...';
  163. $('#toolbar-user-link').html(fn + '<b class="caret"></b>');
  164. },
  165. make_logout: function() {
  166. // logout
  167. $('#toolbar-user').append('<li><a href="#" onclick="return wn.app.logout();">'
  168. +wn._('Logout')+'</a></li>');
  169. }
  170. });
  171. wn.ui.toolbar.clear_cache = function() {
  172. localStorage && localStorage.clear();
  173. $c('webnotes.sessions.clear',{},function(r,rt){
  174. if(!r.exc) {
  175. show_alert(r.message);
  176. location.reload();
  177. }
  178. });
  179. return false;
  180. }
  181. wn.ui.toolbar.download_backup = function() {
  182. msgprint(wn._("Your download is being built, this may take a few moments..."));
  183. $c('webnotes.utils.backups.get_backup',{},function(r,rt) {});
  184. return false;
  185. }
  186. wn.ui.toolbar.show_about = function() {
  187. try {
  188. wn.ui.misc.about();
  189. } catch(e) {
  190. console.log(e);
  191. }
  192. return false;
  193. }