PlotModule.js 3.55 KB
/** 
 * Project   : AMDA-NG
 * Name      : PlotModule.js
 * @class    amdaDesktop.PlotModule
 * @extends  amdaDesktop.InteractiveModule
 * @brief    New Plot Module controller definition 
 * @author   Benjamin Renard
 * $Id: PlotModule.js benjamin $
 */

Ext.define('amdaDesktop.PlotModule', {
	extend: 'amdaDesktop.InteractiveModule',
	
	requires: [
	           'amdaUI.PlotUI',
	           'amdaPlotObj.PlotRequestObject',
	           'amdaModel.PlotNode',
	           'amdaUI.PlotTabResultUI'
	],
	
	contentId : 'plotUI',
    linkedNode : null,
    
    /**
     * @cfg {String} data models
     * @required
     */
    nodeDataModel : 'amdaModel.PlotNode',
    //objectDataModel : 'amdaPlotObj.PlotRequestObject',
    
    /**
     * @cfg {String} window definitions
     * @required
     */
    width: 600, 
    height: 620,
    uiType : 'newPanelPlot',
    helpTitle : 'Help on Plot Module',
    
    plotResultWindowsManager : new Ext.AbstractManager(),
    
    saveState: function() {
            /*var uiContent = this.getUiContent();               
            var form = uiContent.down('form').getForm();
            var values = form.getValues();                
            //   Ext.state.Manager.set(this.id + '_form', values);
            Ext.state.Manager.set('timeinterval', {'startDate' : values.startDate,'stopDate' : values.stopDate });*/
    },
       
    getState : function() {            
        //   return Ext.state.Manager.get(this.id + '_form'); 
        return Ext.state.Manager.get('timeinterval'); 
    },
    
    computeResultWindowSize : function(panelResult)
	{
	    var size = panelResult.getImageSize();
	    size.width  += 30;
	    size.height += 95;
	    
	    return size;
	},
    
    updateInteractiveSession : function(session) {
    	var me = this;
    	Ext.each(session.result, function (tabResult, index) {
    		var winResultId = tabResult.id+"-win";
    		
    		var winResult = me.getWindowResult(winResultId);
    		
    		var plotTabConfig = {
					folder   : session.folder,
					plotFile : tabResult.plot,
					context  : tabResult.context,
					tabId    : tabResult.id
			};
    		
    		if (winResult == null) {
    			//create new result win
    			var panelResult = new amdaUI.PlotTabResultUI(plotTabConfig);
    		
    			var size = me.computeResultWindowSize(panelResult);
    		
    			var win = myDesktopApp.getDesktop().createWindow({
    				id    : tabResult.id+"-win",
    				title : 'Plot '+(index+1),
    				width : size.width,
    				height: size.height,
    				layout: 'fit',
    				items : [ 
    				         panelResult 
    				],
    				listeners: {
    					scope: me,				  
    					beforeclose: function(win,opt) {
    						me.plotResultWindowsManager.unregister(win);
    					}
    				},
    				getPanelResult: function() {
    					return panelResult;
    				}
    			});
    			win.show();
    			me.plotResultWindowsManager.register(win);
    		}
    		else
    		{
    			//update result
    			winResult.getPanelResult().updatePlotImage(plotTabConfig);
    			//update window size
    			var size = me.computeResultWindowSize(winResult.getPanelResult());
    			winResult.setSize(size.width, size.height);
    			
    			winResult.toFront();
    		}
    	});
    },
    
    closeInteractiveSession : function() {
    	var me = this;
    	this.plotResultWindowsManager.each(function (key, value, length) {
    		value.close();
    	});
    },
    
    getWindowResult: function(winResultId){
	    if (!this.plotResultWindowsManager.get(winResultId)) return null;
	    return this.plotResultWindowsManager.get(winResultId);	    
	}
});