X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/6a7e4474cba9d8be4b2ec445e10f1691f7277c50..HEAD:/examples/desktop/js/App.js diff --git a/examples/desktop/js/App.js b/examples/desktop/js/App.js index 24b9af91..c71f061f 100644 --- a/examples/desktop/js/App.js +++ b/examples/desktop/js/App.js @@ -1,83 +1,173 @@ +/* + +This file is part of Ext JS 4 + +Copyright (c) 2011 Sencha Inc + +Contact: http://www.sencha.com/contact + +GNU General Public License Usage +This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. + +If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact. + +*/ /*! - * Ext JS Library 3.2.0 - * Copyright(c) 2006-2010 Ext JS, Inc. - * licensing@extjs.com - * http://www.extjs.com/license + * Ext JS Library 4.0 + * Copyright(c) 2006-2011 Sencha Inc. + * licensing@sencha.com + * http://www.sencha.com/license */ -Ext.app.App = function(cfg){ - Ext.apply(this, cfg); - this.addEvents({ - 'ready' : true, - 'beforeunload' : true - }); - Ext.onReady(this.initApp, this); -}; +Ext.define('Ext.ux.desktop.App', { + mixins: { + observable: 'Ext.util.Observable' + }, + + requires: [ + 'Ext.container.Viewport', + + 'Ext.ux.desktop.Desktop' + ], -Ext.extend(Ext.app.App, Ext.util.Observable, { isReady: false, - startMenu: null, modules: null, + useQuickTips: true, - getStartConfig : function(){ + constructor: function (config) { + var me = this; + me.addEvents( + 'ready', + 'beforeunload' + ); - }, + me.mixins.observable.constructor.call(this, config); - initApp : function(){ - this.startConfig = this.startConfig || this.getStartConfig(); + if (Ext.isReady) { + Ext.Function.defer(me.init, 10, me); + } else { + Ext.onReady(me.init, me); + } + }, - this.desktop = new Ext.Desktop(this); + init: function() { + var me = this, desktopCfg; - this.launcher = this.desktop.taskbar.startMenu; + if (me.useQuickTips) { + Ext.QuickTips.init(); + } - this.modules = this.getModules(); - if(this.modules){ - this.initModules(this.modules); + me.modules = me.getModules(); + if (me.modules) { + me.initModules(me.modules); } - this.init(); + desktopCfg = me.getDesktopConfig(); + me.desktop = new Ext.ux.desktop.Desktop(desktopCfg); + + me.viewport = new Ext.container.Viewport({ + layout: 'fit', + items: [ me.desktop ] + }); - Ext.EventManager.on(window, 'beforeunload', this.onUnload, this); - this.fireEvent('ready', this); - this.isReady = true; + Ext.EventManager.on(window, 'beforeunload', me.onUnload, me); + + me.isReady = true; + me.fireEvent('ready', me); }, - getModules : Ext.emptyFn, - init : Ext.emptyFn, + /** + * This method returns the configuration object for the Desktop object. A derived + * class can override this method, call the base version to build the config and + * then modify the returned object before returning it. + */ + getDesktopConfig: function () { + var me = this, cfg = { + app: me, + taskbarConfig: me.getTaskbarConfig() + }; + + Ext.apply(cfg, me.desktopConfig); + return cfg; + }, - initModules : function(ms){ - for(var i = 0, len = ms.length; i < len; i++){ - var m = ms[i]; - this.launcher.add(m.launcher); - m.app = this; - } + getModules: Ext.emptyFn, + + /** + * This method returns the configuration object for the Start Button. A derived + * class can override this method, call the base version to build the config and + * then modify the returned object before returning it. + */ + getStartConfig: function () { + var me = this, cfg = { + app: me, + menu: [] + }; + + Ext.apply(cfg, me.startConfig); + + Ext.each(me.modules, function (module) { + if (module.launcher) { + cfg.menu.push(module.launcher); + } + }); + + return cfg; + }, + + /** + * This method returns the configuration object for the TaskBar. A derived class + * can override this method, call the base version to build the config and then + * modify the returned object before returning it. + */ + getTaskbarConfig: function () { + var me = this, cfg = { + app: me, + startConfig: me.getStartConfig() + }; + + Ext.apply(cfg, me.taskbarConfig); + return cfg; }, - getModule : function(name){ + initModules : function(modules) { + var me = this; + Ext.each(modules, function (module) { + module.app = me; + }); + }, + + getModule : function(name) { var ms = this.modules; - for(var i = 0, len = ms.length; i < len; i++){ - if(ms[i].id == name || ms[i].appType == name){ - return ms[i]; - } + for (var i = 0, len = ms.length; i < len; i++) { + var m = ms[i]; + if (m.id == name || m.appType == name) { + return m; + } } - return ''; + return null; }, - onReady : function(fn, scope){ - if(!this.isReady){ - this.on('ready', fn, scope); - }else{ + onReady : function(fn, scope) { + if (this.isReady) { fn.call(scope, this); + } else { + this.on({ + ready: fn, + scope: scope, + single: true + }); } }, - getDesktop : function(){ + getDesktop : function() { return this.desktop; }, - onUnload : function(e){ - if(this.fireEvent('beforeunload', this) === false){ + onUnload : function(e) { + if (this.fireEvent('beforeunload', this) === false) { e.stopEvent(); } } -}); \ No newline at end of file +}); +