blob: 1b9e3ea795e5bae751f9b77c5ccc76c30cf45d89 [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);
Anand Doshi5f17be82012-12-15 18:38:18 +053060 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 +053061 if (0 <= diff && diff <= 15) {
62 var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff });
63 $('header').append(repl('<div class="expiry-info"> \
64 Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \
65 Please renew your subscription to continue using ERPNext \
Anand Doshi5f17be82012-12-15 18:38:18 +053066 (and remove this annoying banner). %(payment_link)s\
67 </div>', { expiry_string: expiry_string, payment_link: payment_link }));
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053068 } else if (diff < 0) {
69 $('header').append(repl('<div class="expiry-info"> \
Anand Doshi5f17be82012-12-15 18:38:18 +053070 This ERPNext subscription <b>has expired</b>. %(payment_link)s\
71 </div>', { expiry_string: expiry_string, payment_link: payment_link }));
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053072 }
73 }
74 erpnext.set_about();
75 if(wn.control_panel.custom_startup_code)
76 eval(wn.control_panel.custom_startup_code);
77 }
78}
79
80
81// ========== Update Messages ============
82erpnext.update_messages = function(reset) {
83 // Updates Team Messages
84
85 if(inList(['Guest'], user) || !wn.session_alive) { return; }
86
87 if(!reset) {
88 var set_messages = function(r) {
89 if(!r.exc) {
90 // This function is defined in toolbar.js
91 erpnext.toolbar.set_new_comments(r.message.unread_messages);
92
93 var show_in_circle = function(parent_id, msg) {
94 var parent = $('#'+parent_id);
95 if(parent) {
96 if(msg) {
97 parent.find('span:first').text(msg);
98 parent.toggle(true);
99 } else {
100 parent.toggle(false);
101 }
102 }
103 }
104
Rushabh Mehtaec406862012-11-13 10:59:11 +0530105 show_in_circle('unread_messages', r.message.unread_messages);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530106 show_in_circle('open_support_tickets', r.message.open_support_tickets);
107 show_in_circle('things_todo', r.message.things_todo);
108 show_in_circle('todays_events', r.message.todays_events);
109 show_in_circle('open_tasks', r.message.open_tasks);
110 show_in_circle('unanswered_questions', r.message.unanswered_questions);
111
112 } else {
113 clearInterval(wn.updates.id);
114 }
115 }
116
117 wn.call({
118 method: 'startup.startup.get_global_status_messages',
119 callback: set_messages
120 });
121
122 } else {
123 erpnext.toolbar.set_new_comments(0);
124 $('#unread_messages').toggle(false);
125 }
126}
127
128erpnext.startup.set_periodic_updates = function() {
129 // Set interval for periodic updates of team messages
130 wn.updates = {};
131
132 if(wn.updates.id) {
133 clearInterval(wn.updates.id);
134 }
135
136 wn.updates.id = setInterval(erpnext.update_messages, 60000);
137}
138
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530139// subject, sender, description
140erpnext.send_message = function(opts) {
141 if(opts.btn) {
142 $(opts.btn).start_working();
143 }
144 wn.call({
145 method: 'website.send_message',
146 args: opts,
147 callback: function(r) {
148 if(opts.btn) {
149 $(opts.btn).done_working();
150 }
151 if(opts.callback)opts.callback(r)
152 }
153 });
154}
155
156erpnext.hide_naming_series = function() {
157 if(cur_frm.fields_dict.naming_series) {
158 hide_field('naming_series');
159 if(cur_frm.doc.__islocal) {
160 unhide_field('naming_series');
161 }
162 }
163}
Rushabh Mehtacebb0272012-09-28 12:18:43 +0530164
Rushabh Mehta079df382012-10-02 16:54:42 +0530165erpnext.setup_mousetrap = function() {
166 Mousetrap.bind(["command+g", "ctrl+g"], function() {
167 wn.ui.toolbar.search.show();
168 return false;
169 });
Rushabh Mehtacebb0272012-09-28 12:18:43 +0530170
Rushabh Mehta079df382012-10-02 16:54:42 +0530171 Mousetrap.bind(["command+s", "ctrl+s"], function() {
Anand Doshi161cf872012-12-14 13:13:02 +0530172 if(cur_frm && !cur_frm.save_disabled)
Rushabh Mehta079df382012-10-02 16:54:42 +0530173 cur_frm.save();
Rushabh Mehtaac7baf02012-10-03 12:22:13 +0530174 else if(wn.container.page.save_action)
175 wn.container.page.save_action();
Rushabh Mehta079df382012-10-02 16:54:42 +0530176 return false;
177 });
178}
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530179
Rushabh Mehta9d1faea2012-10-02 14:56:41 +0530180// start
181$(document).bind('startup', function() {
182 erpnext.startup.start();
Anand Doshi5f17be82012-12-15 18:38:18 +0530183});