DynamicModule.js 1.33 KB


Ext.define('amdaDesktop.DynamicModule', {
	extend: 'Ext.ux.desktop.Module',

	/**
     * @cfg {String} id
     * @required
     */
	id : '',
    /**
     * @cfg {String} icon
     * @required
     */
	icon : '',
    /**
     * @cfg {String} title
     * @required
     */
	title : '',
	/**
	 * @cfg {String} source
	 * @required
	 */
	source : '',
	
	module: null,
	
	launcher: null,
	
	constructor : function(id, icon, title, source, useLauncher){
		this.id = id;
		this.icon = icon;
		this.title = title;
		this.source = source;
		if (useLauncher)
			this.launcher = {
    			text : this.title,
    			iconCls : this.icon,
    			handler : this.createWindow,
    			scope : this
			};
		this.callParent(arguments);
	},
	
	isReady : function(){
		return (this.module != null);
	},
	
	get : function(onReady){
		if (!this.isReady())
		{
			var me = this;
			loadMask.show();
			Ext.require(me.source, function() {
				me.module = Ext.create(me.source, {id : me.id, icon : me.icon, title : me.title});
				me.module.app = myDesktopApp;
				if (onReady)
					onReady(me.module);
				loadMask.hide();
			});
		}
		else if (onReady)
			onReady(this.module);
		return this.module;
	},
       
	/**
	 * Window Creation method of the Module
	 */
	createWindow : function () {
		var me = this;
		this.get(function (module) {
			me.module.createWindow();
		});
	}
});