blob: 76f2c264c142a8c4e1c8953bae712e4eead8208d [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();
Rushabh Mehta27c40792013-04-03 15:21:44 +053034
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053035 // setup toolbar
36 erpnext.toolbar.setup();
37
38 // set interval for updates
39 erpnext.startup.set_periodic_updates();
40
41 // border to the body
42 // ------------------
43 $('footer').html('<div class="web-footer erpnext-footer">\
Rushabh Mehta724bb472012-11-13 12:32:11 +053044 <a href="#attributions">Attributions and License</a> | \
45 <a href="#latest-updates"><b>Latest Updates</b></a></div>');
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053046
47 // complete registration
48 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
49 wn.require("app/js/complete_setup.js");
50 erpnext.complete_setup.show();
51 }
52 if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) {
Rushabh Mehtad1784cc2012-11-12 12:57:42 +053053 var today = dateutil.str_to_obj(wn.boot.server_date);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053054 var expires_on = dateutil.str_to_obj(wn.boot.expires_on);
55 var diff = dateutil.get_diff(expires_on, today);
Anand Doshi5f17be82012-12-15 18:38:18 +053056 var payment_link = "<a href=\"https://erpnext.com/modes-of-payment.html\" target=\"_blank\">See Payment Options.</a>";
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053057 if (0 <= diff && diff <= 15) {
58 var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff });
59 $('header').append(repl('<div class="expiry-info"> \
60 Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \
61 Please renew your subscription to continue using ERPNext \
Anand Doshi5f17be82012-12-15 18:38:18 +053062 (and remove this annoying banner). %(payment_link)s\
63 </div>', { expiry_string: expiry_string, payment_link: payment_link }));
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053064 } else if (diff < 0) {
65 $('header').append(repl('<div class="expiry-info"> \
Anand Doshi5f17be82012-12-15 18:38:18 +053066 This ERPNext subscription <b>has expired</b>. %(payment_link)s\
67 </div>', { expiry_string: expiry_string, payment_link: payment_link }));
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053068 }
69 }
70 erpnext.set_about();
71 if(wn.control_panel.custom_startup_code)
72 eval(wn.control_panel.custom_startup_code);
73 }
74}
75
76
77// ========== Update Messages ============
78erpnext.update_messages = function(reset) {
79 // Updates Team Messages
80
81 if(inList(['Guest'], user) || !wn.session_alive) { return; }
82
83 if(!reset) {
84 var set_messages = function(r) {
85 if(!r.exc) {
86 // This function is defined in toolbar.js
87 erpnext.toolbar.set_new_comments(r.message.unread_messages);
88
89 var show_in_circle = function(parent_id, msg) {
90 var parent = $('#'+parent_id);
91 if(parent) {
92 if(msg) {
93 parent.find('span:first').text(msg);
94 parent.toggle(true);
95 } else {
96 parent.toggle(false);
97 }
98 }
99 }
100
Rushabh Mehtaec406862012-11-13 10:59:11 +0530101 show_in_circle('unread_messages', r.message.unread_messages);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530102 show_in_circle('open_support_tickets', r.message.open_support_tickets);
103 show_in_circle('things_todo', r.message.things_todo);
104 show_in_circle('todays_events', r.message.todays_events);
105 show_in_circle('open_tasks', r.message.open_tasks);
106 show_in_circle('unanswered_questions', r.message.unanswered_questions);
Rushabh Mehta2e5db352013-01-16 11:34:26 +0530107 show_in_circle('open_leads', r.message.open_leads);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530108
109 } else {
110 clearInterval(wn.updates.id);
111 }
112 }
113
114 wn.call({
115 method: 'startup.startup.get_global_status_messages',
Rushabh Mehta028abd22013-01-31 11:20:10 +0530116 type:"GET",
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530117 callback: set_messages
118 });
119
120 } else {
121 erpnext.toolbar.set_new_comments(0);
122 $('#unread_messages').toggle(false);
123 }
124}
125
126erpnext.startup.set_periodic_updates = function() {
127 // Set interval for periodic updates of team messages
128 wn.updates = {};
129
130 if(wn.updates.id) {
131 clearInterval(wn.updates.id);
132 }
133
134 wn.updates.id = setInterval(erpnext.update_messages, 60000);
135}
136
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530137erpnext.hide_naming_series = function() {
138 if(cur_frm.fields_dict.naming_series) {
Anand Doshi60666a22013-04-12 20:19:53 +0530139 cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal?true:false);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530140 }
141}
Rushabh Mehtacebb0272012-09-28 12:18:43 +0530142
Rushabh Mehta079df382012-10-02 16:54:42 +0530143erpnext.setup_mousetrap = function() {
144 Mousetrap.bind(["command+g", "ctrl+g"], function() {
145 wn.ui.toolbar.search.show();
146 return false;
147 });
Rushabh Mehtacebb0272012-09-28 12:18:43 +0530148
Rushabh Mehta079df382012-10-02 16:54:42 +0530149 Mousetrap.bind(["command+s", "ctrl+s"], function() {
Nabin Hait5ca0f442012-12-14 19:00:42 +0530150 if(cur_frm && !cur_frm.save_disabled && cint(cur_frm.doc.docstatus)===0)
Rushabh Mehta079df382012-10-02 16:54:42 +0530151 cur_frm.save();
Nabin Hait64354372012-12-19 19:33:41 +0530152 else if(cur_frm && !cur_frm.save_disabled && cint(cur_frm.doc.docstatus)===1
153 && cur_frm.doc.__unsaved)
154 cur_frm.frm_head.appframe.buttons['Update'].click();
Rushabh Mehtaac7baf02012-10-03 12:22:13 +0530155 else if(wn.container.page.save_action)
156 wn.container.page.save_action();
Rushabh Mehta079df382012-10-02 16:54:42 +0530157 return false;
158 });
159}
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530160
Rushabh Mehta9d1faea2012-10-02 14:56:41 +0530161// start
162$(document).bind('startup', function() {
163 erpnext.startup.start();
Anand Doshi5f17be82012-12-15 18:38:18 +0530164});