// Copyright 2013 Web Notes Technologies Pvt Ltd // MIT Licensed. See license.txt if(!console) { var console = { log: function(txt) { // suppress } } } $(document).ready(function() { wn.assets.check(); wn.provide('wn.app'); $.extend(wn.app, new wn.Application()); }); wn._toc = [ "wn.model", "wn.ui", "wn.utils", "wn.views" ] wn.Application = Class.extend({ init: function() { this.load_startup(); }, load_startup: function() { var me = this; if(window.app) { wn.call({ method: 'startup', callback: function(r, rt) { wn.provide('wn.boot'); wn.boot = r; if(wn.boot.profile.name=='Guest') { window.location = 'index.html'; return; } me.startup(); } }) } else { this.startup(); } }, startup: function() { // load boot info this.load_bootinfo(); // page container this.make_page_container(); // navbar this.make_nav_bar(); // favicon this.set_favicon(); if(user!="Guest") this.set_user_display_settings(); // trigger app startup $(document).trigger('startup'); if(wn.boot) { // route to home page wn.route(); } this.start_notification_updates(); $(document).trigger('app_ready'); }, set_user_display_settings: function() { if(wn.boot.profile.background_image) { wn.ui.set_user_background(wn.boot.profile.background_image); } }, load_bootinfo: function() { if(wn.boot) { wn.control_panel = wn.boot.control_panel; wn.modules = wn.boot.modules; this.set_globals(); this.sync_pages(); } else { this.set_as_guest(); } }, start_notification_updates: function() { var me = this; setInterval(function() { me.refresh_notifications(); }, 30000); // first time loaded in boot $(document).trigger("notification-update"); // refresh notifications if user is back after sometime $(document).on("session_alive", function() { me.refresh_notifications(); }) }, refresh_notifications: function() { if(wn.session_alive) { wn.call({ method: "webnotes.widgets.notification.get", callback: function(r) { if(r.message) { $.extend(wn.boot.notification_info, r.message); $(document).trigger("notification-update"); } }, no_spinner: true }); } }, set_globals: function() { // for backward compatibility profile = wn.boot.profile; user = wn.boot.profile.name; user_fullname = wn.user_info(user).fullname; user_defaults = profile.defaults; user_roles = profile.roles; user_email = profile.email; sys_defaults = wn.boot.sysdefaults; }, sync_pages: function() { // clear cached pages if timestamp is not found if(localStorage["page_info"]) { wn.boot.allowed_pages = []; page_info = JSON.parse(localStorage["page_info"]); $.each(wn.boot.page_info, function(name, modified) { if(page_info[name]!=modified) { delete localStorage["_page:" + name]; } wn.boot.allowed_pages.push(name); }); } else { wn.boot.allowed_pages = keys(wn.boot.page_info); } localStorage["page_info"] = JSON.stringify(wn.boot.page_info); }, set_as_guest: function() { // for backward compatibility profile = {name:'Guest'}; user = 'Guest'; user_fullname = 'Guest'; user_defaults = {}; user_roles = ['Guest']; user_email = ''; sys_defaults = {}; }, make_page_container: function() { if($("#body_div").length) { $(".splash").remove(); wn.temp_container = $("