blob: a934063fb304a5ae1e21a1d0ca5926e9a588e746 [file] [log] [blame]
Rushabh Mehta2fa2f712012-09-24 19:13:42 +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
17var current_module;
18var is_system_manager = 0;
19
20wn.provide('erpnext.startup');
21
22erpnext.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',
33 'Activity': 'activity',
34 'To Do': 'todo',
35 'Calendar': 'calendar',
36 'Messages': 'messages',
37 'Knowledge Base': 'questions',
38 'Dashboard': 'dashboard'
39}
40
41// 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
46erpnext.startup.set_globals = function() {
47 if(inList(user_roles,'System Manager')) is_system_manager = 1;
48}
49
50erpnext.startup.start = function() {
51 console.log('Starting up...');
52 $('#startup_div').html('Starting up...').toggle(true);
53
54
55 erpnext.startup.set_globals();
56
57 if(user != 'Guest'){
58 if(wn.boot.user_background) {
59 erpnext.set_user_background(wn.boot.user_background);
60 }
Rushabh Mehtab0d32b72012-09-28 16:11:57 +053061 if(wn.boot.profile.defaults.theme) {
Rushabh Mehta3c041932012-09-28 18:47:47 +053062 erpnext.set_theme(wn.boot.profile.defaults.theme[0]);
Rushabh Mehtab0d32b72012-09-28 16:11:57 +053063 }
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053064
65 // always allow apps
66 wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat(
67 ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages'])
68
69 // setup toolbar
70 erpnext.toolbar.setup();
71
72 // set interval for updates
73 erpnext.startup.set_periodic_updates();
74
75 // border to the body
76 // ------------------
77 $('footer').html('<div class="web-footer erpnext-footer">\
78 <a href="#!attributions">ERPNext | Attributions and License</a></div>');
79
80 // complete registration
81 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
82 wn.require("app/js/complete_setup.js");
83 erpnext.complete_setup.show();
84 }
85 if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) {
86 var today = dateutil.str_to_obj(dateutil.get_today());
87 var expires_on = dateutil.str_to_obj(wn.boot.expires_on);
88 var diff = dateutil.get_diff(expires_on, today);
89 if (0 <= diff && diff <= 15) {
90 var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff });
91 $('header').append(repl('<div class="expiry-info"> \
92 Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \
93 Please renew your subscription to continue using ERPNext \
94 (and remove this annoying banner). \
95 </div>', { expiry_string: expiry_string }));
96 } else if (diff < 0) {
97 $('header').append(repl('<div class="expiry-info"> \
98 This ERPNext subscription <b>has expired</b>. \
99 </div>', { expiry_string: expiry_string }));
100 }
101 }
102 erpnext.set_about();
103 if(wn.control_panel.custom_startup_code)
104 eval(wn.control_panel.custom_startup_code);
105 }
106}
107
108
109// ========== Update Messages ============
110erpnext.update_messages = function(reset) {
111 // Updates Team Messages
112
113 if(inList(['Guest'], user) || !wn.session_alive) { return; }
114
115 if(!reset) {
116 var set_messages = function(r) {
117 if(!r.exc) {
118 // This function is defined in toolbar.js
119 erpnext.toolbar.set_new_comments(r.message.unread_messages);
120
121 var show_in_circle = function(parent_id, msg) {
122 var parent = $('#'+parent_id);
123 if(parent) {
124 if(msg) {
125 parent.find('span:first').text(msg);
126 parent.toggle(true);
127 } else {
128 parent.toggle(false);
129 }
130 }
131 }
132
133 show_in_circle('unread_messages', r.message.unread_messages.length);
134 show_in_circle('open_support_tickets', r.message.open_support_tickets);
135 show_in_circle('things_todo', r.message.things_todo);
136 show_in_circle('todays_events', r.message.todays_events);
137 show_in_circle('open_tasks', r.message.open_tasks);
138 show_in_circle('unanswered_questions', r.message.unanswered_questions);
139
140 } else {
141 clearInterval(wn.updates.id);
142 }
143 }
144
145 wn.call({
146 method: 'startup.startup.get_global_status_messages',
147 callback: set_messages
148 });
149
150 } else {
151 erpnext.toolbar.set_new_comments(0);
152 $('#unread_messages').toggle(false);
153 }
154}
155
156erpnext.startup.set_periodic_updates = function() {
157 // Set interval for periodic updates of team messages
158 wn.updates = {};
159
160 if(wn.updates.id) {
161 clearInterval(wn.updates.id);
162 }
163
164 wn.updates.id = setInterval(erpnext.update_messages, 60000);
165}
166
167erpnext.set_user_background = function(src) {
168 set_style(repl('#body_div { background: url("files/%(src)s") repeat;}', {src:src}))
169}
170
171// start
172$(document).bind('startup', function() {
173 erpnext.startup.start();
174});
175
176// subject, sender, description
177erpnext.send_message = function(opts) {
178 if(opts.btn) {
179 $(opts.btn).start_working();
180 }
181 wn.call({
182 method: 'website.send_message',
183 args: opts,
184 callback: function(r) {
185 if(opts.btn) {
186 $(opts.btn).done_working();
187 }
188 if(opts.callback)opts.callback(r)
189 }
190 });
191}
192
193erpnext.hide_naming_series = function() {
194 if(cur_frm.fields_dict.naming_series) {
195 hide_field('naming_series');
196 if(cur_frm.doc.__islocal) {
197 unhide_field('naming_series');
198 }
199 }
200}
Rushabh Mehtacebb0272012-09-28 12:18:43 +0530201
202Mousetrap.bind(["command+g", "ctrl+g"], function() {
203 wn.ui.toolbar.search.show();
204 return false;
205});
206
207Mousetrap.bind(["command+s", "ctrl+s"], function() {
208 if(cur_frm)
209 cur_frm.save();
210 return false;
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530211});
212
213// theme setter
214
215erpnext.themes = {
Rushabh Mehta3c041932012-09-28 18:47:47 +0530216 "Default": {
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530217 sidebar: "#f2f2f2",
218 titlebar: "#dfdfdf",
219 toolbar: "#e9e9e9"
220 },
Rushabh Mehta3c041932012-09-28 18:47:47 +0530221 Desert: {
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530222 sidebar: "#FFFDF7",
223 titlebar: "#DAD4C2",
224 toolbar: "#FAF6E9"
225 },
Rushabh Mehta3c041932012-09-28 18:47:47 +0530226 Tropic: {
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530227 sidebar: "#FAFFF7",
228 toolbar: "#EEFAE9",
229 titlebar: "#D7ECD1"
230 },
Rushabh Mehta3c041932012-09-28 18:47:47 +0530231 Sky: {
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530232 sidebar: "#F7FFFE",
233 toolbar: "#E9F9FA",
234 titlebar: "#D7F5F7"
235 },
Rushabh Mehta3c041932012-09-28 18:47:47 +0530236 Snow: {
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530237 sidebar: "#fff",
238 titlebar: "#fff",
239 toolbar: "#fff"
240 },
Rushabh Mehta3c041932012-09-28 18:47:47 +0530241 Sunny: {
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530242 sidebar: "#FFFFEF",
Rushabh Mehta3c041932012-09-28 18:47:47 +0530243 titlebar: "#FFFDCA",
244 toolbar: "lightYellow"
245 },
246 Floral: {
247 sidebar: "#FFF7F7",
248 titlebar: "#F7CBCB",
249 toolbar: "#FAE9EA"
250 },
251 Ocean: {
252 sidebar: "#F2FFFE",
253 titlebar: "#8ACFC7",
254 toolbar: "#C3F3EE"
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530255 }
256}
257
258erpnext.set_theme = function(theme) {
259 wn.dom.set_style(repl(".layout-wrapper-background { \
260 background-color: %(sidebar)s !important; }\
261 .appframe-toolbar { \
262 background-color: %(toolbar)s !important; }\
263 .appframe-titlebar { \
264 background-color: %(titlebar)s !important; }", erpnext.themes[theme]));
265}