Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / examples / desktop / js / App.js
old mode 100644 (file)
new mode 100755 (executable)
index 70ed55b..383cd08
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-Ext.app.App = function(cfg){\r
-    Ext.apply(this, cfg);\r
-    this.addEvents({\r
-        'ready' : true,\r
-        'beforeunload' : true\r
-    });\r
-\r
-    Ext.onReady(this.initApp, this);\r
-};\r
-\r
-Ext.extend(Ext.app.App, Ext.util.Observable, {\r
-    isReady: false,\r
-    startMenu: null,\r
-    modules: null,\r
-\r
-    getStartConfig : function(){\r
-\r
-    },\r
-\r
-    initApp : function(){\r
-       this.startConfig = this.startConfig || this.getStartConfig();\r
-\r
-        this.desktop = new Ext.Desktop(this);\r
-\r
-               this.launcher = this.desktop.taskbar.startMenu;\r
-\r
-               this.modules = this.getModules();\r
-        if(this.modules){\r
-            this.initModules(this.modules);\r
-        }\r
-\r
-        this.init();\r
-\r
-        Ext.EventManager.on(window, 'beforeunload', this.onUnload, this);\r
-               this.fireEvent('ready', this);\r
-        this.isReady = true;\r
-    },\r
-\r
-    getModules : Ext.emptyFn,\r
-    init : Ext.emptyFn,\r
-\r
-    initModules : function(ms){\r
-               for(var i = 0, len = ms.length; i < len; i++){\r
-            var m = ms[i];\r
-            this.launcher.add(m.launcher);\r
-            m.app = this;\r
-        }\r
-    },\r
-\r
-    getModule : function(name){\r
-       var ms = this.modules;\r
-       for(var i = 0, len = ms.length; i < len; i++){\r
-               if(ms[i].id == name || ms[i].appType == name){\r
-                       return ms[i];\r
-                       }\r
-        }\r
-        return '';\r
-    },\r
-\r
-    onReady : function(fn, scope){\r
-        if(!this.isReady){\r
-            this.on('ready', fn, scope);\r
-        }else{\r
-            fn.call(scope, this);\r
-        }\r
-    },\r
-\r
-    getDesktop : function(){\r
-        return this.desktop;\r
-    },\r
-\r
-    onUnload : function(e){\r
-        if(this.fireEvent('beforeunload', this) === false){\r
-            e.stopEvent();\r
-        }\r
-    }\r
-});
\ No newline at end of file
+/*!
+ * Ext JS Library 4.0
+ * Copyright(c) 2006-2011 Sencha Inc.
+ * licensing@sencha.com
+ * http://www.sencha.com/license
+ */
+
+Ext.define('Ext.ux.desktop.App', {
+    mixins: {
+        observable: 'Ext.util.Observable'
+    },
+
+    requires: [
+        'Ext.container.Viewport',
+
+        'Ext.ux.desktop.Desktop'
+    ],
+
+    isReady: false,
+    modules: null,
+    useQuickTips: true,
+
+    constructor: function (config) {
+        var me = this;
+        me.addEvents(
+            'ready',
+            'beforeunload'
+        );
+
+        me.mixins.observable.constructor.call(this, config);
+
+        if (Ext.isReady) {
+            Ext.Function.defer(me.init, 10, me);
+        } else {
+            Ext.onReady(me.init, me);
+        }
+    },
+
+    init: function() {
+        var me = this, desktopCfg;
+
+        if (me.useQuickTips) {
+            Ext.QuickTips.init();
+        }
+
+        me.modules = me.getModules();
+        if (me.modules) {
+            me.initModules(me.modules);
+        }
+
+        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', me.onUnload, me);
+
+        me.isReady = true;
+        me.fireEvent('ready', me);
+    },
+
+    /**
+     * 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;
+    },
+
+    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;
+    },
+
+    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++) {
+            var m = ms[i];
+            if (m.id == name || m.appType == name) {
+                return m;
+            }
+        }
+        return null;
+    },
+
+    onReady : function(fn, scope) {
+        if (this.isReady) {
+            fn.call(scope, this);
+        } else {
+            this.on({
+                ready: fn,
+                scope: scope,
+                single: true
+            });
+        }
+    },
+
+    getDesktop : function() {
+        return this.desktop;
+    },
+
+    onUnload : function(e) {
+        if (this.fireEvent('beforeunload', this) === false) {
+            e.stopEvent();
+        }
+    }
+});