blob: 02a00322d5881c8811cfbaae2cce99e043db5b0b [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
Anand Doshib8660fb2012-04-20 11:21:47 +053041// wn.modules is used in breadcrumbs for getting module home page
42wn.provide('wn.modules');
43$.extend(wn.modules, erpnext.modules);
44wn.modules['Core'] = 'Setup';
45
Rushabh Mehta865c00a2012-01-24 14:33:21 +053046erpnext.startup.set_globals = function() {
Rushabh Mehta865c00a2012-01-24 14:33:21 +053047 if(inList(user_roles,'System Manager')) is_system_manager = 1;
48}
Rushabh Mehta8c309be2012-01-20 13:47:16 +053049
Rushabh Mehta865c00a2012-01-24 14:33:21 +053050erpnext.startup.start = function() {
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053051 $('#startup_div').html('Starting up...').toggle(true);
52
Rushabh Mehta70f76742012-03-01 18:42:05 +053053
Rushabh Mehta865c00a2012-01-24 14:33:21 +053054 erpnext.startup.set_globals();
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053055
Rushabh Mehta412a65c2012-02-29 18:38:18 +053056 if(wn.boot.user_background) {
57 erpnext.set_user_background(wn.boot.user_background);
58 }
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053059
Rushabh Mehta865c00a2012-01-24 14:33:21 +053060 if(user == 'Guest'){
Rushabh Mehta983a1712012-03-21 13:35:34 +053061 if(wn.boot.custom_css) {
62 set_style(wn.boot.custom_css);
63 }
Rushabh Mehta7018b192012-02-02 13:42:28 +053064 if(wn.boot.website_settings.title_prefix) {
65 wn.title_prefix = wn.boot.website_settings.title_prefix;
66 }
Rushabh Mehta389880d2012-04-27 18:39:14 +053067 if(wn.boot.startup_code) {
68 eval(wn.boot.startup_code);
69 }
Rushabh Mehta865c00a2012-01-24 14:33:21 +053070 } else {
Rushabh Mehta428929b2012-03-01 11:24:45 +053071 // always allow apps
72 wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat(
Rushabh Mehtacc131af2012-03-01 13:35:07 +053073 ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages'])
Anand Doshi2d4139c2012-03-23 14:46:07 +053074 // allow dashboard to accounts manager
75 if(user_roles.indexOf('Accounts Manager')!=-1) {
76 wn.boot.profile.allow_modules.push('Dashboard');
77 }
Rushabh Mehta428929b2012-03-01 11:24:45 +053078
Rushabh Mehta865c00a2012-01-24 14:33:21 +053079 // setup toolbar
Rushabh Mehta865c00a2012-01-24 14:33:21 +053080 erpnext.toolbar.setup();
Rushabh Mehta12852e72012-02-29 15:11:06 +053081
Anand Doshic3023be2012-02-20 16:31:55 +053082 // set interval for updates
83 erpnext.startup.set_periodic_updates();
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053084
85 // border to the body
86 // ------------------
Rushabh Mehtad48417c2012-03-19 18:42:13 +053087 //$('footer').html('<div class="web-footer erpnext-footer">\
88 // <a href="#!attributions">ERPNext | Attributions and License</a></div>');
Rushabh Mehta12852e72012-02-29 15:11:06 +053089
90 // complete registration
91 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
92 wn.require("erpnext/startup/js/complete_setup.js");
93 erpnext.complete_setup();
94 }
95
Brahma Kd1a2cea2011-08-30 09:33:29 +053096 }
Anand Doshic3023be2012-02-20 16:31:55 +053097
Anand Doshic9d1ac42012-04-17 13:54:53 +053098 erpnext.set_about();
99
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +0530100 $('#startup_div').toggle(false);
Brahma Kd1a2cea2011-08-30 09:33:29 +0530101}
102
Brahma Kd1a2cea2011-08-30 09:33:29 +0530103// chart of accounts
104// ====================================================================
105show_chart_browser = function(nm, chart_type){
106
107 var call_back = function(){
108 if(nm == 'Sales Browser'){
109 var sb_obj = new SalesBrowser();
110 sb_obj.set_val(chart_type);
111 }
112 else if(nm == 'Accounts Browser')
113 pscript.make_chart(chart_type);
114 }
115 loadpage(nm,call_back);
116}
117
118
Anand Doshic3023be2012-02-20 16:31:55 +0530119// ========== Update Messages ============
Anand Doshi08c8edb2012-03-01 14:53:05 +0530120var update_messages = function(reset) {
Anand Doshic3023be2012-02-20 16:31:55 +0530121 // Updates Team Messages
122
Anand Doshia7158f62012-03-19 14:41:05 +0530123 if(inList(['Guest'], user) || !wn.session_alive) { return; }
Anand Doshi08c8edb2012-03-01 14:53:05 +0530124
125 if(!reset) {
Anand Doshi82042f12012-04-06 17:54:17 +0530126 var set_messages = function(r) {
127 if(!r.exc) {
128 // This function is defined in toolbar.js
129 wn.container.wntoolbar.set_new_comments(r.message.unread_messages);
130
131 var show_in_circle = function(parent_id, msg) {
132 var parent = $('#'+parent_id);
133 if(parent) {
134 if(msg) {
135 parent.find('span:first').text(msg);
136 parent.toggle(true);
137 } else {
138 parent.toggle(false);
Anand Doshi08c8edb2012-03-01 14:53:05 +0530139 }
Anand Doshidb628762012-02-24 17:56:00 +0530140 }
141 }
Anand Doshi82042f12012-04-06 17:54:17 +0530142
143 show_in_circle('unread_messages', r.message.unread_messages.length);
144 show_in_circle('open_support_tickets', r.message.open_support_tickets);
145 show_in_circle('things_todo', r.message.things_todo);
146 show_in_circle('todays_events', r.message.todays_events);
147
148 } else {
149 clearInterval(wn.updates.id);
Anand Doshic3023be2012-02-20 16:31:55 +0530150 }
Anand Doshi82042f12012-04-06 17:54:17 +0530151 }
152
153 wn.call({
154 method: 'startup.startup.get_global_status_messages',
155 callback: set_messages
156 });
157
Anand Doshi08c8edb2012-03-01 14:53:05 +0530158 } else {
Rushabh Mehta7afaa862012-03-16 18:28:09 +0530159 wn.container.wntoolbar.set_new_comments(0);
Anand Doshi7854f812012-03-14 12:01:13 +0530160 $('#unread_messages').toggle(false);
Anand Doshi08c8edb2012-03-01 14:53:05 +0530161 }
Anand Doshic3023be2012-02-20 16:31:55 +0530162}
163
164erpnext.startup.set_periodic_updates = function() {
165 // Set interval for periodic updates of team messages
166 wn.updates = {};
167
168 if(wn.updates.id) {
169 clearInterval(wn.updates.id);
170 }
171
Anand Doshidb628762012-02-24 17:56:00 +0530172 wn.updates.id = setInterval(update_messages, 60000);
Anand Doshic3023be2012-02-20 16:31:55 +0530173}
174
Rushabh Mehta412a65c2012-02-29 18:38:18 +0530175erpnext.set_user_background = function(src) {
Rushabh Mehta702473d2012-04-26 19:01:35 +0530176 set_style(repl('#body_div { background: url("files/%(src)s") repeat;}', {src:src}))
Rushabh Mehta412a65c2012-02-29 18:38:18 +0530177}
178
Rushabh Mehta865c00a2012-01-24 14:33:21 +0530179// start
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530180$(document).bind('startup', function() {
Rushabh Mehtad0251332012-02-21 17:26:50 +0530181 erpnext.startup.start();
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530182});
Rushabh Mehta389880d2012-04-27 18:39:14 +0530183
184// subject, sender, description
185erpnext.send_message = function(opts) {
186 if(opts.btn) {
187 $(opts.btn).start_working();
188 }
189 wn.call({
190 method: 'website.send_message',
191 args: opts,
192 callback: function(r) {
193 if(opts.btn) {
194 $(opts.btn).done_working();
195 }
196 if(opts.callback)opts.callback(r)
197 }
198 });
199}