blob: 925c85e6d5fd0a5ef2da07d7c2e6eccbe844573d [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 Mehta70f76742012-03-01 18:42:05 +053049
Rushabh Mehta865c00a2012-01-24 14:33:21 +053050 erpnext.startup.set_globals();
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053051
Rushabh Mehta412a65c2012-02-29 18:38:18 +053052 if(wn.boot.user_background) {
53 erpnext.set_user_background(wn.boot.user_background);
54 }
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053055
Rushabh Mehta865c00a2012-01-24 14:33:21 +053056 if(user == 'Guest'){
Rushabh Mehta983a1712012-03-21 13:35:34 +053057 if(wn.boot.custom_css) {
58 set_style(wn.boot.custom_css);
59 }
Rushabh Mehta7018b192012-02-02 13:42:28 +053060 if(wn.boot.website_settings.title_prefix) {
61 wn.title_prefix = wn.boot.website_settings.title_prefix;
62 }
Rushabh Mehta865c00a2012-01-24 14:33:21 +053063 } else {
Rushabh Mehta428929b2012-03-01 11:24:45 +053064 // always allow apps
65 wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat(
Rushabh Mehtacc131af2012-03-01 13:35:07 +053066 ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages'])
Rushabh Mehta428929b2012-03-01 11:24:45 +053067
Rushabh Mehta865c00a2012-01-24 14:33:21 +053068 // setup toolbar
Rushabh Mehta865c00a2012-01-24 14:33:21 +053069 erpnext.toolbar.setup();
Rushabh Mehta12852e72012-02-29 15:11:06 +053070
Anand Doshic3023be2012-02-20 16:31:55 +053071 // set interval for updates
72 erpnext.startup.set_periodic_updates();
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053073
74 // border to the body
75 // ------------------
Rushabh Mehtad48417c2012-03-19 18:42:13 +053076 //$('footer').html('<div class="web-footer erpnext-footer">\
77 // <a href="#!attributions">ERPNext | Attributions and License</a></div>');
Rushabh Mehta12852e72012-02-29 15:11:06 +053078
79 // complete registration
80 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
81 wn.require("erpnext/startup/js/complete_setup.js");
82 erpnext.complete_setup();
83 }
84
Brahma Kd1a2cea2011-08-30 09:33:29 +053085 }
Anand Doshic3023be2012-02-20 16:31:55 +053086
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053087 $('#startup_div').toggle(false);
Brahma Kd1a2cea2011-08-30 09:33:29 +053088}
89
Brahma Kd1a2cea2011-08-30 09:33:29 +053090// chart of accounts
91// ====================================================================
92show_chart_browser = function(nm, chart_type){
93
94 var call_back = function(){
95 if(nm == 'Sales Browser'){
96 var sb_obj = new SalesBrowser();
97 sb_obj.set_val(chart_type);
98 }
99 else if(nm == 'Accounts Browser')
100 pscript.make_chart(chart_type);
101 }
102 loadpage(nm,call_back);
103}
104
105
Anand Doshic3023be2012-02-20 16:31:55 +0530106// ========== Update Messages ============
Anand Doshi08c8edb2012-03-01 14:53:05 +0530107var update_messages = function(reset) {
Anand Doshic3023be2012-02-20 16:31:55 +0530108 // Updates Team Messages
109
Anand Doshia7158f62012-03-19 14:41:05 +0530110 if(inList(['Guest'], user) || !wn.session_alive) { return; }
Anand Doshi08c8edb2012-03-01 14:53:05 +0530111
112 if(!reset) {
Anand Doshi7854f812012-03-14 12:01:13 +0530113 $c_page('home', 'event_updates', 'get_global_status_messages', null,
Anand Doshi08c8edb2012-03-01 14:53:05 +0530114 function(r,rt) {
115 if(!r.exc) {
116 // This function is defined in toolbar.js
Rushabh Mehta7afaa862012-03-16 18:28:09 +0530117 wn.container.wntoolbar.set_new_comments(r.message.unread_messages);
Anand Doshi7854f812012-03-14 12:01:13 +0530118
119 var show_in_circle = function(parent_id, msg) {
120 var parent = $('#'+parent_id);
121 if(parent) {
122 if(msg) {
123 parent.find('span:first').text(msg);
124 parent.toggle(true);
125 } else {
126 parent.toggle(false);
127 }
Anand Doshi08c8edb2012-03-01 14:53:05 +0530128 }
Anand Doshidb628762012-02-24 17:56:00 +0530129 }
Anand Doshi7854f812012-03-14 12:01:13 +0530130
131 show_in_circle('unread_messages', r.message.unread_messages.length);
132 show_in_circle('open_support_tickets', r.message.open_support_tickets);
133 show_in_circle('things_todo', r.message.things_todo);
134 show_in_circle('todays_events', r.message.todays_events);
135
Anand Doshi08c8edb2012-03-01 14:53:05 +0530136 } else {
137 clearInterval(wn.updates.id);
Anand Doshidb628762012-02-24 17:56:00 +0530138 }
Anand Doshic3023be2012-02-20 16:31:55 +0530139 }
Anand Doshi08c8edb2012-03-01 14:53:05 +0530140 );
141 } else {
Rushabh Mehta7afaa862012-03-16 18:28:09 +0530142 wn.container.wntoolbar.set_new_comments(0);
Anand Doshi7854f812012-03-14 12:01:13 +0530143 $('#unread_messages').toggle(false);
Anand Doshi08c8edb2012-03-01 14:53:05 +0530144 }
Anand Doshic3023be2012-02-20 16:31:55 +0530145}
146
147erpnext.startup.set_periodic_updates = function() {
148 // Set interval for periodic updates of team messages
149 wn.updates = {};
150
151 if(wn.updates.id) {
152 clearInterval(wn.updates.id);
153 }
154
Anand Doshidb628762012-02-24 17:56:00 +0530155 wn.updates.id = setInterval(update_messages, 60000);
Anand Doshic3023be2012-02-20 16:31:55 +0530156}
157
Rushabh Mehta412a65c2012-02-29 18:38:18 +0530158erpnext.set_user_background = function(src) {
Rushabh Mehta37f531b2012-03-02 11:29:09 +0530159 set_style(repl('body { background: url("files/%(src)s") repeat;}', {src:src}))
Rushabh Mehta412a65c2012-02-29 18:38:18 +0530160}
161
Rushabh Mehta865c00a2012-01-24 14:33:21 +0530162// start
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530163$(document).bind('startup', function() {
Rushabh Mehtad0251332012-02-21 17:26:50 +0530164 erpnext.startup.start();
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530165});