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(); |
| 34 | |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 35 | // 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 Mehta | 724bb47 | 2012-11-13 12:32:11 +0530 | [diff] [blame] | 48 | <a href="#attributions">Attributions and License</a> | \ |
| 49 | <a href="#latest-updates"><b>Latest Updates</b></a></div>'); |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 50 | |
| 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 Mehta | d1784cc | 2012-11-12 12:57:42 +0530 | [diff] [blame] | 57 | var today = dateutil.str_to_obj(wn.boot.server_date); |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 58 | var expires_on = dateutil.str_to_obj(wn.boot.expires_on); |
| 59 | var diff = dateutil.get_diff(expires_on, today); |
| 60 | if (0 <= diff && diff <= 15) { |
| 61 | var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff }); |
| 62 | $('header').append(repl('<div class="expiry-info"> \ |
| 63 | Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \ |
| 64 | Please renew your subscription to continue using ERPNext \ |
| 65 | (and remove this annoying banner). \ |
| 66 | </div>', { expiry_string: expiry_string })); |
| 67 | } else if (diff < 0) { |
| 68 | $('header').append(repl('<div class="expiry-info"> \ |
| 69 | This ERPNext subscription <b>has expired</b>. \ |
| 70 | </div>', { expiry_string: expiry_string })); |
| 71 | } |
| 72 | } |
| 73 | erpnext.set_about(); |
| 74 | if(wn.control_panel.custom_startup_code) |
| 75 | eval(wn.control_panel.custom_startup_code); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | |
| 80 | // ========== Update Messages ============ |
| 81 | erpnext.update_messages = function(reset) { |
| 82 | // Updates Team Messages |
| 83 | |
| 84 | if(inList(['Guest'], user) || !wn.session_alive) { return; } |
| 85 | |
| 86 | if(!reset) { |
| 87 | var set_messages = function(r) { |
| 88 | if(!r.exc) { |
| 89 | // This function is defined in toolbar.js |
| 90 | erpnext.toolbar.set_new_comments(r.message.unread_messages); |
| 91 | |
| 92 | var show_in_circle = function(parent_id, msg) { |
| 93 | var parent = $('#'+parent_id); |
| 94 | if(parent) { |
| 95 | if(msg) { |
| 96 | parent.find('span:first').text(msg); |
| 97 | parent.toggle(true); |
| 98 | } else { |
| 99 | parent.toggle(false); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
Rushabh Mehta | ec40686 | 2012-11-13 10:59:11 +0530 | [diff] [blame] | 104 | show_in_circle('unread_messages', r.message.unread_messages); |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 105 | show_in_circle('open_support_tickets', r.message.open_support_tickets); |
| 106 | show_in_circle('things_todo', r.message.things_todo); |
| 107 | show_in_circle('todays_events', r.message.todays_events); |
| 108 | show_in_circle('open_tasks', r.message.open_tasks); |
| 109 | show_in_circle('unanswered_questions', r.message.unanswered_questions); |
| 110 | |
| 111 | } else { |
| 112 | clearInterval(wn.updates.id); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | wn.call({ |
| 117 | method: 'startup.startup.get_global_status_messages', |
| 118 | callback: set_messages |
| 119 | }); |
| 120 | |
| 121 | } else { |
| 122 | erpnext.toolbar.set_new_comments(0); |
| 123 | $('#unread_messages').toggle(false); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | erpnext.startup.set_periodic_updates = function() { |
| 128 | // Set interval for periodic updates of team messages |
| 129 | wn.updates = {}; |
| 130 | |
| 131 | if(wn.updates.id) { |
| 132 | clearInterval(wn.updates.id); |
| 133 | } |
| 134 | |
| 135 | wn.updates.id = setInterval(erpnext.update_messages, 60000); |
| 136 | } |
| 137 | |
Rushabh Mehta | 2fa2f71 | 2012-09-24 19:13:42 +0530 | [diff] [blame] | 138 | // subject, sender, description |
| 139 | erpnext.send_message = function(opts) { |
| 140 | if(opts.btn) { |
| 141 | $(opts.btn).start_working(); |
| 142 | } |
| 143 | wn.call({ |
| 144 | method: 'website.send_message', |
| 145 | args: opts, |
| 146 | callback: function(r) { |
| 147 | if(opts.btn) { |
| 148 | $(opts.btn).done_working(); |
| 149 | } |
| 150 | if(opts.callback)opts.callback(r) |
| 151 | } |
| 152 | }); |
| 153 | } |
| 154 | |
| 155 | erpnext.hide_naming_series = function() { |
| 156 | if(cur_frm.fields_dict.naming_series) { |
| 157 | hide_field('naming_series'); |
| 158 | if(cur_frm.doc.__islocal) { |
| 159 | unhide_field('naming_series'); |
| 160 | } |
| 161 | } |
| 162 | } |
Rushabh Mehta | cebb027 | 2012-09-28 12:18:43 +0530 | [diff] [blame] | 163 | |
Rushabh Mehta | 079df38 | 2012-10-02 16:54:42 +0530 | [diff] [blame] | 164 | erpnext.setup_mousetrap = function() { |
| 165 | Mousetrap.bind(["command+g", "ctrl+g"], function() { |
| 166 | wn.ui.toolbar.search.show(); |
| 167 | return false; |
| 168 | }); |
Rushabh Mehta | cebb027 | 2012-09-28 12:18:43 +0530 | [diff] [blame] | 169 | |
Rushabh Mehta | 079df38 | 2012-10-02 16:54:42 +0530 | [diff] [blame] | 170 | Mousetrap.bind(["command+s", "ctrl+s"], function() { |
| 171 | if(cur_frm) |
| 172 | cur_frm.save(); |
Rushabh Mehta | ac7baf0 | 2012-10-03 12:22:13 +0530 | [diff] [blame] | 173 | else if(wn.container.page.save_action) |
| 174 | wn.container.page.save_action(); |
Rushabh Mehta | 079df38 | 2012-10-02 16:54:42 +0530 | [diff] [blame] | 175 | return false; |
| 176 | }); |
| 177 | } |
Rushabh Mehta | b0d32b7 | 2012-09-28 16:11:57 +0530 | [diff] [blame] | 178 | |
Rushabh Mehta | 9d1faea | 2012-10-02 14:56:41 +0530 | [diff] [blame] | 179 | // start |
| 180 | $(document).bind('startup', function() { |
| 181 | erpnext.startup.start(); |
Anand Doshi | e65e621 | 2012-11-19 15:43:18 +0530 | [diff] [blame] | 182 | }); |