blob: 6448574917c36339203861db0bc77e415de3860b [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',
Rushabh Mehta428929b2012-03-01 11:24:45 +053037 'Knowledge Base': 'questions',
38 'Dashboard': 'dashboard'
Rushabh Mehtaa38bbe22012-02-29 10:55:43 +053039}
40
Rushabh Mehta865c00a2012-01-24 14:33:21 +053041erpnext.startup.set_globals = function() {
42 pscript.is_erpnext_saas = cint(wn.control_panel.sync_with_gateway)
43 if(inList(user_roles,'System Manager')) is_system_manager = 1;
44}
Rushabh Mehta8c309be2012-01-20 13:47:16 +053045
Rushabh Mehta865c00a2012-01-24 14:33:21 +053046erpnext.startup.start = function() {
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053047 $('#startup_div').html('Starting up...').toggle(true);
48
Rushabh Mehta865c00a2012-01-24 14:33:21 +053049 erpnext.startup.set_globals();
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053050
51 if(wn.boot.custom_css) {
52 set_style(wn.boot.custom_css);
53 }
Rushabh Mehta412a65c2012-02-29 18:38:18 +053054 if(wn.boot.user_background) {
55 erpnext.set_user_background(wn.boot.user_background);
56 }
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053057
Rushabh Mehta865c00a2012-01-24 14:33:21 +053058 if(user == 'Guest'){
Rushabh Mehta7018b192012-02-02 13:42:28 +053059 if(wn.boot.website_settings.title_prefix) {
60 wn.title_prefix = wn.boot.website_settings.title_prefix;
61 }
Rushabh Mehta865c00a2012-01-24 14:33:21 +053062 } else {
Rushabh Mehta428929b2012-03-01 11:24:45 +053063 // always allow apps
64 wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat(
Rushabh Mehtacc131af2012-03-01 13:35:07 +053065 ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages'])
Rushabh Mehta428929b2012-03-01 11:24:45 +053066
Rushabh Mehta865c00a2012-01-24 14:33:21 +053067 // setup toolbar
Rushabh Mehta865c00a2012-01-24 14:33:21 +053068 erpnext.toolbar.setup();
Rushabh Mehta12852e72012-02-29 15:11:06 +053069
Anand Doshic3023be2012-02-20 16:31:55 +053070 // set interval for updates
71 erpnext.startup.set_periodic_updates();
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053072
73 // border to the body
74 // ------------------
Anand Doshi01a75582012-02-24 19:35:09 +053075 $('footer').html('<div class="web-footer erpnext-footer">\
Rushabh Mehta4c1e9e72012-03-01 13:30:34 +053076 <a href="#!attributions">ERPNext | Attributions and License</a></div>');
Rushabh Mehta12852e72012-02-29 15:11:06 +053077
78 // complete registration
79 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
80 wn.require("erpnext/startup/js/complete_setup.js");
81 erpnext.complete_setup();
82 }
83
Brahma Kd1a2cea2011-08-30 09:33:29 +053084 }
Anand Doshic3023be2012-02-20 16:31:55 +053085
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053086 $('#startup_div').toggle(false);
Brahma Kd1a2cea2011-08-30 09:33:29 +053087}
88
Brahma Kd1a2cea2011-08-30 09:33:29 +053089// chart of accounts
90// ====================================================================
91show_chart_browser = function(nm, chart_type){
92
93 var call_back = function(){
94 if(nm == 'Sales Browser'){
95 var sb_obj = new SalesBrowser();
96 sb_obj.set_val(chart_type);
97 }
98 else if(nm == 'Accounts Browser')
99 pscript.make_chart(chart_type);
100 }
101 loadpage(nm,call_back);
102}
103
104
Anand Doshic3023be2012-02-20 16:31:55 +0530105// ========== Update Messages ============
Anand Doshi08c8edb2012-03-01 14:53:05 +0530106var update_messages = function(reset) {
Anand Doshic3023be2012-02-20 16:31:55 +0530107 // Updates Team Messages
108
Anand Doshidb628762012-02-24 17:56:00 +0530109 if(inList(['Guest'], user)) { return; }
Anand Doshi08c8edb2012-03-01 14:53:05 +0530110
111 if(!reset) {
112 $c_page('home', 'event_updates', 'get_unread_messages', null,
113 function(r,rt) {
114 if(!r.exc) {
115 // This function is defined in toolbar.js
116 page_body.wntoolbar.set_new_comments(r.message);
117 var circle = $('#msg_count')
118 if(circle) {
119 if(r.message.length) {
120 circle.find('span:first').text(r.message.length);
121 circle.toggle(true);
122 } else {
123 circle.toggle(false);
124 }
Anand Doshidb628762012-02-24 17:56:00 +0530125 }
Anand Doshi08c8edb2012-03-01 14:53:05 +0530126 } else {
127 clearInterval(wn.updates.id);
Anand Doshidb628762012-02-24 17:56:00 +0530128 }
Anand Doshic3023be2012-02-20 16:31:55 +0530129 }
Anand Doshi08c8edb2012-03-01 14:53:05 +0530130 );
131 } else {
132 page_body.wntoolbar.set_new_comments(0);
133 $('#msg_count').toggle(false);
134 }
Anand Doshic3023be2012-02-20 16:31:55 +0530135}
136
137erpnext.startup.set_periodic_updates = function() {
138 // Set interval for periodic updates of team messages
139 wn.updates = {};
140
141 if(wn.updates.id) {
142 clearInterval(wn.updates.id);
143 }
144
Anand Doshidb628762012-02-24 17:56:00 +0530145 wn.updates.id = setInterval(update_messages, 60000);
Anand Doshic3023be2012-02-20 16:31:55 +0530146}
147
Rushabh Mehta412a65c2012-02-29 18:38:18 +0530148erpnext.set_user_background = function(src) {
149 set_style(repl('body { background: url("files/%(src)s") repeat !important;}', {src:src}))
150}
151
Anand Doshic3023be2012-02-20 16:31:55 +0530152// =======================================
153
Rushabh Mehta865c00a2012-01-24 14:33:21 +0530154// start
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530155$(document).bind('startup', function() {
Rushabh Mehtad0251332012-02-21 17:26:50 +0530156 erpnext.startup.start();
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530157});