blob: 1a2bfdfe9a8dc7c0b50deffbd881ad4b53a663c7 [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301// 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 Mehta8c309be2012-01-20 13:47:16 +053017/* toolbar settings */
18wn.provide('erpnext.toolbar');
19
20erpnext.toolbar.setup = function() {
Rushabh Mehtad0251332012-02-21 17:26:50 +053021 // modules
22 erpnext.toolbar.add_modules();
23
Rushabh Mehta8c309be2012-01-20 13:47:16 +053024 // profile
Rushabh Mehta07a36a42012-02-27 18:17:57 +053025 $('#toolbar-user').append('<li><a href="#!profile-settings">Profile Settings</a></li>');
Rushabh Mehtad0251332012-02-21 17:26:50 +053026
Anand Doshi5b1beeb2012-02-27 17:17:48 +053027 $('.navbar .pull-right').append('\
Rushabh Mehta07a36a42012-02-27 18:17:57 +053028 <li><a href="#!messages" title="Unread Messages"><span class="navbar-new-comments"></span></a></li>');
Rushabh Mehta8c309be2012-01-20 13:47:16 +053029
30 // help
Anand Doshi5b1beeb2012-02-27 17:17:48 +053031 $('.navbar .pull-right').prepend('<li class="dropdown">\
Rushabh Mehta6e156c72012-02-21 11:19:24 +053032 <a class="dropdown-toggle" data-toggle="dropdown" href="#" \
33 onclick="return false;">Help<b class="caret"></b></a>\
Rushabh Mehta8c309be2012-01-20 13:47:16 +053034 <ul class="dropdown-menu" id="toolbar-help">\
35 </ul></li>')
36
37 $('#toolbar-help').append('<li><a href="http://erpnext.blogspot.com/2011/03/erpnext-help.html" target="_blank">\
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
46 // billing
47 if(pscript.is_erpnext_saas && is_system_manager) {
48 $('#toolbar-user').append('<li><a href="#billing">Billing</a></li>')
49 }
Anand Doshic3023be2012-02-20 16:31:55 +053050
51 $.extend(page_body.wntoolbar, {
52 set_new_comments: function(new_comments) {
Anand Doshi5b1beeb2012-02-27 17:17:48 +053053 var navbar_nc = $('.navbar-new-comments');
Anand Doshic3023be2012-02-20 16:31:55 +053054 if(new_comments && new_comments.length>0) {
Anand Doshi5b1beeb2012-02-27 17:17:48 +053055 navbar_nc.text(new_comments.length);
56 navbar_nc.addClass('navbar-new-comments-true')
Anand Doshic3023be2012-02-20 16:31:55 +053057 $.each(new_comments, function(i, v) {
58 var msg = 'New Message: ' + (v[1].length<=100 ? v[1] : (v[1].substr(0, 100) + "..."));
59 var id = v[0].replace('/', '-');
60 if(!$('#' + id)[0]) { show_alert(msg, id); }
61 })
62 } else {
Anand Doshi5b1beeb2012-02-27 17:17:48 +053063 navbar_nc.removeClass('navbar-new-comments-true');
64 navbar_nc.text(0);
Anand Doshic3023be2012-02-20 16:31:55 +053065 }
66 }
67 });
68
69 page_body.wntoolbar.set_new_comments();
70}
71
Rushabh Mehtad0251332012-02-21 17:26:50 +053072erpnext.toolbar.add_modules = function() {
73 $('<li class="dropdown">\
74 <a class="dropdown-toggle" data-toggle="dropdown" href="#"\
75 onclick="return false;">Modules<b class="caret"></b></a>\
Rushabh Mehta17da7642012-02-28 18:56:56 +053076 <ul class="dropdown-menu modules">\
Rushabh Mehtad0251332012-02-21 17:26:50 +053077 </ul>\
Anand Doshi5b1beeb2012-02-27 17:17:48 +053078 </li>').prependTo('.navbar .nav:first');
Rushabh Mehta17da7642012-02-28 18:56:56 +053079
80 // if no modules list then show all
81 if(wn.boot.modules_list)
82 wn.boot.modules_list = JSON.parse(wn.boot.modules_list);
83 else
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053084 wn.boot.modules_list = keys(erpnext.modules).sort();
Rushabh Mehta17da7642012-02-28 18:56:56 +053085
86 // add to dropdown
87 for(var i in wn.boot.modules_list) {
88 var m = wn.boot.modules_list[i]
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053089
90 if(m!='Setup') {
91 args = {
92 module: m,
93 module_page: erpnext.modules[m],
94 module_label: m=='HR' ? 'Human Resources' : m
95 }
96
97 $('.navbar .modules').append(repl('<li><a href="#!%(module_page)s" \
98 data-module="%(module)s">%(module_label)s</a></li>', args));
Rushabh Mehta17da7642012-02-28 18:56:56 +053099 }
Rushabh Mehta17da7642012-02-28 18:56:56 +0530100 }
101
102 // setup for system manager
103 if(user_roles.indexOf("System Manager")!=-1) {
104 $('.navbar .modules').append('<li class="divider"></li>\
105 <li><a href="#!Setup" data-module="Setup">Setup</a></li>');
106 }
107
Rushabh Mehtad0251332012-02-21 17:26:50 +0530108}
109