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.

toolbar.js 7.9 KiB

12 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
  2. // MIT License. See license.txt
  3. wn.ui.toolbar.Toolbar = Class.extend({
  4. init: function() {
  5. this.make();
  6. //this.make_modules();
  7. this.make_file();
  8. wn.ui.toolbar.recent = new wn.ui.toolbar.RecentDocs();
  9. wn.ui.toolbar.bookmarks = new wn.ui.toolbar.Bookmarks();
  10. this.make_tools();
  11. this.set_user_name();
  12. this.make_logout();
  13. this.make_notification();
  14. $('.dropdown-toggle').dropdown();
  15. $(document).trigger('toolbar_setup');
  16. // clear all custom menus on page change
  17. $(document).on("page-change", function() {
  18. $("header .navbar .custom-menu").remove();
  19. })
  20. },
  21. make: function() {
  22. $('header').append('<div class="navbar navbar-fixed-top navbar-inverse" style="min-height: 50px;">\
  23. <div class="container">\
  24. <button type="button" class="navbar-toggle" data-toggle="collapse" \
  25. data-target=".navbar-responsive-collapse">\
  26. <span class="icon-bar"></span>\
  27. <span class="icon-bar"></span>\
  28. <span class="icon-bar"></span>\
  29. </button>\
  30. <a class="navbar-brand" href="#"></a>\
  31. <div class="nav-collapse collapse navbar-responsive-collapse">\
  32. <ul class="nav navbar-nav">\
  33. </ul>\
  34. <img src="lib/images/ui/spinner.gif" id="spinner"/>\
  35. <ul class="nav navbar-nav pull-right">\
  36. <li class="dropdown">\
  37. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  38. onclick="return false;" id="toolbar-user-link"></a>\
  39. <ul class="dropdown-menu" id="toolbar-user">\
  40. </ul>\
  41. </li>\
  42. </ul>\
  43. </div>\
  44. </div>\
  45. </div>');
  46. },
  47. make_home: function() {
  48. $('.navbar-brand').attr('href', "#");
  49. },
  50. make_notification: function() {
  51. $('.navbar .pull-right').append('<li class="dropdown">\
  52. <a class="dropdown-toggl" href="#" data-toggle="dropdown"\
  53. title="'+wn._("Unread Messages")+'"\
  54. onclick="return false;"><span class="navbar-new-comments">0</span></a>\
  55. <ul class="dropdown-menu" id="navbar-notification">\
  56. </ul>\
  57. </li>');
  58. $(document).on("notification-update", function() {
  59. wn.ui.toolbar.update_notifications();
  60. })
  61. },
  62. // make_modules: function() {
  63. // $('<li class="dropdown">\
  64. // <a class="dropdown-toggle" data-toggle="dropdown" href="#"\
  65. // title="'+wn._("Modules")+'"\
  66. // onclick="return false;">'+wn._("Modules")+'</a>\
  67. // <ul class="dropdown-menu modules">\
  68. // </ul>\
  69. // </li>').prependTo('.navbar .nav:first');
  70. //
  71. // var modules_list = wn.user.get_desktop_items().sort();
  72. // var menu_list = $(".navbar .modules");
  73. //
  74. // var _get_list_item = function(m) {
  75. // args = {
  76. // module: m,
  77. // module_page: wn.modules[m].link,
  78. // module_label: wn._(wn.modules[m].label || m),
  79. // icon: wn.modules[m].icon
  80. // }
  81. //
  82. // return repl('<li><a href="#%(module_page)s" \
  83. // data-module="%(module)s"><i class="%(icon)s" style="display: inline-block; \
  84. // width: 21px; margin-top: -2px; margin-left: -7px;"></i>\
  85. // %(module_label)s</a></li>', args);
  86. // }
  87. //
  88. // // desktop
  89. // $('<li><a href="#desktop"><i class="icon-th"></i> '
  90. // + wn._("Desktop") + '</a></li>\
  91. // <li class="divider"></li>').appendTo(menu_list)
  92. //
  93. // // add to dropdown
  94. // $.each(modules_list,function(i, m) {
  95. // if(m!='Setup') {
  96. // menu_list.append(_get_list_item(m));
  97. // }
  98. // })
  99. //
  100. // // setup for system manager
  101. // if(user_roles.indexOf("System Manager")!=-1) {
  102. // menu_list.append('<li class="divider">' + _get_list_item("Setup"));
  103. // }
  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_tools: function() {
  125. $('.navbar .nav:first').append('<li class="dropdown">\
  126. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  127. title="'+wn._("Tools")+'"\
  128. onclick="return false;">'+wn._("Tools")+'</a>\
  129. <ul class="dropdown-menu" id="toolbar-tools">\
  130. <li><a href="#" onclick="return wn.ui.toolbar.clear_cache();">\
  131. <i class="icon-fixed-width icon-refresh"></i> '
  132. +wn._('Clear Cache & Refresh')+'</a></li>\
  133. <li><a href="#" onclick="return wn.ui.toolbar.show_about();">\
  134. <i class="icon-fixed-width icon-info-sign"></i> '
  135. +wn._('About')+'</a></li>\
  136. <li><a href="http://erpnext.org/docs.attributions.html" target="_blank"><i class="icon-fixed-width icon-heart"></i> '
  137. +wn._('Attributions')+'</a></li>\
  138. </ul>\
  139. </li>');
  140. if(has_common(user_roles,['Administrator','System Manager'])) {
  141. $('#toolbar-tools').append('<li><a href="#" \
  142. onclick="return wn.ui.toolbar.download_backup();"><i class="icon-fixed-width icon-download"></i> '
  143. +wn._('Download Backup')+'</a></li>');
  144. }
  145. },
  146. set_user_name: function() {
  147. var fn = user_fullname;
  148. if(fn.length > 15) fn = fn.substr(0,12) + '...';
  149. $('#toolbar-user-link').html(fn + '<b class="caret"></b>');
  150. },
  151. make_logout: function() {
  152. // logout
  153. $('#toolbar-user').append('<li><a href="#" onclick="return wn.app.logout();">\
  154. <i class="icon-fixed-width icon-signout"></i> '+wn._('Logout')+'</a></li>');
  155. }
  156. });
  157. wn.ui.toolbar.update_notifications = function() {
  158. var total = 0;
  159. var doctypes = keys(wn.boot.notification_info.open_count_doctype).sort();
  160. var modules = keys(wn.boot.notification_info.open_count_module).sort();
  161. $("#navbar-notification").empty();
  162. $.each(modules, function(i, module) {
  163. var count = wn.boot.notification_info.open_count_module[module];
  164. if(count) {
  165. $(repl('<li><a>\
  166. <span class="badge pull-right">\
  167. %(count)s</span> \
  168. <i class="icon-fixed-width %(icon)s"></i> %(module)s </a></li>', {
  169. module: module,
  170. count: count,
  171. icon: wn.modules[module].icon
  172. }))
  173. .appendTo("#navbar-notification")
  174. .find("a")
  175. .attr("data-module", module)
  176. .css({"min-width":"200px"})
  177. .on("click", function() {
  178. wn.set_route(wn.modules[$(this).attr("data-module")].link);
  179. });
  180. total += count;
  181. }
  182. });
  183. if(total) {
  184. $('<li class="divider"></li>').appendTo("#navbar-notification");
  185. }
  186. $.each(doctypes, function(i, doctype) {
  187. var count = wn.boot.notification_info.open_count_doctype[doctype];
  188. if(count) {
  189. $(repl('<li><a>\
  190. <span class="badge pull-right">\
  191. %(count)s</span> \
  192. <i class="icon-fixed-width %(icon)s"></i> %(doctype)s </a></li>', {
  193. doctype: doctype,
  194. icon: wn.boot.doctype_icons[doctype],
  195. count: count
  196. }))
  197. .appendTo("#navbar-notification")
  198. .find("a")
  199. .attr("data-doctype", doctype)
  200. .css({"min-width":"200px"})
  201. .on("click", function() {
  202. wn.views.show_open_count_list(this);
  203. });
  204. total += count;
  205. }
  206. });
  207. $(".navbar-new-comments")
  208. .html(total)
  209. .toggleClass("navbar-new-comments-true", total ? true : false);
  210. }
  211. wn.ui.toolbar.clear_cache = function() {
  212. localStorage && localStorage.clear();
  213. $c('webnotes.sessions.clear',{},function(r,rt){
  214. if(!r.exc) {
  215. show_alert(r.message);
  216. location.reload();
  217. }
  218. });
  219. return false;
  220. }
  221. wn.ui.toolbar.download_backup = function() {
  222. msgprint(wn._("Your download is being built, this may take a few moments..."));
  223. return $c('webnotes.utils.backups.get_backup',{},function(r,rt) {});
  224. return false;
  225. }
  226. wn.ui.toolbar.show_about = function() {
  227. try {
  228. wn.ui.misc.about();
  229. } catch(e) {
  230. console.log(e);
  231. }
  232. return false;
  233. }