Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +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 | |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 17 | var current_module; |
| 18 | var is_system_manager = 0; |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 19 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 20 | wn.provide('erpnext.startup'); |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 21 | |
Rushabh Mehta | a38bbe2 | 2012-02-29 10:55:43 +0530 | [diff] [blame] | 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', |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 33 | 'Activity': 'activity', |
Rushabh Mehta | a38bbe2 | 2012-02-29 10:55:43 +0530 | [diff] [blame] | 34 | 'To Do': 'todo', |
| 35 | 'Calendar': 'calendar', |
| 36 | 'Messages': 'messages', |
Rushabh Mehta | 428929b | 2012-03-01 11:24:45 +0530 | [diff] [blame] | 37 | 'Knowledge Base': 'questions', |
| 38 | 'Dashboard': 'dashboard' |
Rushabh Mehta | a38bbe2 | 2012-02-29 10:55:43 +0530 | [diff] [blame] | 39 | } |
| 40 | |
Anand Doshi | b8660fb | 2012-04-20 11:21:47 +0530 | [diff] [blame] | 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 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 46 | erpnext.startup.set_globals = function() { |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 47 | if(inList(user_roles,'System Manager')) is_system_manager = 1; |
| 48 | } |
Rushabh Mehta | 8c309be | 2012-01-20 13:47:16 +0530 | [diff] [blame] | 49 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 50 | erpnext.startup.start = function() { |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 51 | console.log('Starting up...'); |
Rushabh Mehta | 9c7a01a | 2012-01-25 11:04:54 +0530 | [diff] [blame] | 52 | $('#startup_div').html('Starting up...').toggle(true); |
| 53 | |
Rushabh Mehta | 70f7674 | 2012-03-01 18:42:05 +0530 | [diff] [blame] | 54 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 55 | erpnext.startup.set_globals(); |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 56 | |
Rushabh Mehta | 412a65c | 2012-02-29 18:38:18 +0530 | [diff] [blame] | 57 | if(wn.boot.user_background) { |
| 58 | erpnext.set_user_background(wn.boot.user_background); |
| 59 | } |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 60 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 61 | if(user == 'Guest'){ |
Rushabh Mehta | 983a171 | 2012-03-21 13:35:34 +0530 | [diff] [blame] | 62 | if(wn.boot.custom_css) { |
| 63 | set_style(wn.boot.custom_css); |
| 64 | } |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 65 | if(wn.boot.website_settings.title_prefix) { |
| 66 | wn.title_prefix = wn.boot.website_settings.title_prefix; |
| 67 | } |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 68 | if(wn.boot.startup_code) { |
| 69 | eval(wn.boot.startup_code); |
| 70 | } |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 71 | } else { |
Rushabh Mehta | 428929b | 2012-03-01 11:24:45 +0530 | [diff] [blame] | 72 | // always allow apps |
| 73 | wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat( |
Rushabh Mehta | cc131af | 2012-03-01 13:35:07 +0530 | [diff] [blame] | 74 | ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages']) |
Anand Doshi | 2d4139c | 2012-03-23 14:46:07 +0530 | [diff] [blame] | 75 | // allow dashboard to accounts manager |
| 76 | if(user_roles.indexOf('Accounts Manager')!=-1) { |
| 77 | wn.boot.profile.allow_modules.push('Dashboard'); |
| 78 | } |
Rushabh Mehta | 428929b | 2012-03-01 11:24:45 +0530 | [diff] [blame] | 79 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 80 | // setup toolbar |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 81 | erpnext.toolbar.setup(); |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 82 | |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 83 | // set interval for updates |
| 84 | erpnext.startup.set_periodic_updates(); |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 85 | |
| 86 | // border to the body |
| 87 | // ------------------ |
Rushabh Mehta | d48417c | 2012-03-19 18:42:13 +0530 | [diff] [blame] | 88 | //$('footer').html('<div class="web-footer erpnext-footer">\ |
| 89 | // <a href="#!attributions">ERPNext | Attributions and License</a></div>'); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 90 | |
| 91 | // complete registration |
| 92 | if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) { |
| 93 | wn.require("erpnext/startup/js/complete_setup.js"); |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 94 | erpnext.complete_setup.show(); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 95 | } |
Anand Doshi | 8cffe7e | 2012-04-30 12:13:51 +0530 | [diff] [blame] | 96 | if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) { |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 97 | var today = dateutil.str_to_obj(dateutil.get_today()); |
| 98 | var expires_on = dateutil.str_to_obj(wn.boot.expires_on); |
| 99 | var diff = dateutil.get_diff(expires_on, today); |
| 100 | if (0 <= diff && diff <= 15) { |
| 101 | var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff }); |
| 102 | $('header').append(repl('<div class="expiry-info"> \ |
Anand Doshi | 84777ac | 2012-04-30 18:33:32 +0530 | [diff] [blame] | 103 | Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \ |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 104 | Please renew your subscription to continue using ERPNext \ |
| 105 | (and remove this annoying banner). \ |
| 106 | </div>', { expiry_string: expiry_string })); |
| 107 | } else if (diff < 0) { |
| 108 | $('header').append(repl('<div class="expiry-info"> \ |
Anand Doshi | 84777ac | 2012-04-30 18:33:32 +0530 | [diff] [blame] | 109 | This ERPNext subscription <b>has expired</b> and should be deleted. \ |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 110 | </div>', { expiry_string: expiry_string })); |
| 111 | } |
| 112 | } |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 113 | |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 114 | } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 115 | |
Anand Doshi | c9d1ac4 | 2012-04-17 13:54:53 +0530 | [diff] [blame] | 116 | erpnext.set_about(); |
| 117 | |
Rushabh Mehta | 9c7a01a | 2012-01-25 11:04:54 +0530 | [diff] [blame] | 118 | $('#startup_div').toggle(false); |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 119 | } |
| 120 | |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 121 | // chart of accounts |
| 122 | // ==================================================================== |
| 123 | show_chart_browser = function(nm, chart_type){ |
| 124 | |
| 125 | var call_back = function(){ |
| 126 | if(nm == 'Sales Browser'){ |
| 127 | var sb_obj = new SalesBrowser(); |
| 128 | sb_obj.set_val(chart_type); |
| 129 | } |
| 130 | else if(nm == 'Accounts Browser') |
| 131 | pscript.make_chart(chart_type); |
| 132 | } |
| 133 | loadpage(nm,call_back); |
| 134 | } |
| 135 | |
| 136 | |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 137 | // ========== Update Messages ============ |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 138 | var update_messages = function(reset) { |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 139 | // Updates Team Messages |
| 140 | |
Anand Doshi | a7158f6 | 2012-03-19 14:41:05 +0530 | [diff] [blame] | 141 | if(inList(['Guest'], user) || !wn.session_alive) { return; } |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 142 | |
| 143 | if(!reset) { |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 144 | var set_messages = function(r) { |
| 145 | if(!r.exc) { |
| 146 | // This function is defined in toolbar.js |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 147 | erpnext.toolbar.set_new_comments(r.message.unread_messages); |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 148 | |
| 149 | var show_in_circle = function(parent_id, msg) { |
| 150 | var parent = $('#'+parent_id); |
| 151 | if(parent) { |
| 152 | if(msg) { |
| 153 | parent.find('span:first').text(msg); |
| 154 | parent.toggle(true); |
| 155 | } else { |
| 156 | parent.toggle(false); |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 157 | } |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 158 | } |
| 159 | } |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 160 | |
| 161 | show_in_circle('unread_messages', r.message.unread_messages.length); |
| 162 | show_in_circle('open_support_tickets', r.message.open_support_tickets); |
| 163 | show_in_circle('things_todo', r.message.things_todo); |
| 164 | show_in_circle('todays_events', r.message.todays_events); |
| 165 | |
| 166 | } else { |
| 167 | clearInterval(wn.updates.id); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 168 | } |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | wn.call({ |
| 172 | method: 'startup.startup.get_global_status_messages', |
| 173 | callback: set_messages |
| 174 | }); |
| 175 | |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 176 | } else { |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 177 | erpnext.toolbar.set_new_comments(0); |
Anand Doshi | 7854f81 | 2012-03-14 12:01:13 +0530 | [diff] [blame] | 178 | $('#unread_messages').toggle(false); |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 179 | } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | erpnext.startup.set_periodic_updates = function() { |
| 183 | // Set interval for periodic updates of team messages |
| 184 | wn.updates = {}; |
| 185 | |
| 186 | if(wn.updates.id) { |
| 187 | clearInterval(wn.updates.id); |
| 188 | } |
| 189 | |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 190 | wn.updates.id = setInterval(update_messages, 60000); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 191 | } |
| 192 | |
Rushabh Mehta | 412a65c | 2012-02-29 18:38:18 +0530 | [diff] [blame] | 193 | erpnext.set_user_background = function(src) { |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 194 | set_style(repl('#body_div { background: url("files/%(src)s") repeat;}', {src:src})) |
Rushabh Mehta | 412a65c | 2012-02-29 18:38:18 +0530 | [diff] [blame] | 195 | } |
| 196 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 197 | // start |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 198 | $(document).bind('startup', function() { |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 199 | erpnext.startup.start(); |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 200 | }); |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 201 | |
| 202 | // subject, sender, description |
| 203 | erpnext.send_message = function(opts) { |
| 204 | if(opts.btn) { |
| 205 | $(opts.btn).start_working(); |
| 206 | } |
| 207 | wn.call({ |
| 208 | method: 'website.send_message', |
| 209 | args: opts, |
| 210 | callback: function(r) { |
| 211 | if(opts.btn) { |
| 212 | $(opts.btn).done_working(); |
| 213 | } |
| 214 | if(opts.callback)opts.callback(r) |
| 215 | } |
| 216 | }); |
| 217 | } |
Rushabh Mehta | 79a664b | 2012-04-30 16:12:03 +0530 | [diff] [blame] | 218 | |
| 219 | erpnext.hide_naming_series = function() { |
| 220 | if(cur_frm.fields_dict.naming_series) { |
| 221 | hide_field('naming_series'); |
| 222 | if(cur_frm.doc.__islocal) { |
| 223 | unhide_field('naming_series'); |
| 224 | } |
| 225 | } |
| 226 | } |