App.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.app.App = function(cfg){
  8. Ext.apply(this, cfg);
  9. this.addEvents({
  10. 'ready' : true,
  11. 'beforeunload' : true
  12. });
  13. Ext.onReady(this.initApp, this);
  14. };
  15. Ext.extend(Ext.app.App, Ext.util.Observable, {
  16. isReady: false,
  17. startMenu: null,
  18. modules: null,
  19. getStartConfig : function(){
  20. },
  21. initApp : function(){
  22. this.startConfig = this.startConfig || this.getStartConfig();
  23. this.desktop = new Ext.Desktop(this);
  24. this.launcher = this.desktop.taskbar.startMenu;
  25. this.modules = this.getModules();
  26. if(this.modules){
  27. this.initModules(this.modules);
  28. }
  29. this.init();
  30. Ext.EventManager.on(window, 'beforeunload', this.onUnload, this);
  31. this.fireEvent('ready', this);
  32. this.isReady = true;
  33. },
  34. getModules : Ext.emptyFn,
  35. init : Ext.emptyFn,
  36. initModules : function(ms){
  37. for(var i = 0, len = ms.length; i < len; i++){
  38. var m = ms[i];
  39. this.launcher.add(m.launcher);
  40. m.app = this;
  41. }
  42. },
  43. getModule : function(name){
  44. var ms = this.modules;
  45. for(var i = 0, len = ms.length; i < len; i++){
  46. if(ms[i].id == name || ms[i].appType == name){
  47. return ms[i];
  48. }
  49. }
  50. return '';
  51. },
  52. onReady : function(fn, scope){
  53. if(!this.isReady){
  54. this.on('ready', fn, scope);
  55. }else{
  56. fn.call(scope, this);
  57. }
  58. },
  59. getDesktop : function(){
  60. return this.desktop;
  61. },
  62. onUnload : function(e){
  63. if(this.fireEvent('beforeunload', this) === false){
  64. e.stopEvent();
  65. }
  66. }
  67. });