blob: 8cc02cbd487552818d86ba48f2b3292e7888b9d2 [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
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053022erpnext.startup.set_globals = function() {
23 if(inList(user_roles,'System Manager')) is_system_manager = 1;
24}
25
26erpnext.startup.start = function() {
27 console.log('Starting up...');
28 $('#startup_div').html('Starting up...').toggle(true);
29
30
31 erpnext.startup.set_globals();
32
33 if(user != 'Guest'){
34 if(wn.boot.user_background) {
35 erpnext.set_user_background(wn.boot.user_background);
36 }
Rushabh Mehtab0d32b72012-09-28 16:11:57 +053037 if(wn.boot.profile.defaults.theme) {
Rushabh Mehta3c041932012-09-28 18:47:47 +053038 erpnext.set_theme(wn.boot.profile.defaults.theme[0]);
Rushabh Mehtab0d32b72012-09-28 16:11:57 +053039 }
Rushabh Mehta2fa2f712012-09-24 19:13:42 +053040
41 // always allow apps
42 wn.boot.profile.allow_modules = wn.boot.profile.allow_modules.concat(
43 ['To Do', 'Knowledge Base', 'Calendar', 'Activity', 'Messages'])
44
45 // setup toolbar
46 erpnext.toolbar.setup();
47
48 // set interval for updates
49 erpnext.startup.set_periodic_updates();
50
51 // border to the body
52 // ------------------
53 $('footer').html('<div class="web-footer erpnext-footer">\
54 <a href="#!attributions">ERPNext | Attributions and License</a></div>');
55
56 // complete registration
57 if(in_list(user_roles,'System Manager') && (wn.boot.setup_complete=='No')) {
58 wn.require("app/js/complete_setup.js");
59 erpnext.complete_setup.show();
60 }
61 if(wn.boot.expires_on && in_list(user_roles, 'System Manager')) {
62 var today = dateutil.str_to_obj(dateutil.get_today());
63 var expires_on = dateutil.str_to_obj(wn.boot.expires_on);
64 var diff = dateutil.get_diff(expires_on, today);
65 if (0 <= diff && diff <= 15) {
66 var expiry_string = diff==0 ? "today" : repl("in %(diff)s day(s)", { diff: diff });
67 $('header').append(repl('<div class="expiry-info"> \
68 Your ERPNext subscription will <b>expire %(expiry_string)s</b>. \
69 Please renew your subscription to continue using ERPNext \
70 (and remove this annoying banner). \
71 </div>', { expiry_string: expiry_string }));
72 } else if (diff < 0) {
73 $('header').append(repl('<div class="expiry-info"> \
74 This ERPNext subscription <b>has expired</b>. \
75 </div>', { expiry_string: expiry_string }));
76 }
77 }
78 erpnext.set_about();
79 if(wn.control_panel.custom_startup_code)
80 eval(wn.control_panel.custom_startup_code);
81 }
82}
83
84
85// ========== Update Messages ============
86erpnext.update_messages = function(reset) {
87 // Updates Team Messages
88
89 if(inList(['Guest'], user) || !wn.session_alive) { return; }
90
91 if(!reset) {
92 var set_messages = function(r) {
93 if(!r.exc) {
94 // This function is defined in toolbar.js
95 erpnext.toolbar.set_new_comments(r.message.unread_messages);
96
97 var show_in_circle = function(parent_id, msg) {
98 var parent = $('#'+parent_id);
99 if(parent) {
100 if(msg) {
101 parent.find('span:first').text(msg);
102 parent.toggle(true);
103 } else {
104 parent.toggle(false);
105 }
106 }
107 }
108
109 show_in_circle('unread_messages', r.message.unread_messages.length);
110 show_in_circle('open_support_tickets', r.message.open_support_tickets);
111 show_in_circle('things_todo', r.message.things_todo);
112 show_in_circle('todays_events', r.message.todays_events);
113 show_in_circle('open_tasks', r.message.open_tasks);
114 show_in_circle('unanswered_questions', r.message.unanswered_questions);
115
116 } else {
117 clearInterval(wn.updates.id);
118 }
119 }
120
121 wn.call({
122 method: 'startup.startup.get_global_status_messages',
123 callback: set_messages
124 });
125
126 } else {
127 erpnext.toolbar.set_new_comments(0);
128 $('#unread_messages').toggle(false);
129 }
130}
131
132erpnext.startup.set_periodic_updates = function() {
133 // Set interval for periodic updates of team messages
134 wn.updates = {};
135
136 if(wn.updates.id) {
137 clearInterval(wn.updates.id);
138 }
139
140 wn.updates.id = setInterval(erpnext.update_messages, 60000);
141}
142
143erpnext.set_user_background = function(src) {
144 set_style(repl('#body_div { background: url("files/%(src)s") repeat;}', {src:src}))
145}
146
Rushabh Mehta2fa2f712012-09-24 19:13:42 +0530147// subject, sender, description
148erpnext.send_message = function(opts) {
149 if(opts.btn) {
150 $(opts.btn).start_working();
151 }
152 wn.call({
153 method: 'website.send_message',
154 args: opts,
155 callback: function(r) {
156 if(opts.btn) {
157 $(opts.btn).done_working();
158 }
159 if(opts.callback)opts.callback(r)
160 }
161 });
162}
163
164erpnext.hide_naming_series = function() {
165 if(cur_frm.fields_dict.naming_series) {
166 hide_field('naming_series');
167 if(cur_frm.doc.__islocal) {
168 unhide_field('naming_series');
169 }
170 }
171}
Rushabh Mehtacebb0272012-09-28 12:18:43 +0530172
173Mousetrap.bind(["command+g", "ctrl+g"], function() {
174 wn.ui.toolbar.search.show();
175 return false;
176});
177
178Mousetrap.bind(["command+s", "ctrl+s"], function() {
179 if(cur_frm)
180 cur_frm.save();
181 return false;
Rushabh Mehtab0d32b72012-09-28 16:11:57 +0530182});
183
Rushabh Mehta9d1faea2012-10-02 14:56:41 +0530184// start
185$(document).bind('startup', function() {
186 erpnext.startup.start();
187});