Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 1 | // 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 | |
| 17 | var current_module; |
| 18 | var is_system_manager = 0; |
| 19 | |
| 20 | wn.provide('erpnext.startup'); |
| 21 | |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 22 | erpnext.startup.set_globals = function() { |
| 23 | if(inList(user_roles,'System Manager')) is_system_manager = 1; |
| 24 | } |
| 25 | |
| 26 | erpnext.startup.start = function() { |
| 27 | console.log('Starting up...'); |
| 28 | $('#startup_div').html('Starting up...').toggle(true); |
| 29 | |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 30 | erpnext.startup.set_globals(); |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 31 | |
Rushabh Mehta | bd919ca | 2012-11-28 15:19:51 +0530 | [diff] [blame] | 32 | if(user != 'Guest'){ |
Rushabh Mehta | 079df38 | 2012-10-02 16:54:42 +0530 | [diff] [blame] | 33 | erpnext.setup_mousetrap(); |
Rushabh Mehta | 27c4079 | 2013-04-03 15:21:44 +0530 | [diff] [blame] | 34 | |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 35 | // setup toolbar |
| 36 | erpnext.toolbar.setup(); |
| 37 | |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 38 | // complete registration |
Rushabh Mehta | 2f7e1ab | 2013-06-26 17:20:12 +0530 | [diff] [blame] | 39 | if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete==='No')) { |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 40 | wn.require("app/js/complete_setup.js"); |
| 41 | erpnext.complete_setup.show(); |
Rushabh Mehta | 2f7e1ab | 2013-06-26 17:20:12 +0530 | [diff] [blame] | 42 | } 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 Mehta | d1784cc | 2012-11-12 12:57:42 +0530 | [diff] [blame] | 51 | var today = dateutil.str_to_obj(wn.boot.server_date); |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 52 | var expires_on = dateutil.str_to_obj(wn.boot.expires_on); |
| 53 | var diff = dateutil.get_diff(expires_on, today); |
Anand Doshi | 5f17be8 | 2012-12-15 18:38:18 +0530 | [diff] [blame] | 54 | var payment_link = "<a href=\"https://erpnext.com/modes-of-payment.html\" target=\"_blank\">See Payment Options.</a>"; |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 55 | 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 Doshi | 5f17be8 | 2012-12-15 18:38:18 +0530 | [diff] [blame] | 60 | (and remove this annoying banner). %(payment_link)s\ |
| 61 | </div>', { expiry_string: expiry_string, payment_link: payment_link })); |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 62 | } else if (diff < 0) { |
| 63 | $('header').append(repl('<div class="expiry-info"> \ |
Anand Doshi | 5f17be8 | 2012-12-15 18:38:18 +0530 | [diff] [blame] | 64 | This ERPNext subscription <b>has expired</b>. %(payment_link)s\ |
| 65 | </div>', { expiry_string: expiry_string, payment_link: payment_link })); |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 66 | } |
| 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 Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 74 | erpnext.hide_naming_series = function() { |
| 75 | if(cur_frm.fields_dict.naming_series) { |
Anand Doshi | 60666a2 | 2013-04-12 20:19:53 +0530 | [diff] [blame] | 76 | cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal?true:false); |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 77 | } |
| 78 | } |
Rushabh Mehta | cebb027 | 2012-09-28 12:18:43 +0530 | [diff] [blame] | 79 | |
Rushabh Mehta | 079df38 | 2012-10-02 16:54:42 +0530 | [diff] [blame] | 80 | erpnext.setup_mousetrap = function() { |
Rushabh Mehta | dd790a5 | 2013-06-17 12:55:54 +0530 | [diff] [blame] | 81 | $(document).keydown("meta+g ctrl+g", function(e) { |
Rushabh Mehta | 079df38 | 2012-10-02 16:54:42 +0530 | [diff] [blame] | 82 | wn.ui.toolbar.search.show(); |
| 83 | return false; |
| 84 | }); |
Rushabh Mehta | dd790a5 | 2013-06-17 12:55:54 +0530 | [diff] [blame] | 85 | |
| 86 | $(document).keydown("meta+s ctrl+s", function(e) { |
| 87 | if(cur_frm) { |
| 88 | cur_frm.save_or_update(); |
| 89 | } |
Rushabh Mehta | ac7baf0 | 2012-10-03 12:22:13 +0530 | [diff] [blame] | 90 | else if(wn.container.page.save_action) |
| 91 | wn.container.page.save_action(); |
Rushabh Mehta | 079df38 | 2012-10-02 16:54:42 +0530 | [diff] [blame] | 92 | return false; |
Rushabh Mehta | dd790a5 | 2013-06-17 12:55:54 +0530 | [diff] [blame] | 93 | }) |
Rushabh Mehta | 079df38 | 2012-10-02 16:54:42 +0530 | [diff] [blame] | 94 | } |
Rushabh Mehta | b0d32b7 | 2012-09-28 16:11:57 +0530 | [diff] [blame] | 95 | |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 96 | // start |
| 97 | $(document).bind('startup', function() { |
| 98 | erpnext.startup.start(); |
Anand Doshi | 5f17be8 | 2012-12-15 18:38:18 +0530 | [diff] [blame] | 99 | }); |