PageRenderTime 26ms CodeModel.GetById 16ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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