/ext-4.1.0_b3/examples/desktop/js/App.js

https://bitbucket.org/srogerf/javascript · JavaScript · 167 lines · 117 code · 29 blank · 21 comment · 14 complexity · 4d8689be974c8ae2e4954bfc4aa5eb52 MD5 · raw file

  1. /*!
  2. * Ext JS Library 4.0
  3. * Copyright(c) 2006-2011 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.define('Ext.ux.desktop.App', {
  8. mixins: {
  9. observable: 'Ext.util.Observable'
  10. },
  11. requires: [
  12. 'Ext.container.Viewport',
  13. 'Ext.ux.desktop.Desktop'
  14. ],
  15. isReady: false,
  16. modules: null,
  17. useQuickTips: true,
  18. constructor: function (config) {
  19. var me = this;
  20. me.addEvents(
  21. 'ready',
  22. 'beforeunload'
  23. );
  24. me.mixins.observable.constructor.call(this, config);
  25. if (Ext.isReady) {
  26. Ext.Function.defer(me.init, 10, me);
  27. } else {
  28. Ext.onReady(me.init, me);
  29. }
  30. },
  31. init: function() {
  32. var me = this, desktopCfg;
  33. if (me.useQuickTips) {
  34. Ext.QuickTips.init();
  35. }
  36. me.modules = me.getModules();
  37. if (me.modules) {
  38. me.initModules(me.modules);
  39. }
  40. desktopCfg = me.getDesktopConfig();
  41. me.desktop = new Ext.ux.desktop.Desktop(desktopCfg);
  42. me.viewport = new Ext.container.Viewport({
  43. layout: 'fit',
  44. items: [ me.desktop ]
  45. });
  46. Ext.EventManager.on(window, 'beforeunload', me.onUnload, me);
  47. me.isReady = true;
  48. me.fireEvent('ready', me);
  49. },
  50. /**
  51. * This method returns the configuration object for the Desktop object. A derived
  52. * class can override this method, call the base version to build the config and
  53. * then modify the returned object before returning it.
  54. */
  55. getDesktopConfig: function () {
  56. var me = this, cfg = {
  57. app: me,
  58. taskbarConfig: me.getTaskbarConfig()
  59. };
  60. Ext.apply(cfg, me.desktopConfig);
  61. return cfg;
  62. },
  63. getModules: Ext.emptyFn,
  64. /**
  65. * This method returns the configuration object for the Start Button. A derived
  66. * class can override this method, call the base version to build the config and
  67. * then modify the returned object before returning it.
  68. */
  69. getStartConfig: function () {
  70. var me = this,
  71. cfg = {
  72. app: me,
  73. menu: []
  74. },
  75. launcher;
  76. Ext.apply(cfg, me.startConfig);
  77. Ext.each(me.modules, function (module) {
  78. launcher = module.launcher;
  79. if (launcher) {
  80. launcher.handler = launcher.handler || Ext.bind(me.createWindow, me, [module]);
  81. cfg.menu.push(module.launcher);
  82. }
  83. });
  84. return cfg;
  85. },
  86. createWindow: function(module) {
  87. var window = module.createWindow();
  88. window.show();
  89. },
  90. /**
  91. * This method returns the configuration object for the TaskBar. A derived class
  92. * can override this method, call the base version to build the config and then
  93. * modify the returned object before returning it.
  94. */
  95. getTaskbarConfig: function () {
  96. var me = this, cfg = {
  97. app: me,
  98. startConfig: me.getStartConfig()
  99. };
  100. Ext.apply(cfg, me.taskbarConfig);
  101. return cfg;
  102. },
  103. initModules : function(modules) {
  104. var me = this;
  105. Ext.each(modules, function (module) {
  106. module.app = me;
  107. });
  108. },
  109. getModule : function(name) {
  110. var ms = this.modules;
  111. for (var i = 0, len = ms.length; i < len; i++) {
  112. var m = ms[i];
  113. if (m.id == name || m.appType == name) {
  114. return m;
  115. }
  116. }
  117. return null;
  118. },
  119. onReady : function(fn, scope) {
  120. if (this.isReady) {
  121. fn.call(scope, this);
  122. } else {
  123. this.on({
  124. ready: fn,
  125. scope: scope,
  126. single: true
  127. });
  128. }
  129. },
  130. getDesktop : function() {
  131. return this.desktop;
  132. },
  133. onUnload : function(e) {
  134. if (this.fireEvent('beforeunload', this) === false) {
  135. e.stopEvent();
  136. }
  137. }
  138. });