blob: ed71aa19ba26cfbcb29955f0b1fb572811eb68bd [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301// 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 Kd1a2cea2011-08-30 09:33:29 +053017var current_module;
18var is_system_manager = 0;
19var module_content_dict = {};
20var user_full_nm = {};
21
Rushabh Mehta865c00a2012-01-24 14:33:21 +053022wn.provide('erpnext.startup');
Brahma Kd1a2cea2011-08-30 09:33:29 +053023
Rushabh Mehta865c00a2012-01-24 14:33:21 +053024erpnext.startup.set_globals = function() {
25 pscript.is_erpnext_saas = cint(wn.control_panel.sync_with_gateway)
26 if(inList(user_roles,'System Manager')) is_system_manager = 1;
27}
Rushabh Mehta8c309be2012-01-20 13:47:16 +053028
Rushabh Mehta865c00a2012-01-24 14:33:21 +053029erpnext.startup.start = function() {
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053030 $('#startup_div').html('Starting up...').toggle(true);
31
Rushabh Mehta865c00a2012-01-24 14:33:21 +053032 erpnext.startup.set_globals();
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053033
34 if(wn.boot.custom_css) {
35 set_style(wn.boot.custom_css);
36 }
37
Rushabh Mehta865c00a2012-01-24 14:33:21 +053038 if(user == 'Guest'){
Rushabh Mehta7018b192012-02-02 13:42:28 +053039 if(wn.boot.website_settings.title_prefix) {
40 wn.title_prefix = wn.boot.website_settings.title_prefix;
41 }
Rushabh Mehta865c00a2012-01-24 14:33:21 +053042 } else {
Rushabh Mehta865c00a2012-01-24 14:33:21 +053043 // setup toolbar
Rushabh Mehta865c00a2012-01-24 14:33:21 +053044 erpnext.toolbar.setup();
Anand Doshic3023be2012-02-20 16:31:55 +053045
46 // set interval for updates
47 erpnext.startup.set_periodic_updates();
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053048
49 // border to the body
50 // ------------------
51 $('footer').html('<div class="erpnext-footer">\
52 Powered by <a href="https://erpnext.com">ERPNext</a></div>');
Brahma Kd1a2cea2011-08-30 09:33:29 +053053 }
Anand Doshic3023be2012-02-20 16:31:55 +053054
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053055 $('#startup_div').toggle(false);
Brahma Kd1a2cea2011-08-30 09:33:29 +053056}
57
Brahma Kd1a2cea2011-08-30 09:33:29 +053058// chart of accounts
59// ====================================================================
60show_chart_browser = function(nm, chart_type){
61
62 var call_back = function(){
63 if(nm == 'Sales Browser'){
64 var sb_obj = new SalesBrowser();
65 sb_obj.set_val(chart_type);
66 }
67 else if(nm == 'Accounts Browser')
68 pscript.make_chart(chart_type);
69 }
70 loadpage(nm,call_back);
71}
72
73
74// Module Page
75// ====================================================================
76
77ModulePage = function(parent, module_name, module_label, help_page, callback) {
78 this.parent = parent;
79
80 // add to current page
81 page_body.cur_page.module_page = this;
82
83 this.wrapper = $a(parent,'div');
84 this.module_name = module_name;
85 this.transactions = [];
86 this.page_head = new PageHeader(this.wrapper, module_label);
87
88 if(help_page) {
89 var btn = this.page_head.add_button('Help', function() { loadpage(this.help_page) }, 1, 'ui-icon-help')
90 btn.help_page = help_page;
91 }
92
93 if(callback) this.callback = function(){ callback(); }
94}
95
Anand Doshic3023be2012-02-20 16:31:55 +053096// ========== Update Messages ============
97var update_messages = function() {
98 // Updates Team Messages
99
Anand Doshidb628762012-02-24 17:56:00 +0530100 if(inList(['Guest'], user)) { return; }
Anand Doshic3023be2012-02-20 16:31:55 +0530101
102 $c_page('home', 'event_updates', 'get_unread_messages', null,
103 function(r,rt) {
104 if(!r.exc) {
105 // This function is defined in toolbar.js
106 page_body.wntoolbar.set_new_comments(r.message);
Anand Doshidb628762012-02-24 17:56:00 +0530107 var circle = $('#msg_count')
108 if(circle) {
109 if(r.message.length) {
110 circle.find('span:first').text(r.message.length);
111 circle.toggle(true);
112 } else {
113 circle.toggle(false);
114 }
115 }
Anand Doshic3023be2012-02-20 16:31:55 +0530116 }
117 }
118 );
119}
120
121erpnext.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 Doshidb628762012-02-24 17:56:00 +0530129 wn.updates.id = setInterval(update_messages, 60000);
Anand Doshic3023be2012-02-20 16:31:55 +0530130}
131
132// =======================================
133
Rushabh Mehta865c00a2012-01-24 14:33:21 +0530134// start
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530135$(document).bind('startup', function() {
Rushabh Mehtad0251332012-02-21 17:26:50 +0530136 erpnext.startup.start();
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530137});