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']) |
Rushabh Mehta | 428929b | 2012-03-01 11:24:45 +0530 | [diff] [blame] | 75 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 76 | // setup toolbar |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 77 | erpnext.toolbar.setup(); |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 78 | |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 79 | // set interval for updates |
| 80 | erpnext.startup.set_periodic_updates(); |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 81 | |
| 82 | // border to the body |
| 83 | // ------------------ |
Rushabh Mehta | ef048f7 | 2012-05-01 14:56:20 +0530 | [diff] [blame] | 84 | $('footer').html('<div class="web-footer erpnext-footer">\ |
| 85 | <a href="#!attributions">ERPNext | Attributions and License</a></div>'); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 86 | |
| 87 | // complete registration |
| 88 | if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) { |
| 89 | wn.require("erpnext/startup/js/complete_setup.js"); |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 90 | erpnext.complete_setup.show(); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 91 | } |
Anand Doshi | 8cffe7e | 2012-04-30 12:13:51 +0530 | [diff] [blame] | 92 | if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) { |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 93 | var today = dateutil.str_to_obj(dateutil.get_today()); |
| 94 | var expires_on = dateutil.str_to_obj(wn.boot.expires_on); |
| 95 | var diff = dateutil.get_diff(expires_on, today); |
| 96 | if (0 <= diff && diff <= 15) { |
| 97 | var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff }); |
| 98 | $('header').append(repl('<div class="expiry-info"> \ |
Anand Doshi | 84777ac | 2012-04-30 18:33:32 +0530 | [diff] [blame] | 99 | Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \ |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 100 | Please renew your subscription to continue using ERPNext \ |
| 101 | (and remove this annoying banner). \ |
| 102 | </div>', { expiry_string: expiry_string })); |
| 103 | } else if (diff < 0) { |
| 104 | $('header').append(repl('<div class="expiry-info"> \ |
Anand Doshi | 563fcc1 | 2012-04-30 21:06:31 +0530 | [diff] [blame] | 105 | This ERPNext subscription <b>has expired</b>. \ |
Anand Doshi | 1ed4ef1 | 2012-04-27 15:30:23 +0530 | [diff] [blame] | 106 | </div>', { expiry_string: expiry_string })); |
| 107 | } |
| 108 | } |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 109 | |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 110 | } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 111 | |
Anand Doshi | c9d1ac4 | 2012-04-17 13:54:53 +0530 | [diff] [blame] | 112 | erpnext.set_about(); |
Rushabh Mehta | aa51377 | 2012-05-02 13:03:41 +0530 | [diff] [blame] | 113 | if(wn.control_panel.custom_startup_code) |
| 114 | eval(wn.control_panel.custom_startup_code); |
Rushabh Mehta | d5e1031 | 2012-05-02 17:44:59 +0530 | [diff] [blame] | 115 | |
| 116 | $('body').append('<a class="erpnext-logo" title="Powered by ERPNext" href="http://erpnext.com" target="_blank"></a>') |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 120 | // ========== Update Messages ============ |
Rushabh Mehta | d5e1031 | 2012-05-02 17:44:59 +0530 | [diff] [blame] | 121 | erpnext.update_messages = function(reset) { |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 122 | // Updates Team Messages |
| 123 | |
Anand Doshi | a7158f6 | 2012-03-19 14:41:05 +0530 | [diff] [blame] | 124 | if(inList(['Guest'], user) || !wn.session_alive) { return; } |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 125 | |
| 126 | if(!reset) { |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 127 | var set_messages = function(r) { |
| 128 | if(!r.exc) { |
| 129 | // This function is defined in toolbar.js |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 130 | erpnext.toolbar.set_new_comments(r.message.unread_messages); |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 131 | |
| 132 | var show_in_circle = function(parent_id, msg) { |
| 133 | var parent = $('#'+parent_id); |
| 134 | if(parent) { |
| 135 | if(msg) { |
| 136 | parent.find('span:first').text(msg); |
| 137 | parent.toggle(true); |
| 138 | } else { |
| 139 | parent.toggle(false); |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 140 | } |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 141 | } |
| 142 | } |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 143 | |
| 144 | show_in_circle('unread_messages', r.message.unread_messages.length); |
| 145 | show_in_circle('open_support_tickets', r.message.open_support_tickets); |
| 146 | show_in_circle('things_todo', r.message.things_todo); |
| 147 | show_in_circle('todays_events', r.message.todays_events); |
| 148 | |
| 149 | } else { |
| 150 | clearInterval(wn.updates.id); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 151 | } |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | wn.call({ |
| 155 | method: 'startup.startup.get_global_status_messages', |
| 156 | callback: set_messages |
| 157 | }); |
| 158 | |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 159 | } else { |
Anand Doshi | 2aa9ba6 | 2012-04-30 15:43:34 +0530 | [diff] [blame] | 160 | erpnext.toolbar.set_new_comments(0); |
Anand Doshi | 7854f81 | 2012-03-14 12:01:13 +0530 | [diff] [blame] | 161 | $('#unread_messages').toggle(false); |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 162 | } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | erpnext.startup.set_periodic_updates = function() { |
| 166 | // Set interval for periodic updates of team messages |
| 167 | wn.updates = {}; |
| 168 | |
| 169 | if(wn.updates.id) { |
| 170 | clearInterval(wn.updates.id); |
| 171 | } |
| 172 | |
Rushabh Mehta | d5e1031 | 2012-05-02 17:44:59 +0530 | [diff] [blame] | 173 | wn.updates.id = setInterval(erpnext.update_messages, 60000); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 174 | } |
| 175 | |
Rushabh Mehta | 412a65c | 2012-02-29 18:38:18 +0530 | [diff] [blame] | 176 | erpnext.set_user_background = function(src) { |
Rushabh Mehta | 702473d | 2012-04-26 19:01:35 +0530 | [diff] [blame] | 177 | 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] | 178 | } |
| 179 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 180 | // start |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 181 | $(document).bind('startup', function() { |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 182 | erpnext.startup.start(); |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 183 | }); |
Rushabh Mehta | 389880d | 2012-04-27 18:39:14 +0530 | [diff] [blame] | 184 | |
| 185 | // subject, sender, description |
| 186 | erpnext.send_message = function(opts) { |
| 187 | if(opts.btn) { |
| 188 | $(opts.btn).start_working(); |
| 189 | } |
| 190 | wn.call({ |
| 191 | method: 'website.send_message', |
| 192 | args: opts, |
| 193 | callback: function(r) { |
| 194 | if(opts.btn) { |
| 195 | $(opts.btn).done_working(); |
| 196 | } |
| 197 | if(opts.callback)opts.callback(r) |
| 198 | } |
| 199 | }); |
| 200 | } |
Rushabh Mehta | 30e3f15 | 2012-05-01 14:07:41 +0530 | [diff] [blame] | 201 | |
| 202 | erpnext.hide_naming_series = function() { |
| 203 | if(cur_frm.fields_dict.naming_series) { |
| 204 | hide_field('naming_series'); |
| 205 | if(cur_frm.doc.__islocal) { |
| 206 | unhide_field('naming_series'); |
| 207 | } |
| 208 | } |
| 209 | } |