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