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