Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | // ERPNext - web based ERP (http://erpnext.com) |
| 2 | // Copyright (C) 2012 Web Notes Technologies Pvt Ltd |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
Rushabh Mehta | 8c309be | 2012-01-20 13:47:16 +0530 | [diff] [blame] | 17 | /* toolbar settings */ |
| 18 | wn.provide('erpnext.toolbar'); |
| 19 | |
| 20 | erpnext.toolbar.setup = function() { |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 21 | // modules |
| 22 | erpnext.toolbar.add_modules(); |
| 23 | |
Rushabh Mehta | 8c309be | 2012-01-20 13:47:16 +0530 | [diff] [blame] | 24 | // profile |
Rushabh Mehta | 07a36a4 | 2012-02-27 18:17:57 +0530 | [diff] [blame] | 25 | $('#toolbar-user').append('<li><a href="#!profile-settings">Profile Settings</a></li>'); |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 26 | |
Anand Doshi | 5b1beeb | 2012-02-27 17:17:48 +0530 | [diff] [blame] | 27 | $('.navbar .pull-right').append('\ |
Rushabh Mehta | 07a36a4 | 2012-02-27 18:17:57 +0530 | [diff] [blame] | 28 | <li><a href="#!messages" title="Unread Messages"><span class="navbar-new-comments"></span></a></li>'); |
Rushabh Mehta | 8c309be | 2012-01-20 13:47:16 +0530 | [diff] [blame] | 29 | |
| 30 | // help |
Anand Doshi | 5b1beeb | 2012-02-27 17:17:48 +0530 | [diff] [blame] | 31 | $('.navbar .pull-right').prepend('<li class="dropdown">\ |
Rushabh Mehta | 6e156c7 | 2012-02-21 11:19:24 +0530 | [diff] [blame] | 32 | <a class="dropdown-toggle" data-toggle="dropdown" href="#" \ |
| 33 | onclick="return false;">Help<b class="caret"></b></a>\ |
Rushabh Mehta | 8c309be | 2012-01-20 13:47:16 +0530 | [diff] [blame] | 34 | <ul class="dropdown-menu" id="toolbar-help">\ |
| 35 | </ul></li>') |
| 36 | |
Rushabh Mehta | 39c0aa7 | 2012-07-26 12:39:07 +0530 | [diff] [blame] | 37 | $('#toolbar-help').append('<li><a href="https://erpnext.com/manual" target="_blank">\ |
Rushabh Mehta | 8c309be | 2012-01-20 13:47:16 +0530 | [diff] [blame] | 38 | Documentation</a></li>') |
| 39 | |
| 40 | $('#toolbar-help').append('<li><a href="http://groups.google.com/group/erpnext-user-forum" target="_blank">\ |
| 41 | Forum</a></li>') |
| 42 | |
| 43 | $('#toolbar-help').append('<li><a href="http://www.providesupport.com?messenger=iwebnotes" target="_blank">\ |
| 44 | Live Chat (Office Hours)</a></li>') |
| 45 | |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 46 | erpnext.toolbar.set_new_comments(); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 47 | } |
| 48 | |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 49 | erpnext.toolbar.add_modules = function() { |
| 50 | $('<li class="dropdown">\ |
| 51 | <a class="dropdown-toggle" data-toggle="dropdown" href="#"\ |
| 52 | onclick="return false;">Modules<b class="caret"></b></a>\ |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 53 | <ul class="dropdown-menu modules">\ |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 54 | </ul>\ |
Anand Doshi | 5b1beeb | 2012-02-27 17:17:48 +0530 | [diff] [blame] | 55 | </li>').prependTo('.navbar .nav:first'); |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 56 | |
| 57 | // if no modules list then show all |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 58 | if(wn.boot.modules_list && typeof(wn.boot.modules_list) == 'string') { |
| 59 | wn.boot.modules_list = JSON.parse(wn.boot.modules_list); |
| 60 | } |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 61 | else |
Rushabh Mehta | a38bbe2 | 2012-02-29 10:55:43 +0530 | [diff] [blame] | 62 | wn.boot.modules_list = keys(erpnext.modules).sort(); |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 63 | |
| 64 | // add to dropdown |
| 65 | for(var i in wn.boot.modules_list) { |
| 66 | var m = wn.boot.modules_list[i] |
Rushabh Mehta | a38bbe2 | 2012-02-29 10:55:43 +0530 | [diff] [blame] | 67 | |
Rushabh Mehta | 428929b | 2012-03-01 11:24:45 +0530 | [diff] [blame] | 68 | if(m!='Setup' && wn.boot.profile.allow_modules.indexOf(m)!=-1) { |
Rushabh Mehta | a38bbe2 | 2012-02-29 10:55:43 +0530 | [diff] [blame] | 69 | args = { |
| 70 | module: m, |
| 71 | module_page: erpnext.modules[m], |
| 72 | module_label: m=='HR' ? 'Human Resources' : m |
| 73 | } |
| 74 | |
| 75 | $('.navbar .modules').append(repl('<li><a href="#!%(module_page)s" \ |
| 76 | data-module="%(module)s">%(module_label)s</a></li>', args)); |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 77 | } |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 78 | } |
Rushabh Mehta | 428929b | 2012-03-01 11:24:45 +0530 | [diff] [blame] | 79 | |
| 80 | // dasboard for accounts system manager |
| 81 | if(user_roles.indexOf("Accounts Manager")!=-1) { |
| 82 | $('.navbar .modules').append('<li><a href="#!dashboard" \ |
| 83 | data-module="Dashboard">Dashboard</a></li>'); |
| 84 | } |
Rushabh Mehta | 17da764 | 2012-02-28 18:56:56 +0530 | [diff] [blame] | 85 | |
| 86 | // setup for system manager |
| 87 | if(user_roles.indexOf("System Manager")!=-1) { |
| 88 | $('.navbar .modules').append('<li class="divider"></li>\ |
| 89 | <li><a href="#!Setup" data-module="Setup">Setup</a></li>'); |
| 90 | } |
| 91 | |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 92 | } |
| 93 | |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 94 | erpnext.toolbar.set_new_comments = function(new_comments) { |
| 95 | var navbar_nc = $('.navbar-new-comments'); |
| 96 | if(new_comments && new_comments.length>0) { |
| 97 | navbar_nc.text(new_comments.length); |
| 98 | navbar_nc.addClass('navbar-new-comments-true') |
| 99 | $.each(new_comments, function(i, v) { |
| 100 | var msg = 'New Message: ' + (v[1].length<=100 ? v[1] : (v[1].substr(0, 100) + "...")); |
| 101 | var id = v[0].replace('/', '-'); |
| 102 | if(!$('#' + id)[0]) { show_alert(msg, id); } |
| 103 | }) |
| 104 | } else { |
| 105 | navbar_nc.removeClass('navbar-new-comments-true'); |
| 106 | navbar_nc.text(0); |
| 107 | } |
| 108 | } |
| 109 | |