blob: 0f584b3064ac59a9bf3d62b1e66620f315dbe88a [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;
Brahma Kd1a2cea2011-08-30 09:33:29 +053019
Rushabh Mehta865c00a2012-01-24 14:33:21 +053020wn.provide('erpnext.startup');
Brahma Kd1a2cea2011-08-30 09:33:29 +053021
Rushabh Mehta865c00a2012-01-24 14:33:21 +053022erpnext.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 Mehta8c309be2012-01-20 13:47:16 +053026
Rushabh Mehta865c00a2012-01-24 14:33:21 +053027erpnext.startup.start = function() {
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053028 $('#startup_div').html('Starting up...').toggle(true);
29
Rushabh Mehta865c00a2012-01-24 14:33:21 +053030 erpnext.startup.set_globals();
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053031
32 if(wn.boot.custom_css) {
33 set_style(wn.boot.custom_css);
34 }
35
Rushabh Mehta865c00a2012-01-24 14:33:21 +053036 if(user == 'Guest'){
Rushabh Mehta7018b192012-02-02 13:42:28 +053037 if(wn.boot.website_settings.title_prefix) {
38 wn.title_prefix = wn.boot.website_settings.title_prefix;
39 }
Rushabh Mehta865c00a2012-01-24 14:33:21 +053040 } else {
Rushabh Mehta865c00a2012-01-24 14:33:21 +053041 // setup toolbar
Rushabh Mehta865c00a2012-01-24 14:33:21 +053042 erpnext.toolbar.setup();
Anand Doshic3023be2012-02-20 16:31:55 +053043
44 // set interval for updates
45 erpnext.startup.set_periodic_updates();
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053046
47 // border to the body
48 // ------------------
Anand Doshi01a75582012-02-24 19:35:09 +053049 $('footer').html('<div class="web-footer erpnext-footer">\
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053050 Powered by <a href="https://erpnext.com">ERPNext</a></div>');
Brahma Kd1a2cea2011-08-30 09:33:29 +053051 }
Anand Doshic3023be2012-02-20 16:31:55 +053052
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053053 $('#startup_div').toggle(false);
Brahma Kd1a2cea2011-08-30 09:33:29 +053054}
55
Brahma Kd1a2cea2011-08-30 09:33:29 +053056// chart of accounts
57// ====================================================================
58show_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
75ModulePage = 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 Doshic3023be2012-02-20 16:31:55 +053094// ========== Update Messages ============
95var update_messages = function() {
96 // Updates Team Messages
97
Anand Doshidb628762012-02-24 17:56:00 +053098 if(inList(['Guest'], user)) { return; }
Anand Doshic3023be2012-02-20 16:31:55 +053099
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 Doshidb628762012-02-24 17:56:00 +0530105 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 Doshic3023be2012-02-20 16:31:55 +0530114 }
115 }
116 );
117}
118
119erpnext.startup.set_periodic_updates = function() {
120 // Set interval for periodic updates of team messages
121 wn.updates = {};
122
123 if(wn.updates.id) {
124 clearInterval(wn.updates.id);
125 }
126
Anand Doshidb628762012-02-24 17:56:00 +0530127 wn.updates.id = setInterval(update_messages, 60000);
Anand Doshic3023be2012-02-20 16:31:55 +0530128}
129
130// =======================================
131
Rushabh Mehta865c00a2012-01-24 14:33:21 +0530132// start
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530133$(document).bind('startup', function() {
Rushabh Mehtad0251332012-02-21 17:26:50 +0530134 erpnext.startup.start();
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530135});