blob: aef298cbd2bbf432e35680b66e1cf9c73eacc097 [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 Mehtaa38bbe22012-02-29 10:55:43 +053022erpnext.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 Mehta12852e72012-02-29 15:11:06 +053033 'Activity': 'activity',
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053034 'To Do': 'todo',
35 'Calendar': 'calendar',
36 'Messages': 'messages',
37 'Knowledge Base': 'questions'
38}
39
Rushabh Mehta865c00a2012-01-24 14:33:21 +053040erpnext.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 Mehta8c309be2012-01-20 13:47:16 +053044
Rushabh Mehta865c00a2012-01-24 14:33:21 +053045erpnext.startup.start = function() {
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053046 $('#startup_div').html('Starting up...').toggle(true);
47
Rushabh Mehta865c00a2012-01-24 14:33:21 +053048 erpnext.startup.set_globals();
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053049
50 if(wn.boot.custom_css) {
51 set_style(wn.boot.custom_css);
52 }
53
Rushabh Mehta865c00a2012-01-24 14:33:21 +053054 if(user == 'Guest'){
Rushabh Mehta7018b192012-02-02 13:42:28 +053055 if(wn.boot.website_settings.title_prefix) {
56 wn.title_prefix = wn.boot.website_settings.title_prefix;
57 }
Rushabh Mehta865c00a2012-01-24 14:33:21 +053058 } else {
Rushabh Mehta865c00a2012-01-24 14:33:21 +053059 // setup toolbar
Rushabh Mehta865c00a2012-01-24 14:33:21 +053060 erpnext.toolbar.setup();
Rushabh Mehta12852e72012-02-29 15:11:06 +053061
Anand Doshic3023be2012-02-20 16:31:55 +053062 // set interval for updates
63 erpnext.startup.set_periodic_updates();
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053064
65 // border to the body
66 // ------------------
Anand Doshi01a75582012-02-24 19:35:09 +053067 $('footer').html('<div class="web-footer erpnext-footer">\
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053068 Powered by <a href="https://erpnext.com">ERPNext</a></div>');
Rushabh Mehta12852e72012-02-29 15:11:06 +053069
70 // complete registration
71 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
72 wn.require("erpnext/startup/js/complete_setup.js");
73 erpnext.complete_setup();
74 }
75
Brahma Kd1a2cea2011-08-30 09:33:29 +053076 }
Anand Doshic3023be2012-02-20 16:31:55 +053077
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053078 $('#startup_div').toggle(false);
Brahma Kd1a2cea2011-08-30 09:33:29 +053079}
80
Brahma Kd1a2cea2011-08-30 09:33:29 +053081// chart of accounts
82// ====================================================================
83show_chart_browser = function(nm, chart_type){
84
85 var call_back = function(){
86 if(nm == 'Sales Browser'){
87 var sb_obj = new SalesBrowser();
88 sb_obj.set_val(chart_type);
89 }
90 else if(nm == 'Accounts Browser')
91 pscript.make_chart(chart_type);
92 }
93 loadpage(nm,call_back);
94}
95
96
Anand Doshic3023be2012-02-20 16:31:55 +053097// ========== Update Messages ============
98var update_messages = function() {
99 // Updates Team Messages
100
Anand Doshidb628762012-02-24 17:56:00 +0530101 if(inList(['Guest'], user)) { return; }
Anand Doshic3023be2012-02-20 16:31:55 +0530102
103 $c_page('home', 'event_updates', 'get_unread_messages', null,
104 function(r,rt) {
105 if(!r.exc) {
106 // This function is defined in toolbar.js
107 page_body.wntoolbar.set_new_comments(r.message);
Anand Doshidb628762012-02-24 17:56:00 +0530108 var circle = $('#msg_count')
109 if(circle) {
110 if(r.message.length) {
111 circle.find('span:first').text(r.message.length);
112 circle.toggle(true);
113 } else {
114 circle.toggle(false);
115 }
116 }
Anand Doshi2b8c4d72012-02-27 18:42:00 +0530117 } else {
118 clearInterval(wn.updates.id);
Anand Doshic3023be2012-02-20 16:31:55 +0530119 }
120 }
121 );
122}
123
124erpnext.startup.set_periodic_updates = function() {
125 // Set interval for periodic updates of team messages
126 wn.updates = {};
127
128 if(wn.updates.id) {
129 clearInterval(wn.updates.id);
130 }
131
Anand Doshidb628762012-02-24 17:56:00 +0530132 wn.updates.id = setInterval(update_messages, 60000);
Anand Doshic3023be2012-02-20 16:31:55 +0530133}
134
135// =======================================
136
Rushabh Mehta865c00a2012-01-24 14:33:21 +0530137// start
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530138$(document).bind('startup', function() {
Rushabh Mehtad0251332012-02-21 17:26:50 +0530139 erpnext.startup.start();
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530140});