blob: 33059e33aecb4b562463457fe8bd7c55ad680e2a [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
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053038 // complete registration
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053039 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete==='No')) {
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053040 wn.require("app/js/complete_setup.js");
41 erpnext.complete_setup.show();
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053042 } else if(!wn.boot.customer_count) {
43 if(wn.get_route()[0]!=="Setup") {
44 msgprint("<a class='btn btn-success' href='#Setup'>"
45 + wn._("Proceed to Setup") + "</a>\
46 <br><br><p class='text-muted'>"+
47 wn._("This message goes away after you create your first customer.")+
48 "</p>", wn._("Welcome"));
49 }
50 } else if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) {
Rushabh Mehtad1784cc2012-11-12 12:57:42 +053051 var today = dateutil.str_to_obj(wn.boot.server_date);
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053052 var expires_on = dateutil.str_to_obj(wn.boot.expires_on);
53 var diff = dateutil.get_diff(expires_on, today);
Anand Doshi5f17be82012-12-15 18:38:18 +053054 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 +053055 if (0 <= diff && diff <= 15) {
56 var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff });
57 $('header').append(repl('<div class="expiry-info"> \
58 Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \
59 Please renew your subscription to continue using ERPNext \
Anand Doshi5f17be82012-12-15 18:38:18 +053060 (and remove this annoying banner). %(payment_link)s\
61 </div>', { expiry_string: expiry_string, payment_link: payment_link }));
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053062 } else if (diff < 0) {
63 $('header').append(repl('<div class="expiry-info"> \
Anand Doshi5f17be82012-12-15 18:38:18 +053064 This ERPNext subscription <b>has expired</b>. %(payment_link)s\
65 </div>', { expiry_string: expiry_string, payment_link: payment_link }));
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053066 }
67 }
68 erpnext.set_about();
69 if(wn.control_panel.custom_startup_code)
70 eval(wn.control_panel.custom_startup_code);
71 }
72}
73
Rushabh Mehta079df382012-10-02 16:54:42 +053074erpnext.setup_mousetrap = function() {
Rushabh Mehtadd790a52013-06-17 12:55:54 +053075 $(document).keydown("meta+g ctrl+g", function(e) {
Rushabh Mehta079df382012-10-02 16:54:42 +053076 wn.ui.toolbar.search.show();
77 return false;
78 });
Rushabh Mehtadd790a52013-06-17 12:55:54 +053079
80 $(document).keydown("meta+s ctrl+s", function(e) {
81 if(cur_frm) {
82 cur_frm.save_or_update();
83 }
Rushabh Mehtaac7baf02012-10-03 12:22:13 +053084 else if(wn.container.page.save_action)
85 wn.container.page.save_action();
Rushabh Mehta079df382012-10-02 16:54:42 +053086 return false;
Rushabh Mehtadd790a52013-06-17 12:55:54 +053087 })
Rushabh Mehta079df382012-10-02 16:54:42 +053088}
Rushabh Mehtab0d32b72012-09-28 16:11:57 +053089
Rushabh Mehta9d1faea2012-10-02 14:56:41 +053090// start
91$(document).bind('startup', function() {
92 erpnext.startup.start();
Anand Doshi5f17be82012-12-15 18:38:18 +053093});