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() { |
| 42 | pscript.is_erpnext_saas = cint(wn.control_panel.sync_with_gateway) |
| 43 | if(inList(user_roles,'System Manager')) is_system_manager = 1; |
| 44 | } |
Rushabh Mehta | 8c309be | 2012-01-20 13:47:16 +0530 | [diff] [blame] | 45 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 46 | erpnext.startup.start = function() { |
Rushabh Mehta | 9c7a01a | 2012-01-25 11:04:54 +0530 | [diff] [blame] | 47 | $('#startup_div').html('Starting up...').toggle(true); |
| 48 | |
Rushabh Mehta | 70f7674 | 2012-03-01 18:42:05 +0530 | [diff] [blame] | 49 | if(!erpnext.check_browser_support()) |
| 50 | return; |
| 51 | |
| 52 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 53 | erpnext.startup.set_globals(); |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 54 | |
| 55 | if(wn.boot.custom_css) { |
| 56 | set_style(wn.boot.custom_css); |
| 57 | } |
Rushabh Mehta | 412a65c | 2012-02-29 18:38:18 +0530 | [diff] [blame] | 58 | if(wn.boot.user_background) { |
| 59 | erpnext.set_user_background(wn.boot.user_background); |
| 60 | } |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 61 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 62 | if(user == 'Guest'){ |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 63 | if(wn.boot.website_settings.title_prefix) { |
| 64 | wn.title_prefix = wn.boot.website_settings.title_prefix; |
| 65 | } |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 66 | } else { |
Rushabh Mehta | 428929b | 2012-03-01 11:24:45 +0530 | [diff] [blame] | 67 | // always allow apps |
| 68 | wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat( |
Rushabh Mehta | cc131af | 2012-03-01 13:35:07 +0530 | [diff] [blame] | 69 | ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages']) |
Rushabh Mehta | 428929b | 2012-03-01 11:24:45 +0530 | [diff] [blame] | 70 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 71 | // setup toolbar |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 72 | erpnext.toolbar.setup(); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 73 | |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 74 | // set interval for updates |
| 75 | erpnext.startup.set_periodic_updates(); |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 76 | |
| 77 | // border to the body |
| 78 | // ------------------ |
Anand Doshi | 01a7558 | 2012-02-24 19:35:09 +0530 | [diff] [blame] | 79 | $('footer').html('<div class="web-footer erpnext-footer">\ |
Rushabh Mehta | 4c1e9e7 | 2012-03-01 13:30:34 +0530 | [diff] [blame] | 80 | <a href="#!attributions">ERPNext | Attributions and License</a></div>'); |
Rushabh Mehta | 12852e7 | 2012-02-29 15:11:06 +0530 | [diff] [blame] | 81 | |
| 82 | // complete registration |
| 83 | if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) { |
| 84 | wn.require("erpnext/startup/js/complete_setup.js"); |
| 85 | erpnext.complete_setup(); |
| 86 | } |
| 87 | |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 88 | } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 89 | |
Rushabh Mehta | 9c7a01a | 2012-01-25 11:04:54 +0530 | [diff] [blame] | 90 | $('#startup_div').toggle(false); |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 91 | } |
| 92 | |
Rushabh Mehta | 70f7674 | 2012-03-01 18:42:05 +0530 | [diff] [blame] | 93 | erpnext.check_browser_support = function() { |
| 94 | var is_supported = function() { |
| 95 | if($.browser.mozilla && flt($.browser.version)<4) return false; |
| 96 | if($.browser.msie && flt($.browser.version)<9) return false; |
| 97 | if($.browser.webkit && flt($.browser.version)<534) return false; |
| 98 | return true; |
| 99 | } |
| 100 | var s = is_supported(); |
| 101 | if(!s) { |
| 102 | $('body').html('<div style="width: 900px; margin: 20px auto; padding: 20px;\ |
| 103 | background-color: #fff; border: 2px solid #aaa; font-family: Arial">\ |
| 104 | <h3>Unsupported Browser</h3> \ |
| 105 | <p><i>ERPNext requires a modern web browser to function correctly</i></p> \ |
| 106 | <p>Supported browsers are: \ |
| 107 | <ul><li><a href="http://mozilla.com/firefox">Mozilla Firfox 4+</a>, \ |
| 108 | <li><a href="http://google.com/chrome">Google Chorme 14+</a>, \ |
| 109 | <li><a href="http://apple.com/safari">Apple Safari 5+</a>, \ |
| 110 | <li><a href="http://ie.microsoft.com">Microsoft Internet Explorer 9+</a>, \ |
| 111 | <li><a href="http://www.opera.com/">Opera</a></p></ul>') |
| 112 | } |
| 113 | return s; |
| 114 | } |
| 115 | |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 116 | // chart of accounts |
| 117 | // ==================================================================== |
| 118 | show_chart_browser = function(nm, chart_type){ |
| 119 | |
| 120 | var call_back = function(){ |
| 121 | if(nm == 'Sales Browser'){ |
| 122 | var sb_obj = new SalesBrowser(); |
| 123 | sb_obj.set_val(chart_type); |
| 124 | } |
| 125 | else if(nm == 'Accounts Browser') |
| 126 | pscript.make_chart(chart_type); |
| 127 | } |
| 128 | loadpage(nm,call_back); |
| 129 | } |
| 130 | |
| 131 | |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 132 | // ========== Update Messages ============ |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 133 | var update_messages = function(reset) { |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 134 | // Updates Team Messages |
| 135 | |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 136 | if(inList(['Guest'], user)) { return; } |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 137 | |
| 138 | if(!reset) { |
| 139 | $c_page('home', 'event_updates', 'get_unread_messages', null, |
| 140 | function(r,rt) { |
| 141 | if(!r.exc) { |
| 142 | // This function is defined in toolbar.js |
| 143 | page_body.wntoolbar.set_new_comments(r.message); |
| 144 | var circle = $('#msg_count') |
| 145 | if(circle) { |
| 146 | if(r.message.length) { |
| 147 | circle.find('span:first').text(r.message.length); |
| 148 | circle.toggle(true); |
| 149 | } else { |
| 150 | circle.toggle(false); |
| 151 | } |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 152 | } |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 153 | } else { |
| 154 | clearInterval(wn.updates.id); |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 155 | } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 156 | } |
Anand Doshi | 08c8edb | 2012-03-01 14:53:05 +0530 | [diff] [blame] | 157 | ); |
| 158 | } else { |
| 159 | page_body.wntoolbar.set_new_comments(0); |
| 160 | $('#msg_count').toggle(false); |
| 161 | } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | erpnext.startup.set_periodic_updates = function() { |
| 165 | // Set interval for periodic updates of team messages |
| 166 | wn.updates = {}; |
| 167 | |
| 168 | if(wn.updates.id) { |
| 169 | clearInterval(wn.updates.id); |
| 170 | } |
| 171 | |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 172 | wn.updates.id = setInterval(update_messages, 60000); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 173 | } |
| 174 | |
Rushabh Mehta | 412a65c | 2012-02-29 18:38:18 +0530 | [diff] [blame] | 175 | erpnext.set_user_background = function(src) { |
| 176 | set_style(repl('body { background: url("files/%(src)s") repeat !important;}', {src:src})) |
| 177 | } |
| 178 | |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 179 | // ======================================= |
| 180 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 181 | // start |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 182 | $(document).bind('startup', function() { |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 183 | erpnext.startup.start(); |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 184 | }); |