// Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com) // // MIT License (MIT) // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // wn.ui.toolbar.Toolbar = Class.extend({ init: function() { this.make(); //this.make_modules(); this.make_file(); wn.ui.toolbar.recent = new wn.ui.toolbar.RecentDocs(); wn.ui.toolbar.bookmarks = new wn.ui.toolbar.Bookmarks(); this.make_tools(); this.set_user_name(); this.make_logout(); this.make_notification(); $('.dropdown-toggle').dropdown(); $(document).trigger('toolbar_setup'); // clear all custom menus on page change $(document).on("page-change", function() { $("header .navbar .custom-menu").remove(); }) }, make: function() { $('header').append(''); }, make_home: function() { $('.navbar-brand').attr('href', "#"); }, make_notification: function() { $('.navbar .pull-right').append(''); $(document).on("notification-update", function() { wn.ui.toolbar.update_notifications(); }) }, // make_modules: function() { // $('').prependTo('.navbar .nav:first'); // // var modules_list = wn.user.get_desktop_items().sort(); // var menu_list = $(".navbar .modules"); // // var _get_list_item = function(m) { // args = { // module: m, // module_page: wn.modules[m].link, // module_label: wn._(wn.modules[m].label || m), // icon: wn.modules[m].icon // } // // return repl('
  • \ // %(module_label)s
  • ', args); // } // // // desktop // $('
  • ' // + wn._("Desktop") + '
  • \ //
  • ').appendTo(menu_list) // // // add to dropdown // $.each(modules_list,function(i, m) { // if(m!='Setup') { // menu_list.append(_get_list_item(m)); // } // }) // // // setup for system manager // if(user_roles.indexOf("System Manager")!=-1) { // menu_list.append('
  • ' + _get_list_item("Setup")); // } // // }, make_file: function() { wn.ui.toolbar.new_dialog = new wn.ui.toolbar.NewDialog(); wn.ui.toolbar.search = new wn.ui.toolbar.Search(); wn.ui.toolbar.report = new wn.ui.toolbar.Report(); $('.navbar .nav:first').append('
  • '); }, make_tools: function() { $('.navbar .nav:first').append(''); if(has_common(user_roles,['Administrator','System Manager'])) { $('#toolbar-tools').append('
  • ' +wn._('Download Backup')+'
  • '); } }, set_user_name: function() { var fn = user_fullname; if(fn.length > 15) fn = fn.substr(0,12) + '...'; $('#toolbar-user-link').html(fn + ''); }, make_logout: function() { // logout $('#toolbar-user').append('
  • ' +wn._('Logout')+'
  • '); } }); wn.ui.toolbar.update_notifications = function() { var total = 0; var doctypes = keys(wn.boot.notification_info.open_count_doctype).sort(); var modules = keys(wn.boot.notification_info.open_count_module).sort(); $("#navbar-notification").empty(); $.each(modules, function(i, module) { var count = wn.boot.notification_info.open_count_module[module]; if(count) { $(repl('
  • \ \ %(count)s \ %(module)s
  • ', { module: module, count: count, icon: wn.modules[module].icon })) .appendTo("#navbar-notification") .find("a") .attr("data-module", module) .css({"min-width":"200px"}) .on("click", function() { wn.set_route(wn.modules[$(this).attr("data-module")].link); }); total += count; } }); if(total) { $('
  • ').appendTo("#navbar-notification"); } $.each(doctypes, function(i, doctype) { var count = wn.boot.notification_info.open_count_doctype[doctype]; if(count) { $(repl('
  • \ \ %(count)s \ %(doctype)s
  • ', { doctype: doctype, icon: wn.boot.doctype_icons[doctype], count: count })) .appendTo("#navbar-notification") .find("a") .attr("data-doctype", doctype) .css({"min-width":"200px"}) .on("click", function() { wn.views.show_open_count_list(this); }); total += count; } }); $(".navbar-new-comments") .html(total) .toggleClass("navbar-new-comments-true", total ? true : false); } wn.ui.toolbar.clear_cache = function() { localStorage && localStorage.clear(); $c('webnotes.sessions.clear',{},function(r,rt){ if(!r.exc) { show_alert(r.message); location.reload(); } }); return false; } wn.ui.toolbar.download_backup = function() { msgprint(wn._("Your download is being built, this may take a few moments...")); $c('webnotes.utils.backups.get_backup',{},function(r,rt) {}); return false; } wn.ui.toolbar.show_about = function() { try { wn.ui.misc.about(); } catch(e) { console.log(e); } return false; }