blob: 9d8c5c5c35472818f49a6a2d2de36d615ddc6741 [file] [log] [blame]
Rushabh Mehta2fa2f712012-09-24 19:13:42 +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
17var current_module;
18var is_system_manager = 0;
19
20wn.provide('erpnext.startup');
21
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053022erpnext.startup.set_globals = function() {
23 if(inList(user_roles,'System Manager')) is_system_manager = 1;
24}
25
26erpnext.startup.start = function() {
27 console.log('Starting up...');
28 $('#startup_div').html('Starting up...').toggle(true);
29
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053030 erpnext.startup.set_globals();
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053031
Rushabh Mehtabd919ca2012-11-28 15:19:51 +053032 if(user != 'Guest'){
Rushabh Mehta079df382012-10-02 16:54:42 +053033 erpnext.setup_mousetrap();
34
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053035 // always allow apps
36 wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat(
37 ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages'])
38
39 // setup toolbar
40 erpnext.toolbar.setup();
41
42 // set interval for updates
43 erpnext.startup.set_periodic_updates();
44
45 // border to the body
46 // ------------------
47 $('footer').html('<div class="web-footer erpnext-footer">\
Rushabh Mehta724bb472012-11-13 12:32:11 +053048 <a href="#attributions">Attributions and License</a> | \
49 <a href="#latest-updates"><b>Latest Updates</b></a></div>');
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053050
51 // complete registration
52 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
53 wn.require("app/js/complete_setup.js");
54 erpnext.complete_setup.show();
55 }
56 if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) {
Rushabh Mehtad1784cc2012-11-12 12:57:42 +053057 var today = dateutil.str_to_obj(wn.boot.server_date);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053058 var expires_on = dateutil.str_to_obj(wn.boot.expires_on);
59 var diff = dateutil.get_diff(expires_on, today);
60 if (0 <= diff && diff <= 15) {
61 var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff });
62 $('header').append(repl('<div class="expiry-info"> \
63 Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \
64 Please renew your subscription to continue using ERPNext \
65 (and remove this annoying banner). \
66 </div>', { expiry_string: expiry_string }));
67 } else if (diff < 0) {
68 $('header').append(repl('<div class="expiry-info"> \
69 This ERPNext subscription <b>has expired</b>. \
70 </div>', { expiry_string: expiry_string }));
71 }
72 }
73 erpnext.set_about();
74 if(wn.control_panel.custom_startup_code)
75 eval(wn.control_panel.custom_startup_code);
76 }
77}
78
79
80// ========== Update Messages ============
81erpnext.update_messages = function(reset) {
82 // Updates Team Messages
83
84 if(inList(['Guest'], user) || !wn.session_alive) { return; }
85
86 if(!reset) {
87 var set_messages = function(r) {
88 if(!r.exc) {
89 // This function is defined in toolbar.js
90 erpnext.toolbar.set_new_comments(r.message.unread_messages);
91
92 var show_in_circle = function(parent_id, msg) {
93 var parent = $('#'+parent_id);
94 if(parent) {
95 if(msg) {
96 parent.find('span:first').text(msg);
97 parent.toggle(true);
98 } else {
99 parent.toggle(false);
100 }
101 }
102 }
103
Rushabh Mehtaec406862012-11-13 10:59:11 +0530104 show_in_circle('unread_messages', r.message.unread_messages);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530105 show_in_circle('open_support_tickets', r.message.open_support_tickets);
106 show_in_circle('things_todo', r.message.things_todo);
107 show_in_circle('todays_events', r.message.todays_events);
108 show_in_circle('open_tasks', r.message.open_tasks);
109 show_in_circle('unanswered_questions', r.message.unanswered_questions);
110
111 } else {
112 clearInterval(wn.updates.id);
113 }
114 }
115
116 wn.call({
117 method: 'startup.startup.get_global_status_messages',
118 callback: set_messages
119 });
120
121 } else {
122 erpnext.toolbar.set_new_comments(0);
123 $('#unread_messages').toggle(false);
124 }
125}
126
127erpnext.startup.set_periodic_updates = function() {
128 // Set interval for periodic updates of team messages
129 wn.updates = {};
130
131 if(wn.updates.id) {
132 clearInterval(wn.updates.id);
133 }
134
135 wn.updates.id = setInterval(erpnext.update_messages, 60000);
136}
137
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530138// subject, sender, description
139erpnext.send_message = function(opts) {
140 if(opts.btn) {
141 $(opts.btn).start_working();
142 }
143 wn.call({
144 method: 'website.send_message',
145 args: opts,
146 callback: function(r) {
147 if(opts.btn) {
148 $(opts.btn).done_working();
149 }
150 if(opts.callback)opts.callback(r)
151 }
152 });
153}
154
155erpnext.hide_naming_series = function() {
156 if(cur_frm.fields_dict.naming_series) {
157 hide_field('naming_series');
158 if(cur_frm.doc.__islocal) {
159 unhide_field('naming_series');
160 }
161 }
162}
Rushabh Mehtacebb0272012-09-28 12:18:43 +0530163
Rushabh Mehta079df382012-10-02 16:54:42 +0530164erpnext.setup_mousetrap = function() {
165 Mousetrap.bind(["command+g", "ctrl+g"], function() {
166 wn.ui.toolbar.search.show();
167 return false;
168 });
Rushabh Mehtacebb0272012-09-28 12:18:43 +0530169
Rushabh Mehta079df382012-10-02 16:54:42 +0530170 Mousetrap.bind(["command+s", "ctrl+s"], function() {
Nabin Hait5ca0f442012-12-14 19:00:42 +0530171 if(cur_frm && !cur_frm.save_disabled && cint(cur_frm.doc.docstatus)===0)
Rushabh Mehta079df382012-10-02 16:54:42 +0530172 cur_frm.save();
Rushabh Mehtaac7baf02012-10-03 12:22:13 +0530173 else if(wn.container.page.save_action)
174 wn.container.page.save_action();
Rushabh Mehta079df382012-10-02 16:54:42 +0530175 return false;
176 });
177}
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530178
Rushabh Mehta9d1faea2012-10-02 14:56:41 +0530179// start
180$(document).bind('startup', function() {
181 erpnext.startup.start();
Anand Doshie65e6212012-11-19 15:43:18 +0530182});