blob: c68650a800e1e4272a845bbed99c1682699dfe36 [file] [log] [blame]
Brahma Kd1a2cea2011-08-30 09:33:29 +05301var current_module;
2var is_system_manager = 0;
3var module_content_dict = {};
4var user_full_nm = {};
5
Rushabh Mehta865c00a2012-01-24 14:33:21 +05306wn.provide('erpnext.startup');
Brahma Kd1a2cea2011-08-30 09:33:29 +05307
Rushabh Mehta865c00a2012-01-24 14:33:21 +05308erpnext.startup.set_globals = function() {
9 pscript.is_erpnext_saas = cint(wn.control_panel.sync_with_gateway)
10 if(inList(user_roles,'System Manager')) is_system_manager = 1;
11}
Rushabh Mehta8c309be2012-01-20 13:47:16 +053012
Rushabh Mehta865c00a2012-01-24 14:33:21 +053013erpnext.startup.start = function() {
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053014 $('#startup_div').html('Starting up...').toggle(true);
15
Rushabh Mehta865c00a2012-01-24 14:33:21 +053016 erpnext.startup.set_globals();
17
18 if(user == 'Guest'){
19 $dh(page_body.left_sidebar);
Rushabh Mehta7018b192012-02-02 13:42:28 +053020 if(wn.boot.custom_css) {
21 set_style(wn.boot.custom_css);
22 }
23 if(wn.boot.website_settings.title_prefix) {
24 wn.title_prefix = wn.boot.website_settings.title_prefix;
25 }
Rushabh Mehta865c00a2012-01-24 14:33:21 +053026 } else {
27 // modules
Rushabh Mehta865c00a2012-01-24 14:33:21 +053028 pscript.startup_make_sidebar();
Brahma Kd1a2cea2011-08-30 09:33:29 +053029
Rushabh Mehta865c00a2012-01-24 14:33:21 +053030 // setup toolbar
Rushabh Mehta865c00a2012-01-24 14:33:21 +053031 erpnext.toolbar.setup();
Anand Doshic3023be2012-02-20 16:31:55 +053032
33 // set interval for updates
34 erpnext.startup.set_periodic_updates();
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053035
36 // border to the body
37 // ------------------
38 $('footer').html('<div class="erpnext-footer">\
39 Powered by <a href="https://erpnext.com">ERPNext</a></div>');
Brahma Kd1a2cea2011-08-30 09:33:29 +053040 }
Anand Doshic3023be2012-02-20 16:31:55 +053041
Rushabh Mehta9c7a01a2012-01-25 11:04:54 +053042 $('#startup_div').toggle(false);
Brahma Kd1a2cea2011-08-30 09:33:29 +053043}
44
Brahma Kd1a2cea2011-08-30 09:33:29 +053045// chart of accounts
46// ====================================================================
47show_chart_browser = function(nm, chart_type){
48
49 var call_back = function(){
50 if(nm == 'Sales Browser'){
51 var sb_obj = new SalesBrowser();
52 sb_obj.set_val(chart_type);
53 }
54 else if(nm == 'Accounts Browser')
55 pscript.make_chart(chart_type);
56 }
57 loadpage(nm,call_back);
58}
59
60
61// Module Page
62// ====================================================================
63
64ModulePage = function(parent, module_name, module_label, help_page, callback) {
65 this.parent = parent;
66
67 // add to current page
68 page_body.cur_page.module_page = this;
69
70 this.wrapper = $a(parent,'div');
71 this.module_name = module_name;
72 this.transactions = [];
73 this.page_head = new PageHeader(this.wrapper, module_label);
74
75 if(help_page) {
76 var btn = this.page_head.add_button('Help', function() { loadpage(this.help_page) }, 1, 'ui-icon-help')
77 btn.help_page = help_page;
78 }
79
80 if(callback) this.callback = function(){ callback(); }
81}
82
Anand Doshic3023be2012-02-20 16:31:55 +053083// ========== Update Messages ============
84var update_messages = function() {
85 // Updates Team Messages
86
87 if(inList(['Guest', 'Administrator'], user)) { return; }
88
89 $c_page('home', 'event_updates', 'get_unread_messages', null,
90 function(r,rt) {
91 if(!r.exc) {
92 // This function is defined in toolbar.js
93 page_body.wntoolbar.set_new_comments(r.message);
94 }
95 }
96 );
97}
98
99erpnext.startup.set_periodic_updates = function() {
100 // Set interval for periodic updates of team messages
101 wn.updates = {};
102
103 if(wn.updates.id) {
104 clearInterval(wn.updates.id);
105 }
106
107 wn.updates.id = setInterval(update_messages, 180000);
108}
109
110// =======================================
111
Rushabh Mehta865c00a2012-01-24 14:33:21 +0530112// start
Rushabh Mehtaafaac602012-02-14 11:44:13 +0530113$(document).bind('startup', function() {
114 erpnext.startup.start();
115});