PlotUI.js 6.96 KB
/**
 * Project   : AMDA-NG
 * Name      : PlotUI.js
 * @class   amdaUI.PlotUI
 * @extends Ext.container.Container
 * @brief   New Plot Module UI definition (View)
 * @author  Benjamin Renard
 * @version $Id: PlotUI.js benjamin $
 */


Ext.define('amdaUI.PlotUI', {
	extend: 'Ext.container.Container',
	alias: 'widget.newPanelPlot',
	
	requires: [
	           'amdaModel.DownloadNode',
	           'amdaModel.Download',
	           'amdaUI.TimeSelectorUI',
	           'amdaPlotComp.PlotTabPanel',
	           'amdaPlotComp.PlotOutputForm',
	           'amdaPlotComp.PlotElementPanel'
    ],
	
	formPanel: null,
	
	multiPlotIntervalPanel : null,
	
	plotOutput: null,
	
	plotTabs : null,
	
	plotElement : null,
	
	constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
		if (this.object)
			this.setObject(this.object);
	},
	
	setObject : function(object) {
		this.object = object;
		this.plotOutput.setObject(this.object);
		this.plotTabs.setRequestObject(this.object);
		this.timeSelector.intervalSel.setInterval(this.object.get('startDate'), this.object.get('stopDate'));
	},
	
	/**
     * save method called by Save button to launch the save process
     */
    saveProcess : function(){
    	var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
    	if (plotModule)
    		plotModule.linkedNode.create();
    },
    
    resetProcess : function(){
    	var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);			
		plotModule.createLinkedNode();
		plotModule.createObject();					  
		this.setObject(plotModule.linkedNode.get('object'));
    },
	
    getDataProcess : function(){
    	var downObject = amdaModel.DownloadNode.decodeObject(this.object);
    	amdaModel.DownloadNode.set('object',Ext.create('amdaModel.Download',downObject));		 
    	amdaModel.DownloadNode.editInModule(); 
    },
    
    addParameter : function(node){
    	var crtTree = this.plotTabs.getTreeFromPlotTab(this.plotTabs.getActiveTab());
    	crtTree.dropRecord(node,null,'append');
    },
    
	/**
     * plot method called by 'Do Plot' button to launch the plot process
     */
    doPlot : function(){
    	var timeSource = this.timeSelector.getActiveTimeSource();
    	var multiPlotForm = this.multiPlotIntervalPanel.getForm();
    	multiPlotForm.updateRecord(this.object);
    	this.object.set('timesrc', timeSource);
    	if (timeSource === amdaModel.AmdaTimeObject.inputTimeSrc[0])
        	this.object.set('timeTables',this.timeSelector.TTGrid.getStore().data.items);
    	this.plotTabs.updateTimeObject();
    	
    	// fire execution        
    	var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
    	if (plotModule)
    		plotModule.linkedNode.execute();
    },  
	
	/**
	 * Check if changes were made before closing window 
	 * @return false
	 */	
	fclose : function() {
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id, true, function (module) {
			module.closeInteractiveSession();
		});
		
		return false;
	},
	
	addTT : function(newTTName,newTTid)
    {		 
		this.timeSelector.addTT(newTTName,newTTid);
	},

    addTTs : function(TTarray) {
    	// set TTTab	    
    	this.timeSelector.setTTTab(TTarray);
    },
    
    /**
     * Set Start-Stop from parameter info (Local & MyData)
     */ 
     setTimeFromData : function(obj) 
     {                                                               
         var dateStart = new Date(obj.start.replace(/[T|Z]/g,' ').replace(/\-/g,'\/')); 
         var dateStop = new Date(obj.stop.replace(/[T|Z]/g,' ').replace(/\-/g,'\/')); 
         
         this.timeSelector.intervalSel.setInterval(dateStart, dateStop);
         this.timeSelector.intervalSel.updateDuration();        
    },
	
    updateLinkedToMultiPlotMode : function(isLinkedToMultiPlotMode) {
		this.multiPlotIntervalPanel.setVisible(isLinkedToMultiPlotMode);
	},
    
	init : function(config) {
		this.timeSelector = new amdaUI.TimeSelectorUI( { id: 'plotTimeSelector' + config.id, flex: 1, title : 'MultiPlot Time Selection'} );
		
		this.plotOutput = new amdaPlotComp.PlotOutputForm({flex: 2});
		
		this.plotElement = new amdaPlotComp.PlotElementPanel({flex: 3});

		this.plotTabs = new amdaPlotComp.PlotTabPanel({flex: 2, plotElementPanel : this.plotElement, plotUI : this});
		
		this.optionsPanel = new Ext.form.Panel({
			layout: {
			    type: 'vbox',
			    pack: 'start',
			    align: 'stretch'
			},
			bodyStyle: { background : '#dfe8f6' },  
			defaults: {
				border: false
			},
			items: [
			        this.plotElement,
			        this.plotOutput
			]
		});
		
		this.multiPlotIntervalPanel = new Ext.form.Panel({
			layout: 'fit',
			bodyStyle: { background : '#dfe8f6' },
			visible : false,
			defaults: {
				border: false
			},
			items : [
			         this.timeSelector
			]
		});
		
		this.formPanel = new Ext.form.Panel({
			region: 'center',
			layout: {
			    type: 'hbox',
			    pack: 'start',
			    align: 'stretch'
			},
			bodyStyle: { background : '#dfe8f6' },  
			defaults: {
				border: false
			},
			items: [
			        {
						xtype : 'panel',
						layout: {
						    type: 'vbox',
						    pack: 'start',
						    align: 'stretch'
						},
						bodyStyle: { background : '#dfe8f6' },
						defaults: {
							border: false
						},
						flex: 1,
						items: [
	        				this.plotTabs,
	        				this.multiPlotIntervalPanel
	        			]
					},
			        {
			        	xtype : 'panel',
			        	layout: 'fit',
			        	bodyStyle: { background : '#dfe8f6' },  
			        	defaults: {
							border: false
						},
			        	flex: 1,
			        	items: [
			        	        this.optionsPanel
			            ]
			        }
			],
			fbar: [
			       {
			    	   xtype: 'button',
			    	   text: 'Plot',
			    	   scope: this,
			    	   handler: function(button) {
			    		   this.doPlot();
			    	   }
			       },
			       ' ',
			       {
			    	   xtype: 'button',
			    	   text: 'Get Data',
			    	   scope: this,
			    	   handler: function(button) {
			    		   this.getDataProcess();
			    	   }
			       },
			       ' ',
			       {
			    	   xtype: 'button',
			    	   text: 'Reset',
			    	   scope: this,
			    	   handler: function(button) {
			    		   this.resetProcess();
			    	   }
			       },
			       '->',
			       {
			    	   xtype: 'button',
			    	   text: 'Save Request',
			    	   scope: this,
			    	   handler: function(button) {
			    		   this.saveProcess();
			    	   }
			       }
			]
		});
		
		var myConf = {
				layout: 'border',
				items: [
				        this.formPanel,
				        {
				        	xtype: 'panel', 
				        	region: 'south',
				        	title: 'Information',
				        	collapsible: true,
				        	height: 100,
				        	autoHide: false,
				        	bodyStyle: 'padding:5px',
				        	iconCls: 'icon-information',
				        	loader: {
				        		autoLoad: true,
				        		url: helpDir+'plotHOWTO'
				        	}
				        }
	            ]
		};
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
});