Program.js 2.71 KB
Ext.define('MyMA.controller.Program', {
    extend: 'Ext.app.Controller',
    stores: ['Programs'],
    refs: [{
        selector: 'taskpanel',
        ref: 'taskPanel'
    }],
	
    init: function() {
		var control = {};
		Ext.each(this.refs, function(item){
			this.control[item.selector] = {
				beforeclose: this.me.programStop,
				hide: this.me.programState,
				show: this.me.programState,
				minimize: this.me.programMinimize
			}
		}, {
			control: control,
            me: this
		});
		
		this.control(control);
    },
    
    
    /**
     * Register controll for the created "Program"
     * @param   String, selector name
     */
    registerControl: function(selector) {
        var selector = selector || null,
            ctrl = {};
        
        if(!selector) {
            return;
        }
        
        ctrl[selector] = {
            beforeclose: this.programStop,
            hide: this.programState,
            show: this.programState,
            minimize: this.programMinimize
        };
        
        this.control(ctrl);
    }, // end registerControl()
	
	
	/**
	 * Hides widget and sets status to the Store object
     * @param {Object} item
	 */
    programMinimize: function(item) {
        var record;
        
        if(!(record = this.getStore('Programs').getProccess({
            property: 'item',
            value: item.getId()
        })))
        {
            return false;
        }
        
        this.getTaskPanel().items.get(record.get('control')).toggle(false);
        item.hide();
        this.programState(item);
    }, // end programMinimize()
    
    
    /**
     * Writes program state to the Store object
     * @param {Object} item
     * @param {Object} opt
     */
    programState: function(item, opt) {
        var record;
        
        if(!(record = this.getStore('Programs').getProccess({
            property: 'item',
            value: item.getId()
        })))
        {
            return false;
        }
        
		record.set('state', item.isHidden() ? 'hide' : 'show');
    }, // end programState()
    
    
    /**
     * Destroyes wiget and removes program information from the Store
     * @param {Object} item
     * @param {Object} record
     */
    programStop: function(item, record) {
        var record = record || Ext.undefined;
        
		if (!record['data']) {
			(record = this.getStore('Programs').getProccess({
				property: 'item',
				value: item.getId()
			}));
		}
        
        if(item.animateTarget) {
            item.animateTarget = null;
        }
        
        if(record && record['data']) {
            this.getTaskPanel().items.get(record.get('control')).destroy();
            this.getStore('Programs').remove(record);
        }
    } // end programStop()
});