blob: 759454052612a756c5fae96ab04815c2415cf1b6 [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() {
Anand Doshi1ed4ef12012-04-27 15:30:23 +053051 console.log('Starting up...');
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053052 $('#startup_div').html('Starting up...').toggle(true);
53
Rushabh Mehta70f76742012-03-01 18:42:05 +053054
Rushabh Mehta865c00a2012-01-24 14:33:21 +053055 erpnext.startup.set_globals();
Rushabh Mehtac5471dd2012-02-22 12:07:42 +053056
Rushabh Mehtaa9209432012-05-07 18:00:57 +053057 if(user != 'Guest'){
58 if(wn.boot.user_background) {
59 erpnext.set_user_background(wn.boot.user_background);
Rushabh Mehta983a1712012-03-21 13:35:34 +053060 }
Rushabh Mehtaa9209432012-05-07 18:00:57 +053061
Rushabh Mehta428929b2012-03-01 11:24:45 +053062 // always allow apps
63 wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat(
Rushabh Mehtacc131af2012-03-01 13:35:07 +053064 ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages'])
Rushabh Mehta428929b2012-03-01 11:24:45 +053065
Rushabh Mehta865c00a2012-01-24 14:33:21 +053066 // setup toolbar
Rushabh Mehta865c00a2012-01-24 14:33:21 +053067 erpnext.toolbar.setup();
Anand Doshi2aa9ba62012-04-30 15:43:34 +053068
Anand Doshic3023be2012-02-20 16:31:55 +053069 // set interval for updates
70 erpnext.startup.set_periodic_updates();
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053071
72 // border to the body
73 // ------------------
Rushabh Mehtaef048f72012-05-01 14:56:20 +053074 $('footer').html('<div class="web-footer erpnext-footer">\
75 <a href="#!attributions">ERPNext | Attributions and License</a></div>');
Rushabh Mehta12852e72012-02-29 15:11:06 +053076
77 // complete registration
78 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
Anand Doshi951d8ec2012-05-10 14:19:11 +053079 wn.require("js/complete_setup.js");
Anand Doshi1ed4ef12012-04-27 15:30:23 +053080 erpnext.complete_setup.show();
Rushabh Mehta12852e72012-02-29 15:11:06 +053081 }
Anand Doshi8cffe7e2012-04-30 12:13:51 +053082 if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) {
Anand Doshi1ed4ef12012-04-27 15:30:23 +053083 var today = dateutil.str_to_obj(dateutil.get_today());
84 var expires_on = dateutil.str_to_obj(wn.boot.expires_on);
85 var diff = dateutil.get_diff(expires_on, today);
86 if (0 <= diff && diff <= 15) {
87 var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff });
88 $('header').append(repl('<div class="expiry-info"> \
Anand Doshi84777ac2012-04-30 18:33:32 +053089 Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \
Anand Doshi1ed4ef12012-04-27 15:30:23 +053090 Please renew your subscription to continue using ERPNext \
91 (and remove this annoying banner). \
92 </div>', { expiry_string: expiry_string }));
93 } else if (diff < 0) {
94 $('header').append(repl('<div class="expiry-info"> \
Anand Doshi563fcc12012-04-30 21:06:31 +053095 This ERPNext subscription <b>has expired</b>. \
Anand Doshi1ed4ef12012-04-27 15:30:23 +053096 </div>', { expiry_string: expiry_string }));
97 }
98 }
Rushabh Mehtaa9209432012-05-07 18:00:57 +053099 erpnext.set_about();
100 if(wn.control_panel.custom_startup_code)
101 eval(wn.control_panel.custom_startup_code);
Brahma Kd1a2cea2011-08-30 09:33:29 +0530102 }
Brahma Kd1a2cea2011-08-30 09:33:29 +0530103}
104
105
Anand Doshic3023be2012-02-20 16:31:55 +0530106// ========== Update Messages ============
Rushabh Mehtad5e10312012-05-02 17:44:59 +0530107erpnext.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 Doshi82042f12012-04-06 17:54:17 +0530113 var set_messages = function(r) {
114 if(!r.exc) {
115 // This function is defined in toolbar.js
Anand Doshi2aa9ba62012-04-30 15:43:34 +0530116 erpnext.toolbar.set_new_comments(r.message.unread_messages);
Anand Doshi82042f12012-04-06 17:54:17 +0530117
118 var show_in_circle = function(parent_id, msg) {
119 var parent = $('#'+parent_id);
120 if(parent) {
121 if(msg) {
122 parent.find('span:first').text(msg);
123 parent.toggle(true);
124 } else {
125 parent.toggle(false);
Anand Doshi08c8edb2012-03-01 14:53:05 +0530126 }
Anand Doshidb628762012-02-24 17:56:00 +0530127 }
128 }
Anand Doshi82042f12012-04-06 17:54:17 +0530129
130 show_in_circle('unread_messages', r.message.unread_messages.length);
131 show_in_circle('open_support_tickets', r.message.open_support_tickets);
132 show_in_circle('things_todo', r.message.things_todo);
133 show_in_circle('todays_events', r.message.todays_events);
Rushabh Mehta07c94ce2012-06-04 12:57:23 +0530134 show_in_circle('open_tasks', r.message.open_tasks);
Anand Doshi82042f12012-04-06 17:54:17 +0530135
136 } else {
137 clearInterval(wn.updates.id);
Anand Doshic3023be2012-02-20 16:31:55 +0530138 }
Anand Doshi82042f12012-04-06 17:54:17 +0530139 }
140
141 wn.call({
142 method: 'startup.startup.get_global_status_messages',
143 callback: set_messages
144 });
145
Anand Doshi08c8edb2012-03-01 14:53:05 +0530146 } else {
Anand Doshi2aa9ba62012-04-30 15:43:34 +0530147 erpnext.toolbar.set_new_comments(0);
Anand Doshi7854f812012-03-14 12:01:13 +0530148 $('#unread_messages').toggle(false);
Anand Doshi08c8edb2012-03-01 14:53:05 +0530149 }
Anand Doshic3023be2012-02-20 16:31:55 +0530150}
151
152erpnext.startup.set_periodic_updates = function() {
153 // Set interval for periodic updates of team messages
154 wn.updates = {};
155
156 if(wn.updates.id) {
157 clearInterval(wn.updates.id);
158 }
159
Rushabh Mehtad5e10312012-05-02 17:44:59 +0530160 wn.updates.id = setInterval(erpnext.update_messages, 60000);
Anand Doshic3023be2012-02-20 16:31:55 +0530161}
162
Rushabh Mehta412a65c2012-02-29 18:38:18 +0530163erpnext.set_user_background = function(src) {
Rushabh Mehta702473d2012-04-26 19:01:35 +0530164 set_style(repl('#body_div { background: url("files/%(src)s") repeat;}', {src:src}))
Rushabh Mehta412a65c2012-02-29 18:38:18 +0530165}
166
Rushabh Mehta865c00a2012-01-24 14:33:21 +0530167// start
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530168$(document).bind('startup', function() {
Rushabh Mehtad0251332012-02-21 17:26:50 +0530169 erpnext.startup.start();
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530170});
Rushabh Mehta389880d2012-04-27 18:39:14 +0530171
172// subject, sender, description
173erpnext.send_message = function(opts) {
174 if(opts.btn) {
175 $(opts.btn).start_working();
176 }
177 wn.call({
178 method: 'website.send_message',
179 args: opts,
180 callback: function(r) {
181 if(opts.btn) {
182 $(opts.btn).done_working();
183 }
184 if(opts.callback)opts.callback(r)
185 }
186 });
187}
Rushabh Mehta30e3f152012-05-01 14:07:41 +0530188
189erpnext.hide_naming_series = function() {
190 if(cur_frm.fields_dict.naming_series) {
191 hide_field('naming_series');
192 if(cur_frm.doc.__islocal) {
193 unhide_field('naming_series');
194 }
195 }
196}