Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

186 righe
6.1 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" 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. <div class="nav-collapse collapse navbar-responsive-collapse">\
  50. <ul class="nav">\
  51. </ul>\
  52. <img src="lib/images/ui/spinner.gif" id="spinner"/>\
  53. <ul class="nav pull-right">\
  54. <li class="dropdown">\
  55. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  56. onclick="return false;" id="toolbar-user-link"></a>\
  57. <ul class="dropdown-menu" id="toolbar-user">\
  58. </ul>\
  59. </li>\
  60. </ul>\
  61. </div>\
  62. </div>\
  63. </div>');
  64. },
  65. make_home: function() {
  66. $('.navbar-brand').attr('href', "#");
  67. },
  68. make_erpnext: function() {
  69. $('<li class="dropdown">\
  70. <a class="dropdown-toggle" data-toggle="dropdown" href="#"\
  71. title="'+wn._("ERPNext")+'"\
  72. onclick="return false;"><b>ERPNext</b></a>\
  73. <ul class="dropdown-menu modules">\
  74. </ul>\
  75. </li>').prependTo('.navbar .nav:first');
  76. var modules_list = wn.user.get_desktop_items().sort();
  77. var _get_list_item = function(m) {
  78. args = {
  79. module: m,
  80. module_page: wn.modules[m].link,
  81. module_label: wn._(wn.modules[m].label || m),
  82. icon: wn.modules[m].icon
  83. }
  84. return repl('<li><a href="#!%(module_page)s" \
  85. data-module="%(module)s"><i class="%(icon)s" style="display: inline-block; \
  86. width: 21px; margin-top: -2px; margin-left: -7px;"></i>\
  87. %(module_label)s</a></li>', args);
  88. }
  89. // add to dropdown
  90. $.each(modules_list,function(i, m) {
  91. if(m!='Setup') {
  92. $('.navbar .modules').append(_get_list_item(m));
  93. }
  94. })
  95. // setup for system manager
  96. if(user_roles.indexOf("System Manager")!=-1) {
  97. $('.navbar .modules').append('<li class="divider">' + _get_list_item("Setup"));
  98. }
  99. },
  100. make_file: function() {
  101. wn.ui.toolbar.new_dialog = new wn.ui.toolbar.NewDialog();
  102. wn.ui.toolbar.search = new wn.ui.toolbar.Search();
  103. wn.ui.toolbar.report = new wn.ui.toolbar.Report();
  104. $('.navbar .nav:first').append('<li class="dropdown">\
  105. <a class="dropdown-toggle" href="#" data-toggle="dropdown"\
  106. title="'+wn._("File")+'"\
  107. onclick="return false;">File</a>\
  108. <ul class="dropdown-menu" id="navbar-file">\
  109. <li><a href="#" onclick="return wn.ui.toolbar.new_dialog.show();">\
  110. <i class="icon-plus"></i> '+wn._('New')+'...</a></li>\
  111. <li><a href="#" onclick="return wn.ui.toolbar.search.show();">\
  112. <i class="icon-search"></i> '+wn._('Search')+'...</a></li>\
  113. <li><a href="#" onclick="return wn.ui.toolbar.report.show();">\
  114. <i class="icon-list"></i> '+wn._('Report')+'...</a></li>\
  115. </ul>\
  116. </li>');
  117. },
  118. make_tools: function() {
  119. $('.navbar .nav:first').append('<li class="dropdown">\
  120. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  121. title="'+wn._("Tools")+'"\
  122. onclick="return false;">Tools</a>\
  123. <ul class="dropdown-menu" id="toolbar-tools">\
  124. <li><a href="#" onclick="return wn.ui.toolbar.clear_cache();">'
  125. +wn._('Clear Cache & Refresh')+'</a></li>\
  126. <li><a href="#" onclick="return wn.ui.toolbar.show_about();">'
  127. +wn._('About')+'</a></li>\
  128. </ul>\
  129. </li>');
  130. if(has_common(user_roles,['Administrator','System Manager'])) {
  131. $('#toolbar-tools').append('<li><a href="#" \
  132. onclick="return wn.ui.toolbar.download_backup();">'
  133. +wn._('Download Backup')+'</a></li>');
  134. }
  135. },
  136. set_user_name: function() {
  137. var fn = user_fullname;
  138. if(fn.length > 15) fn = fn.substr(0,12) + '...';
  139. $('#toolbar-user-link').html(fn + '<b class="caret"></b>');
  140. },
  141. make_logout: function() {
  142. // logout
  143. $('#toolbar-user').append('<li><a href="#" onclick="return wn.app.logout();">'
  144. +wn._('Logout')+'</a></li>');
  145. }
  146. });
  147. wn.ui.toolbar.clear_cache = function() {
  148. localStorage && localStorage.clear();
  149. $c('webnotes.sessions.clear',{},function(r,rt){
  150. if(!r.exc) {
  151. show_alert(r.message);
  152. location.reload();
  153. }
  154. });
  155. return false;
  156. }
  157. wn.ui.toolbar.download_backup = function() {
  158. msgprint(wn._("Your download is being built, this may take a few moments..."));
  159. $c('webnotes.utils.backups.get_backup',{},function(r,rt) {});
  160. return false;
  161. }
  162. wn.ui.toolbar.show_about = function() {
  163. try {
  164. wn.ui.misc.about();
  165. } catch(e) {
  166. console.log(e);
  167. }
  168. return false;
  169. }