您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

13 年前
13 年前
13 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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_quick_search();
  27. this.make_file();
  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" style="min-height: 50px;">\
  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. <a class="navbar-brand" href="#"></a>\
  51. <div class="nav-collapse collapse navbar-responsive-collapse">\
  52. <ul class="nav navbar-nav">\
  53. </ul>\
  54. <img src="lib/images/ui/spinner.gif" id="spinner"/>\
  55. <ul class="nav navbar-nav pull-right">\
  56. <li class="dropdown">\
  57. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  58. onclick="return false;" id="toolbar-user-link"></a>\
  59. <ul class="dropdown-menu" id="toolbar-user">\
  60. </ul>\
  61. </li>\
  62. </ul>\
  63. </div>\
  64. </div>\
  65. </div>');
  66. },
  67. make_home: function() {
  68. $('.navbar-brand').attr('href', "#");
  69. },
  70. make_modules: function() {
  71. $('<li class="dropdown">\
  72. <a class="dropdown-toggle" data-toggle="dropdown" href="#"\
  73. title="'+wn._("Modules")+'"\
  74. onclick="return false;">'+wn._("Modules")+'</a>\
  75. <ul class="dropdown-menu modules">\
  76. </ul>\
  77. </li>').prependTo('.navbar .nav:first');
  78. var modules_list = wn.user.get_desktop_items().sort();
  79. var menu_list = $(".navbar .modules");
  80. var _get_list_item = function(m) {
  81. args = {
  82. module: m,
  83. module_page: wn.modules[m].link,
  84. module_label: wn._(wn.modules[m].label || m),
  85. icon: wn.modules[m].icon
  86. }
  87. return repl('<li><a href="#%(module_page)s" \
  88. data-module="%(module)s"><i class="%(icon)s" style="display: inline-block; \
  89. width: 21px; margin-top: -2px; margin-left: -7px;"></i>\
  90. %(module_label)s</a></li>', args);
  91. }
  92. // desktop
  93. $('<li><a href="#desktop"><i class="icon-th"></i> '
  94. + wn._("Desktop") + '</a></li>\
  95. <li class="divider"></li>').appendTo(menu_list)
  96. // add to dropdown
  97. $.each(modules_list,function(i, m) {
  98. if(m!='Setup') {
  99. menu_list.append(_get_list_item(m));
  100. }
  101. })
  102. // setup for system manager
  103. if(user_roles.indexOf("System Manager")!=-1) {
  104. menu_list.append('<li class="divider">' + _get_list_item("Setup"));
  105. }
  106. },
  107. make_quick_search: function() {
  108. $('.navbar .nav:first').append('<li class="dropdown" id="go-dropdown"> \
  109. <a class="dropdown-toggle" href="#" data-toggle="dropdown"\
  110. title="'+wn._("Go")+'"\
  111. onclick="return false;">'+wn._("Go")+'</a>\
  112. <ul class="dropdown-menu" id="navbar-doctype">\
  113. <li><form>\
  114. <div class="input-group col col-lg-7" style="width: 300px; margin: 20px 10px;">\
  115. <select id="go-doctype-list"></select>\
  116. <span class="input-group-btn">\
  117. <button class="btn btn-default" type="button" id="go-new-btn">\
  118. <span class="icon icon-plus"></span></button>\
  119. </span> \
  120. </div> \
  121. <div class="input-group col col-lg-7" style="width: 300px; margin: 20px 10px;">\
  122. <input type="text" id="go-search-input"></input>\
  123. <span class="input-group-btn">\
  124. <button class="btn btn-default" type="button" id="go-search-btn">\
  125. <span class="icon icon-search"></span></button>\
  126. </span> \
  127. </div> \
  128. </form></li>\
  129. </ul>\
  130. </li>');
  131. this.bind_quick_search_events();
  132. },
  133. bind_quick_search_events: function() {
  134. // render searchable doctype list
  135. $("#go-doctype-list")
  136. .empty().add_options(wn.boot.profile.can_search.sort())
  137. .on("change", function() {
  138. if(wn.boot.profile.can_create.indexOf($(this).val()) === -1) {
  139. $("#go-new-btn").attr("disabled", "disabled");
  140. } else {
  141. $("#go-new-btn").removeAttr("disabled");
  142. }
  143. })
  144. .trigger("change");
  145. $("#go-search-input").keypress(function(ev){
  146. if(ev.which==13) { $("#go-search-btn").trigger("click"); }
  147. });
  148. // new button
  149. $("#go-new-btn").on("click", function() {
  150. $("#go-dropdown").removeClass("open");
  151. new_doc($("#go-doctype-list").val());
  152. });
  153. // search button
  154. $("#go-search-btn").on("click", function() {
  155. var doctype = doctype = $("#go-doctype-list").val(),
  156. search_string = $("#go-search-input").val();
  157. if(search_string) {
  158. wn.call({
  159. type: "GET",
  160. method: 'webnotes.client.get_value',
  161. args: {
  162. doctype: doctype,
  163. fieldname: "name",
  164. filters: {name: ["like", "%" + search_string + "%"]}
  165. },
  166. callback: function(r) {
  167. if(!r.exc && r.message && r.message.name) {
  168. console.log("opening " + doctype + " " + r.message.name);
  169. $("#go-dropdown").removeClass("open");
  170. wn.set_route("Form", doctype, r.message.name);
  171. }
  172. }
  173. });
  174. } else {
  175. $("#go-dropdown").removeClass("open");
  176. wn.set_route("List", $("#go-doctype-list").val());
  177. }
  178. });
  179. },
  180. make_file: function() {
  181. wn.ui.toolbar.new_dialog = new wn.ui.toolbar.NewDialog();
  182. wn.ui.toolbar.search = new wn.ui.toolbar.Search();
  183. wn.ui.toolbar.report = new wn.ui.toolbar.Report();
  184. $('.navbar .nav:first').append('<li class="dropdown">\
  185. <a class="dropdown-toggle" href="#" data-toggle="dropdown"\
  186. title="'+wn._("File")+'"\
  187. onclick="return false;">'+wn._("File")+'</a>\
  188. <ul class="dropdown-menu" id="navbar-file">\
  189. <li><a href="#" onclick="return wn.ui.toolbar.new_dialog.show();">\
  190. <i class="icon-plus"></i> '+wn._('New')+'...</a></li>\
  191. <li><a href="#" onclick="return wn.ui.toolbar.search.show();">\
  192. <i class="icon-search"></i> '+wn._('Search')+'...</a></li>\
  193. <li><a href="#" onclick="return wn.ui.toolbar.report.show();">\
  194. <i class="icon-list"></i> '+wn._('Report')+'...</a></li>\
  195. </ul>\
  196. </li>');
  197. },
  198. // make_actions: function() {
  199. // $('.navbar .nav:first').append('<li class="dropdown">\
  200. // <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  201. // title="'+wn._("Actions")+'"\
  202. // onclick="return false;">'+wn._("Actions")+'</a>\
  203. // <ul class="dropdown-menu" id="navbar-actions">\
  204. // </ul>\
  205. // </li>');
  206. // },
  207. make_tools: function() {
  208. $('.navbar .nav:first').append('<li class="dropdown">\
  209. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  210. title="'+wn._("Tools")+'"\
  211. onclick="return false;">Tools</a>\
  212. <ul class="dropdown-menu" id="toolbar-tools">\
  213. <li><a href="#" onclick="return wn.ui.toolbar.clear_cache();">'
  214. +wn._('Clear Cache & Refresh')+'</a></li>\
  215. <li><a href="#" onclick="return wn.ui.toolbar.show_about();">'
  216. +wn._('About')+'</a></li>\
  217. </ul>\
  218. </li>');
  219. if(has_common(user_roles,['Administrator','System Manager'])) {
  220. $('#toolbar-tools').append('<li><a href="#" \
  221. onclick="return wn.ui.toolbar.download_backup();">'
  222. +wn._('Download Backup')+'</a></li>');
  223. }
  224. },
  225. set_user_name: function() {
  226. var fn = user_fullname;
  227. if(fn.length > 15) fn = fn.substr(0,12) + '...';
  228. $('#toolbar-user-link').html(fn + '<b class="caret"></b>');
  229. },
  230. make_logout: function() {
  231. // logout
  232. $('#toolbar-user').append('<li><a href="#" onclick="return wn.app.logout();">'
  233. +wn._('Logout')+'</a></li>');
  234. }
  235. });
  236. wn.ui.toolbar.clear_cache = function() {
  237. localStorage && localStorage.clear();
  238. $c('webnotes.sessions.clear',{},function(r,rt){
  239. if(!r.exc) {
  240. show_alert(r.message);
  241. location.reload();
  242. }
  243. });
  244. return false;
  245. }
  246. wn.ui.toolbar.download_backup = function() {
  247. msgprint(wn._("Your download is being built, this may take a few moments..."));
  248. $c('webnotes.utils.backups.get_backup',{},function(r,rt) {});
  249. return false;
  250. }
  251. wn.ui.toolbar.show_about = function() {
  252. try {
  253. wn.ui.misc.about();
  254. } catch(e) {
  255. console.log(e);
  256. }
  257. return false;
  258. }