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.

13 年之前
13 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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_home();
  26. this.make_document();
  27. wn.ui.toolbar.recent = new wn.ui.toolbar.RecentDocs();
  28. this.make_tools();
  29. this.set_user_name();
  30. this.make_logout();
  31. $('.dropdown-toggle').dropdown();
  32. $(document).trigger('toolbar_setup');
  33. },
  34. make: function() {
  35. $('header').append('<div class="navbar navbar-fixed-top">\
  36. <div class="navbar-inner">\
  37. <div class="container">\
  38. <a class="brand"></a>\
  39. <ul class="nav">\
  40. </ul>\
  41. <img src="lib/images/ui/spinner.gif" id="spinner"/>\
  42. <ul class="nav pull-right">\
  43. <li class="dropdown">\
  44. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  45. onclick="return false;" id="toolbar-user-link"></a>\
  46. <ul class="dropdown-menu" id="toolbar-user">\
  47. </ul>\
  48. </li>\
  49. </ul>\
  50. </div>\
  51. </div>\
  52. </div>');
  53. },
  54. make_home: function() {
  55. $('.navbar .brand').attr('href', "#");
  56. },
  57. make_document: function() {
  58. wn.ui.toolbar.new_dialog = new wn.ui.toolbar.NewDialog();
  59. wn.ui.toolbar.search = new wn.ui.toolbar.Search();
  60. wn.ui.toolbar.report = new wn.ui.toolbar.Report();
  61. $('.navbar .nav:first').append('<li class="dropdown">\
  62. <a class="dropdown-toggle" href="#" data-toggle="dropdown"\
  63. onclick="return false;">Document<b class="caret"></b></a>\
  64. <ul class="dropdown-menu" id="toolbar-document">\
  65. <li><a href="#" onclick="return wn.ui.toolbar.new_dialog.show();">\
  66. <i class="icon-plus"></i> New</a></li>\
  67. <li><a href="#" onclick="return wn.ui.toolbar.search.show();">\
  68. <i class="icon-search"></i> Search</a></li>\
  69. <li><a href="#" onclick="return wn.ui.toolbar.report.show();">\
  70. <i class="icon-list"></i> Report</a></li>\
  71. </ul>\
  72. </li>');
  73. },
  74. make_tools: function() {
  75. $('.navbar .nav:first').append('<li class="dropdown">\
  76. <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
  77. onclick="return false;">Tools<b class="caret"></b></a>\
  78. <ul class="dropdown-menu" id="toolbar-tools">\
  79. <li><a href="#" onclick="return wn.ui.toolbar.clear_cache();">Clear Cache & Refresh</a></li>\
  80. <li><a href="#" onclick="return wn.ui.toolbar.show_about();">About</a></li>\
  81. </ul>\
  82. </li>');
  83. if(has_common(user_roles,['Administrator','System Manager'])) {
  84. $('#toolbar-tools').append('<li><a href="#" \
  85. onclick="return wn.ui.toolbar.download_backup();">\
  86. Download Backup</a></li>');
  87. }
  88. },
  89. set_user_name: function() {
  90. var fn = user_fullname;
  91. if(fn.length > 15) fn = fn.substr(0,12) + '...';
  92. $('#toolbar-user-link').html(fn + '<b class="caret"></b>');
  93. },
  94. make_logout: function() {
  95. // logout
  96. $('#toolbar-user').append('<li><a href="#" onclick="return wn.app.logout();">Logout</a></li>');
  97. }
  98. });
  99. wn.ui.toolbar.clear_cache = function() {
  100. localStorage && localStorage.clear();
  101. $c('webnotes.session_cache.clear',{},function(r,rt){
  102. if(!r.exc) {
  103. show_alert(r.message);
  104. location.reload();
  105. }
  106. });
  107. return false;
  108. }
  109. wn.ui.toolbar.download_backup = function() {
  110. $c('webnotes.utils.backups.get_backup',{},function(r,rt) {});
  111. return false;
  112. }
  113. wn.ui.toolbar.show_about = function() {
  114. try {
  115. wn.ui.misc.about();
  116. } catch(e) {
  117. console.log(e);
  118. }
  119. return false;
  120. }