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