blob: f587fbc0c67ee55b5fdfa5e256ec08de2dd60b09 [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
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053041 // complete registration
42 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
43 wn.require("app/js/complete_setup.js");
44 erpnext.complete_setup.show();
45 }
46 if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) {
Rushabh Mehtad1784cc2012-11-12 12:57:42 +053047 var today = dateutil.str_to_obj(wn.boot.server_date);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053048 var expires_on = dateutil.str_to_obj(wn.boot.expires_on);
49 var diff = dateutil.get_diff(expires_on, today);
Anand Doshi5f17be82012-12-15 18:38:18 +053050 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 +053051 if (0 <= diff && diff <= 15) {
52 var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff });
53 $('header').append(repl('<div class="expiry-info"> \
54 Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \
55 Please renew your subscription to continue using ERPNext \
Anand Doshi5f17be82012-12-15 18:38:18 +053056 (and remove this annoying banner). %(payment_link)s\
57 </div>', { expiry_string: expiry_string, payment_link: payment_link }));
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053058 } else if (diff < 0) {
59 $('header').append(repl('<div class="expiry-info"> \
Anand Doshi5f17be82012-12-15 18:38:18 +053060 This ERPNext subscription <b>has expired</b>. %(payment_link)s\
61 </div>', { expiry_string: expiry_string, payment_link: payment_link }));
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053062 }
63 }
64 erpnext.set_about();
65 if(wn.control_panel.custom_startup_code)
66 eval(wn.control_panel.custom_startup_code);
67 }
68}
69
70
71// ========== Update Messages ============
72erpnext.update_messages = function(reset) {
73 // Updates Team Messages
74
75 if(inList(['Guest'], user) || !wn.session_alive) { return; }
76
77 if(!reset) {
78 var set_messages = function(r) {
79 if(!r.exc) {
80 // This function is defined in toolbar.js
81 erpnext.toolbar.set_new_comments(r.message.unread_messages);
82
83 var show_in_circle = function(parent_id, msg) {
84 var parent = $('#'+parent_id);
85 if(parent) {
86 if(msg) {
87 parent.find('span:first').text(msg);
88 parent.toggle(true);
89 } else {
90 parent.toggle(false);
91 }
92 }
93 }
94
Rushabh Mehtaec406862012-11-13 10:59:11 +053095 show_in_circle('unread_messages', r.message.unread_messages);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053096 show_in_circle('open_support_tickets', r.message.open_support_tickets);
97 show_in_circle('things_todo', r.message.things_todo);
98 show_in_circle('todays_events', r.message.todays_events);
99 show_in_circle('open_tasks', r.message.open_tasks);
100 show_in_circle('unanswered_questions', r.message.unanswered_questions);
Rushabh Mehta2e5db352013-01-16 11:34:26 +0530101 show_in_circle('open_leads', r.message.open_leads);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530102
103 } else {
104 clearInterval(wn.updates.id);
105 }
106 }
107
108 wn.call({
109 method: 'startup.startup.get_global_status_messages',
Rushabh Mehta028abd22013-01-31 11:20:10 +0530110 type:"GET",
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530111 callback: set_messages
112 });
113
114 } else {
115 erpnext.toolbar.set_new_comments(0);
116 $('#unread_messages').toggle(false);
117 }
118}
119
120erpnext.startup.set_periodic_updates = function() {
121 // Set interval for periodic updates of team messages
122 wn.updates = {};
123
124 if(wn.updates.id) {
125 clearInterval(wn.updates.id);
126 }
127
128 wn.updates.id = setInterval(erpnext.update_messages, 60000);
129}
130
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530131erpnext.hide_naming_series = function() {
132 if(cur_frm.fields_dict.naming_series) {
Anand Doshi60666a22013-04-12 20:19:53 +0530133 cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal?true:false);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530134 }
135}
Rushabh Mehtacebb0272012-09-28 12:18:43 +0530136
Rushabh Mehta079df382012-10-02 16:54:42 +0530137erpnext.setup_mousetrap = function() {
Rushabh Mehtadd790a52013-06-17 12:55:54 +0530138 $(document).keydown("meta+g ctrl+g", function(e) {
Rushabh Mehta079df382012-10-02 16:54:42 +0530139 wn.ui.toolbar.search.show();
140 return false;
141 });
Rushabh Mehtadd790a52013-06-17 12:55:54 +0530142
143 $(document).keydown("meta+s ctrl+s", function(e) {
144 if(cur_frm) {
145 cur_frm.save_or_update();
146 }
Rushabh Mehtaac7baf02012-10-03 12:22:13 +0530147 else if(wn.container.page.save_action)
148 wn.container.page.save_action();
Rushabh Mehta079df382012-10-02 16:54:42 +0530149 return false;
Rushabh Mehtadd790a52013-06-17 12:55:54 +0530150 })
Rushabh Mehta079df382012-10-02 16:54:42 +0530151}
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530152
Rushabh Mehta9d1faea2012-10-02 14:56:41 +0530153// start
154$(document).bind('startup', function() {
155 erpnext.startup.start();
Anand Doshi5f17be82012-12-15 18:38:18 +0530156});