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 | |
| 22 | erpnext.modules = { |
| 23 | 'Selling': 'selling-home', |
| 24 | 'Accounts': 'accounts-home', |
| 25 | 'Stock': 'stock-home', |
| 26 | 'Buying': 'buying-home', |
| 27 | 'Support': 'support-home', |
| 28 | 'Projects': 'projects-home', |
| 29 | 'Production': 'production-home', |
| 30 | 'Website': 'website-home', |
| 31 | 'HR': 'hr-home', |
| 32 | 'Setup': 'Setup', |
| 33 | 'Activity': 'activity', |
| 34 | 'To Do': 'todo', |
| 35 | 'Calendar': 'calendar', |
| 36 | 'Messages': 'messages', |
| 37 | 'Knowledge Base': 'questions', |
| 38 | 'Dashboard': 'dashboard' |
| 39 | } |
| 40 | |
| 41 | // wn.modules is used in breadcrumbs for getting module home page |
| 42 | wn.provide('wn.modules'); |
| 43 | $.extend(wn.modules, erpnext.modules); |
| 44 | wn.modules['Core'] = 'Setup'; |
| 45 | |
| 46 | erpnext.startup.set_globals = function() { |
| 47 | if(inList(user_roles,'System Manager')) is_system_manager = 1; |
| 48 | } |
| 49 | |
| 50 | erpnext.startup.start = function() { |
| 51 | console.log('Starting up...'); |
| 52 | $('#startup_div').html('Starting up...').toggle(true); |
| 53 | |
| 54 | |
| 55 | erpnext.startup.set_globals(); |
| 56 | |
| 57 | if(user != 'Guest'){ |
| 58 | if(wn.boot.user_background) { |
| 59 | erpnext.set_user_background(wn.boot.user_background); |
| 60 | } |
| 61 | |
| 62 | // always allow apps |
| 63 | wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat( |
| 64 | ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages']) |
| 65 | |
| 66 | // setup toolbar |
| 67 | erpnext.toolbar.setup(); |
| 68 | |
| 69 | // set interval for updates |
| 70 | erpnext.startup.set_periodic_updates(); |
| 71 | |
| 72 | // border to the body |
| 73 | // ------------------ |
| 74 | $('footer').html('<div class="web-footer erpnext-footer">\ |
| 75 | <a href="#!attributions">ERPNext | Attributions and License</a></div>'); |
| 76 | |
| 77 | // complete registration |
| 78 | if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) { |
| 79 | wn.require("app/js/complete_setup.js"); |
| 80 | erpnext.complete_setup.show(); |
| 81 | } |
| 82 | if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) { |
| 83 | var today = dateutil.str_to_obj(dateutil.get_today()); |
| 84 | var expires_on = dateutil.str_to_obj(wn.boot.expires_on); |
| 85 | var diff = dateutil.get_diff(expires_on, today); |
| 86 | if (0 <= diff && diff <= 15) { |
| 87 | var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff }); |
| 88 | $('header').append(repl('<div class="expiry-info"> \ |
| 89 | Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \ |
| 90 | Please renew your subscription to continue using ERPNext \ |
| 91 | (and remove this annoying banner). \ |
| 92 | </div>', { expiry_string: expiry_string })); |
| 93 | } else if (diff < 0) { |
| 94 | $('header').append(repl('<div class="expiry-info"> \ |
| 95 | This ERPNext subscription <b>has expired</b>. \ |
| 96 | </div>', { expiry_string: expiry_string })); |
| 97 | } |
| 98 | } |
| 99 | erpnext.set_about(); |
| 100 | if(wn.control_panel.custom_startup_code) |
| 101 | eval(wn.control_panel.custom_startup_code); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | |
| 106 | // ========== Update Messages ============ |
| 107 | erpnext.update_messages = function(reset) { |
| 108 | // Updates Team Messages |
| 109 | |
| 110 | if(inList(['Guest'], user) || !wn.session_alive) { return; } |
| 111 | |
| 112 | if(!reset) { |
| 113 | var set_messages = function(r) { |
| 114 | if(!r.exc) { |
| 115 | // This function is defined in toolbar.js |
| 116 | erpnext.toolbar.set_new_comments(r.message.unread_messages); |
| 117 | |
| 118 | var show_in_circle = function(parent_id, msg) { |
| 119 | var parent = $('#'+parent_id); |
| 120 | if(parent) { |
| 121 | if(msg) { |
| 122 | parent.find('span:first').text(msg); |
| 123 | parent.toggle(true); |
| 124 | } else { |
| 125 | parent.toggle(false); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | show_in_circle('unread_messages', r.message.unread_messages.length); |
| 131 | show_in_circle('open_support_tickets', r.message.open_support_tickets); |
| 132 | show_in_circle('things_todo', r.message.things_todo); |
| 133 | show_in_circle('todays_events', r.message.todays_events); |
| 134 | show_in_circle('open_tasks', r.message.open_tasks); |
| 135 | show_in_circle('unanswered_questions', r.message.unanswered_questions); |
| 136 | |
| 137 | } else { |
| 138 | clearInterval(wn.updates.id); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | wn.call({ |
| 143 | method: 'startup.startup.get_global_status_messages', |
| 144 | callback: set_messages |
| 145 | }); |
| 146 | |
| 147 | } else { |
| 148 | erpnext.toolbar.set_new_comments(0); |
| 149 | $('#unread_messages').toggle(false); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | erpnext.startup.set_periodic_updates = function() { |
| 154 | // Set interval for periodic updates of team messages |
| 155 | wn.updates = {}; |
| 156 | |
| 157 | if(wn.updates.id) { |
| 158 | clearInterval(wn.updates.id); |
| 159 | } |
| 160 | |
| 161 | wn.updates.id = setInterval(erpnext.update_messages, 60000); |
| 162 | } |
| 163 | |
| 164 | erpnext.set_user_background = function(src) { |
| 165 | set_style(repl('#body_div { background: url("files/%(src)s") repeat;}', {src:src})) |
| 166 | } |
| 167 | |
| 168 | // start |
| 169 | $(document).bind('startup', function() { |
| 170 | erpnext.startup.start(); |
| 171 | }); |
| 172 | |
| 173 | // subject, sender, description |
| 174 | erpnext.send_message = function(opts) { |
| 175 | if(opts.btn) { |
| 176 | $(opts.btn).start_working(); |
| 177 | } |
| 178 | wn.call({ |
| 179 | method: 'website.send_message', |
| 180 | args: opts, |
| 181 | callback: function(r) { |
| 182 | if(opts.btn) { |
| 183 | $(opts.btn).done_working(); |
| 184 | } |
| 185 | if(opts.callback)opts.callback(r) |
| 186 | } |
| 187 | }); |
| 188 | } |
| 189 | |
| 190 | erpnext.hide_naming_series = function() { |
| 191 | if(cur_frm.fields_dict.naming_series) { |
| 192 | hide_field('naming_series'); |
| 193 | if(cur_frm.doc.__islocal) { |
| 194 | unhide_field('naming_series'); |
| 195 | } |
| 196 | } |
| 197 | } |