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 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 41 | erpnext.startup.set_globals = function() { |
Rushabh Mehta | cabfc65 | 2012-04-14 16:08:45 +0530 | [diff] [blame] | 42 | wn.control_panel.sync_with_gateway = wn.boot.sync_with_gateway |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 43 | pscript.is_erpnext_saas = cint(wn.control_panel.sync_with_gateway) |
| 44 | if(inList(user_roles,'System Manager')) is_system_manager = 1; |
| 45 | } |
Rushabh Mehta | 8c309be | 2012-01-20 13:47:16 +0530 | [diff] [blame] | 46 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 47 | erpnext.startup.start = function() { |
Rushabh Mehta | 9c7a01a | 2012-01-25 11:04:54 +0530 | [diff] [blame] | 48 | $('#startup_div').html('Starting up...').toggle(true); |
| 49 | |
Rushabh Mehta | 70f7674 | 2012-03-01 18:42:05 +0530 | [diff] [blame] | 50 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 51 | erpnext.startup.set_globals(); |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 52 | |
Rushabh Mehta | 412a65c | 2012-02-29 18:38:18 +0530 | [diff] [blame] | 53 | if(wn.boot.user_background) { |
| 54 | erpnext.set_user_background(wn.boot.user_background); |
| 55 | } |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 56 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 57 | if(user == 'Guest'){ |
Rushabh Mehta | 983a171 | 2012-03-21 13:35:34 +0530 | [diff] [blame] | 58 | if(wn.boot.custom_css) { |
| 59 | set_style(wn.boot.custom_css); |
| 60 | } |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 61 | if(wn.boot.website_settings.title_prefix) { |
| 62 | wn.title_prefix = wn.boot.website_settings.title_prefix; |
| 63 | } |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 64 | } else { |
Rushabh Mehta | 428929b | 2012-03-01 11:24:45 +0530 | [diff] [blame] | 65 | // always allow apps |
| 66 | wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat( |
Rushabh Mehta | cc131af | 2012-03-01 13:35:07 +0530 | [diff] [blame] | 67 | ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages']) |
Anand Doshi | 2d4139c | 2012-03-23 14:46:07 +0530 | [diff] [blame] | 68 | // allow dashboard to accounts manager |
| 69 | if(user_roles.indexOf('Accounts Manager')!=-1) { |
| 70 | wn.boot.profile.allow_modules.push('Dashboard'); |
| 71 | } |
Rushabh Mehta | 428929b | 2012-03-01 11:24:45 +0530 | [diff] [blame] | 72 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 73 | // setup toolbar |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 74 | erpnext.toolbar.setup(); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 75 | |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 76 | // set interval for updates |
| 77 | erpnext.startup.set_periodic_updates(); |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 78 | |
| 79 | // border to the body |
| 80 | // ------------------ |
Rushabh Mehta | d48417c | 2012-03-19 18:42:13 +0530 | [diff] [blame] | 81 | //$('footer').html('<div class="web-footer erpnext-footer">\ |
| 82 | // <a href="#!attributions">ERPNext | Attributions and License</a></div>'); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 83 | |
| 84 | // complete registration |
| 85 | if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) { |
| 86 | wn.require("erpnext/startup/js/complete_setup.js"); |
| 87 | erpnext.complete_setup(); |
| 88 | } |
| 89 | |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 90 | } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 91 | |
Anand Doshi | c9d1ac4 | 2012-04-17 13:54:53 +0530 | [diff] [blame] | 92 | erpnext.set_about(); |
| 93 | |
Rushabh Mehta | 9c7a01a | 2012-01-25 11:04:54 +0530 | [diff] [blame] | 94 | $('#startup_div').toggle(false); |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 95 | } |
| 96 | |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 97 | // chart of accounts |
| 98 | // ==================================================================== |
| 99 | show_chart_browser = function(nm, chart_type){ |
| 100 | |
| 101 | var call_back = function(){ |
| 102 | if(nm == 'Sales Browser'){ |
| 103 | var sb_obj = new SalesBrowser(); |
| 104 | sb_obj.set_val(chart_type); |
| 105 | } |
| 106 | else if(nm == 'Accounts Browser') |
| 107 | pscript.make_chart(chart_type); |
| 108 | } |
| 109 | loadpage(nm,call_back); |
| 110 | } |
| 111 | |
| 112 | |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 113 | // ========== Update Messages ============ |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 114 | var update_messages = function(reset) { |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 115 | // Updates Team Messages |
| 116 | |
Anand Doshi | a7158f6 | 2012-03-19 14:41:05 +0530 | [diff] [blame] | 117 | if(inList(['Guest'], user) || !wn.session_alive) { return; } |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 118 | |
| 119 | if(!reset) { |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 120 | var set_messages = function(r) { |
| 121 | if(!r.exc) { |
| 122 | // This function is defined in toolbar.js |
| 123 | wn.container.wntoolbar.set_new_comments(r.message.unread_messages); |
| 124 | |
| 125 | var show_in_circle = function(parent_id, msg) { |
| 126 | var parent = $('#'+parent_id); |
| 127 | if(parent) { |
| 128 | if(msg) { |
| 129 | parent.find('span:first').text(msg); |
| 130 | parent.toggle(true); |
| 131 | } else { |
| 132 | parent.toggle(false); |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 133 | } |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 134 | } |
| 135 | } |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 136 | |
| 137 | show_in_circle('unread_messages', r.message.unread_messages.length); |
| 138 | show_in_circle('open_support_tickets', r.message.open_support_tickets); |
| 139 | show_in_circle('things_todo', r.message.things_todo); |
| 140 | show_in_circle('todays_events', r.message.todays_events); |
| 141 | |
| 142 | } else { |
| 143 | clearInterval(wn.updates.id); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 144 | } |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | wn.call({ |
| 148 | method: 'startup.startup.get_global_status_messages', |
| 149 | callback: set_messages |
| 150 | }); |
| 151 | |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 152 | } else { |
Rushabh Mehta | 7afaa86 | 2012-03-16 18:28:09 +0530 | [diff] [blame] | 153 | wn.container.wntoolbar.set_new_comments(0); |
Anand Doshi | 7854f81 | 2012-03-14 12:01:13 +0530 | [diff] [blame] | 154 | $('#unread_messages').toggle(false); |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 155 | } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | erpnext.startup.set_periodic_updates = function() { |
| 159 | // Set interval for periodic updates of team messages |
| 160 | wn.updates = {}; |
| 161 | |
| 162 | if(wn.updates.id) { |
| 163 | clearInterval(wn.updates.id); |
| 164 | } |
| 165 | |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 166 | wn.updates.id = setInterval(update_messages, 60000); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 167 | } |
| 168 | |
Rushabh Mehta | 412a65c | 2012-02-29 18:38:18 +0530 | [diff] [blame] | 169 | erpnext.set_user_background = function(src) { |
Rushabh Mehta | 37f531b | 2012-03-02 11:29:09 +0530 | [diff] [blame] | 170 | set_style(repl('body { background: url("files/%(src)s") repeat;}', {src:src})) |
Rushabh Mehta | 412a65c | 2012-02-29 18:38:18 +0530 | [diff] [blame] | 171 | } |
| 172 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 173 | // start |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 174 | $(document).bind('startup', function() { |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 175 | erpnext.startup.start(); |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 176 | }); |