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', |
| 33 | 'Activity': 'Event Updates', |
| 34 | 'To Do': 'todo', |
| 35 | 'Calendar': 'calendar', |
| 36 | 'Messages': 'messages', |
| 37 | 'Knowledge Base': 'questions' |
| 38 | } |
| 39 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 40 | erpnext.startup.set_globals = function() { |
| 41 | pscript.is_erpnext_saas = cint(wn.control_panel.sync_with_gateway) |
| 42 | if(inList(user_roles,'System Manager')) is_system_manager = 1; |
| 43 | } |
Rushabh Mehta | 8c309be | 2012-01-20 13:47:16 +0530 | [diff] [blame] | 44 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 45 | erpnext.startup.start = function() { |
Rushabh Mehta | 9c7a01a | 2012-01-25 11:04:54 +0530 | [diff] [blame] | 46 | $('#startup_div').html('Starting up...').toggle(true); |
| 47 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 48 | erpnext.startup.set_globals(); |
Rushabh Mehta | c5471dd | 2012-02-22 12:07:42 +0530 | [diff] [blame] | 49 | |
| 50 | if(wn.boot.custom_css) { |
| 51 | set_style(wn.boot.custom_css); |
| 52 | } |
| 53 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 54 | if(user == 'Guest'){ |
Rushabh Mehta | 7018b19 | 2012-02-02 13:42:28 +0530 | [diff] [blame] | 55 | if(wn.boot.website_settings.title_prefix) { |
| 56 | wn.title_prefix = wn.boot.website_settings.title_prefix; |
| 57 | } |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 58 | } else { |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 59 | // setup toolbar |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 60 | erpnext.toolbar.setup(); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 61 | |
| 62 | // set interval for updates |
| 63 | erpnext.startup.set_periodic_updates(); |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 64 | |
| 65 | // border to the body |
| 66 | // ------------------ |
Anand Doshi | 01a7558 | 2012-02-24 19:35:09 +0530 | [diff] [blame] | 67 | $('footer').html('<div class="web-footer erpnext-footer">\ |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 68 | Powered by <a href="https://erpnext.com">ERPNext</a></div>'); |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 69 | } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 70 | |
Rushabh Mehta | 9c7a01a | 2012-01-25 11:04:54 +0530 | [diff] [blame] | 71 | $('#startup_div').toggle(false); |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 72 | } |
| 73 | |
Brahma K | d1a2cea | 2011-08-30 09:33:29 +0530 | [diff] [blame] | 74 | // chart of accounts |
| 75 | // ==================================================================== |
| 76 | show_chart_browser = function(nm, chart_type){ |
| 77 | |
| 78 | var call_back = function(){ |
| 79 | if(nm == 'Sales Browser'){ |
| 80 | var sb_obj = new SalesBrowser(); |
| 81 | sb_obj.set_val(chart_type); |
| 82 | } |
| 83 | else if(nm == 'Accounts Browser') |
| 84 | pscript.make_chart(chart_type); |
| 85 | } |
| 86 | loadpage(nm,call_back); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | // Module Page |
| 91 | // ==================================================================== |
| 92 | |
| 93 | ModulePage = function(parent, module_name, module_label, help_page, callback) { |
| 94 | this.parent = parent; |
| 95 | |
| 96 | // add to current page |
| 97 | page_body.cur_page.module_page = this; |
| 98 | |
| 99 | this.wrapper = $a(parent,'div'); |
| 100 | this.module_name = module_name; |
| 101 | this.transactions = []; |
| 102 | this.page_head = new PageHeader(this.wrapper, module_label); |
| 103 | |
| 104 | if(help_page) { |
| 105 | var btn = this.page_head.add_button('Help', function() { loadpage(this.help_page) }, 1, 'ui-icon-help') |
| 106 | btn.help_page = help_page; |
| 107 | } |
| 108 | |
| 109 | if(callback) this.callback = function(){ callback(); } |
| 110 | } |
| 111 | |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 112 | // ========== Update Messages ============ |
| 113 | var update_messages = function() { |
| 114 | // Updates Team Messages |
| 115 | |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 116 | if(inList(['Guest'], user)) { return; } |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 117 | |
| 118 | $c_page('home', 'event_updates', 'get_unread_messages', null, |
| 119 | function(r,rt) { |
| 120 | if(!r.exc) { |
| 121 | // This function is defined in toolbar.js |
| 122 | page_body.wntoolbar.set_new_comments(r.message); |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 123 | var circle = $('#msg_count') |
| 124 | if(circle) { |
| 125 | if(r.message.length) { |
| 126 | circle.find('span:first').text(r.message.length); |
| 127 | circle.toggle(true); |
| 128 | } else { |
| 129 | circle.toggle(false); |
| 130 | } |
| 131 | } |
Anand Doshi | 2b8c4d7 | 2012-02-27 18:42:00 +0530 | [diff] [blame] | 132 | } else { |
| 133 | clearInterval(wn.updates.id); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | ); |
| 137 | } |
| 138 | |
| 139 | erpnext.startup.set_periodic_updates = function() { |
| 140 | // Set interval for periodic updates of team messages |
| 141 | wn.updates = {}; |
| 142 | |
| 143 | if(wn.updates.id) { |
| 144 | clearInterval(wn.updates.id); |
| 145 | } |
| 146 | |
Anand Doshi | db62876 | 2012-02-24 17:56:00 +0530 | [diff] [blame] | 147 | wn.updates.id = setInterval(update_messages, 60000); |
Anand Doshi | c3023be | 2012-02-20 16:31:55 +0530 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // ======================================= |
| 151 | |
Rushabh Mehta | 865c00a | 2012-01-24 14:33:21 +0530 | [diff] [blame] | 152 | // start |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 153 | $(document).bind('startup', function() { |
Rushabh Mehta | d025133 | 2012-02-21 17:26:50 +0530 | [diff] [blame] | 154 | erpnext.startup.start(); |
Rushabh Mehta | afaac60 | 2012-02-14 11:44:13 +0530 | [diff] [blame] | 155 | }); |