You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

163 line
4.0 KiB

  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. if(!console) {
  23. var console = {
  24. log: function(txt) {
  25. // suppress
  26. }
  27. }
  28. }
  29. $(document).ready(function() {
  30. wn.assets.check();
  31. wn.provide('wn.app');
  32. $.extend(wn.app, new wn.Application());
  33. });
  34. wn.Application = Class.extend({
  35. init: function() {
  36. this.load_startup();
  37. },
  38. load_startup: function() {
  39. var me = this;
  40. if(window.app) {
  41. wn.call({
  42. method: 'startup',
  43. callback: function(r, rt) {
  44. wn.provide('wn.boot');
  45. wn.boot = r;
  46. if(wn.boot.profile.name=='Guest') {
  47. window.location = 'index.html';
  48. return;
  49. }
  50. me.startup();
  51. }
  52. })
  53. } else {
  54. this.startup();
  55. }
  56. },
  57. startup: function() {
  58. // load boot info
  59. this.load_bootinfo();
  60. // page container
  61. this.make_page_container();
  62. // navbar
  63. this.make_nav_bar();
  64. // favicon
  65. this.set_favicon();
  66. if(user!="Guest") this.set_user_display_settings();
  67. // trigger app startup
  68. $(document).trigger('startup');
  69. if(wn.boot) {
  70. // route to home page
  71. wn.route();
  72. }
  73. $(document).trigger('app_ready');
  74. },
  75. set_user_display_settings: function() {
  76. if(wn.boot.profile.background_image) {
  77. wn.ui.set_user_background(wn.boot.profile.background_image);
  78. }
  79. if(wn.boot.profile.theme) {
  80. wn.ui.set_theme(wn.boot.profile.theme);
  81. }
  82. },
  83. load_bootinfo: function() {
  84. if(wn.boot) {
  85. wn.control_panel = wn.boot.control_panel;
  86. this.set_globals();
  87. } else {
  88. this.set_as_guest();
  89. }
  90. },
  91. set_globals: function() {
  92. // for backward compatibility
  93. profile = wn.boot.profile;
  94. user = wn.boot.profile.name;
  95. user_fullname = wn.user_info(user).fullname;
  96. user_defaults = profile.defaults;
  97. user_roles = profile.roles;
  98. user_email = profile.email;
  99. sys_defaults = wn.boot.sysdefaults;
  100. },
  101. set_as_guest: function() {
  102. // for backward compatibility
  103. profile = {name:'Guest'};
  104. user = 'Guest';
  105. user_fullname = 'Guest';
  106. user_defaults = {};
  107. user_roles = ['Guest'];
  108. user_email = '';
  109. sys_defaults = {};
  110. },
  111. make_page_container: function() {
  112. if($("#body_div").length) {
  113. wn.temp_container = $("<div id='#temp-container' style='display: none;'>")
  114. .appendTo("body");
  115. wn.container = new wn.views.Container();
  116. wn.views.make_403();
  117. wn.views.make_404();
  118. }
  119. },
  120. make_nav_bar: function() {
  121. // toolbar
  122. if(wn.boot) {
  123. wn.container.wntoolbar = new wn.ui.toolbar.Toolbar();
  124. }
  125. },
  126. logout: function() {
  127. var me = this;
  128. me.logged_out = true;
  129. wn.call({
  130. method:'logout',
  131. callback: function(r) {
  132. if(r.exc) {
  133. console.log(r.exc);
  134. }
  135. me.redirect_to_login();
  136. }
  137. })
  138. },
  139. redirect_to_login: function() {
  140. window.location.href = 'index.html';
  141. },
  142. set_favicon: function() {
  143. var link = $('link[type="image/x-icon"]').remove().attr("href");
  144. var favicon ='\
  145. <link rel="shortcut icon" href="' + link + '" type="image/x-icon"> \
  146. <link rel="icon" href="' + link + '" type="image/x-icon">'
  147. $(favicon).appendTo('head');
  148. }
  149. })