InteractivePlotMgr.js 10.6 KB

/** 
 * Project   : AMDA-NG
 * Name      : InteractivePlotMgr.js
 * @class    amdaDesktop.ResultModule
 * @extends  amdaDesktop.InteractiveModule
 * @brief    Result Module controller definition 
 * @author   
 * @version $Id: InteractivePlotMgr.js 1875 2013-11-22 15:02:50Z elena $
 *****************************************************************************
 *    FT Id     :   Date   : Name - Description
 *******************************************************************************
 *  			 
 */

Ext.define('amdaDesktop.InteractivePlotMgr', {
        extend: 'amdaDesktop.InteractiveModule',
  
        requires: [
                    'amdaUI.InteractivePlotUI',
                    'amdaUI.PlotTabResultUI'
        ],
    
        statics: {
            multiSelector: false,            
           
            maxWinNumber : 5,
	    imgOffset : { x : 70, y : 85 },
	    winSize : {
	         landscape : { width : 0, height : 0 },
	         portrait : { width : 0, height : 0 }
	    }
        },
	
	imgSize : {
	      landscape : { width : 1052, height : 744 },
	      portrait : { width : 744, height : 1052 }
	    },
	   
 	maxWinNumber : 5,	 
 	contentId : 'InteractivePlotUI',	
    /**
     * @cfg {String} data models
     * @required
     */
	nodeDataModel :  'amdaModel.BkgJobNode',	
	windowMgr : null,
	win: null,
	
	 constructor : function(config) {
	    this.callParent(arguments);
	    if (!this.windowMgr) this.windowMgr = new Ext.AbstractManager();
	}, 
	
	init : function() {	
		//force the launcher to null to don't add this item on start menu
		this.launcher = null;
		amdaDesktop.InteractivePlotMgr.winSize.landscape.width  = this.imgSize.landscape.width + amdaDesktop.InteractivePlotMgr.imgOffset.x;
		amdaDesktop.InteractivePlotMgr.winSize.landscape.height = this.imgSize.landscape.height + amdaDesktop.InteractivePlotMgr.imgOffset.y;
		amdaDesktop.InteractivePlotMgr.winSize.portrait.width   = this.imgSize.portrait.width + amdaDesktop.InteractivePlotMgr.imgOffset.x;
		amdaDesktop.InteractivePlotMgr.winSize.portrait.height  = this.imgSize.portrait.height + amdaDesktop.InteractivePlotMgr.imgOffset.y;   
	},	
	
	computeWindowSize : function(panelResult)
	{
	    var size = panelResult.getImageSize();
	    size.width  += 30;
	    size.height += 95;
	    
	    return size;
	},
    /**
      * Window Creation method of the Module
      */
	createWindow : function () {	
	   // independent window manager to register all plot windows	        	   
		this.win = myDesktopApp.desktop.getWindow(this.id);
		 
		if (!this.win) {
			this.win = myDesktopApp.desktop.createWindow({
				id : this.id,
				title : this.title,
				width :  320,
				height : 120,
				iconCls : this.icon,
				x : 3000,
				y : 5 ,
				border : false,
				constrainHeader : true,
				layout : 'fit',
                                closable: false,
                                maximizable: false,
				tools: [
				  {
			        	type:'help',
			        	qtip: 'Help on Multi Plot',
                                        scope:this,
			        	handler: function(event, toolEl, panel){	
			        		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function (module) {
			        			module.createWindow('multiPlot', 'Help on Multi Plot');	  
			        		});             
			        	}
			         }
				],
				items : [ { xtype : 'panelPlotMgr' } ]
			});
			
			this.win.on({
				scope: this,				 
				// on window closing event
				beforeclose: function(){
				   this.windowMgr.each(function(key,win){
						   win.close();				        			      
				    });	
                                   this.linkedNode = null;
				} 
			});
		} 		 	 	  
	  
	    var linkedNode = this.getLinkedNode();	 

	    if (linkedNode) {
	    // array of nodes for reference
		this.addLinkedNode(linkedNode);	 	 	       
		this.setResult({object: linkedNode.get('object')});	   
	    }
	    
           //     this.win.show();
           //     this.win.toFront(); 
            
	},
	
       setResult: function(configResult){
 
// define window size depending on plot orientation
	    var orientation = configResult.object.get('orientation');
	     	     
            // get existing plot Result Plot Window with this resultId	    
	    var id = 'plot'+configResult.object.get('tabId');
	    var windowResultId = id + '-win';
	   	            
	    var windowResult = this.getWindowResult(windowResultId);

            // if no existing plot Tab Result Panel	 
            if (!windowResult) {	      
	      N = eval(configResult.object.get('tabId'));
	      
	      var title = 'Plot '+ configResult.object.get('tabId'); 	      
	      var panelResult = new amdaUI.PlotTabResultUI(configResult);
	    
	      var pageSize = Ext.state.Manager.getProvider().get(windowResultId+'_pagesize');
	      if (!pageSize)
	    	  pageSize = 75;
	      	      
	      var size = this.computeWindowSize(panelResult);
	     	      
	      var x = N * 50;
	      var y = 100 + N * 20;
	      var win = myDesktopApp.getDesktop().createWindow({
				id : windowResultId,
				mode : orientation,
				title : title,
				width : size.width,
				height : size.height,
				x : x,
				y : y,
				iconCls : this.icon,
				border : false,
				constrainHeader : true,
				layout : 'fit',
				items : [ 
				    panelResult 
				],  
				listeners: {
				  scope: this,				  
				  move: function(win,x,y){
				    var panel = win.items.items[0];
				    var image = panel.items.items[0];
				    panel.setImageSettings(image);
				  },				  
				  resize: function(win, w, h){
				    var panel = win.items.items[0];
				    var image = panel.items.items[0];
				    panel.setImageSettings(image);
				  },
				  beforeclose: function(win,opt){
					var linkedNodeKey = win.id;   					 
					var linkedNode = this.getLinkedNodeByKey(linkedNodeKey);					
					this.removeLinkedNode(linkedNodeKey);
					this.win.items.items[0].removePlotItem(linkedNodeKey);	
				     
					linkedNode.deleteNode();
					this.windowMgr.unregister(win);
					if (myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interactive_plot.id) != null)
						myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interactive_plot.id).multiSelector = false;					
				  },				  
				//   destroy: function(win,opt){
				// 	  if (this.windowMgr.getCount() === 0) this.win.close();
				//   }, 
				  show: function(o)
				  {
					  panelResult.setPageSize(pageSize);					 
				  }			      
			      }
		});
	      
		panelResult.on({
		      scope : this,
		      pagesize : function(win,val)
		      {
			    Ext.state.Manager.getProvider().set(windowResultId+'_pagesize',val);
		    }
		});
	      
		// register new window 	       
		this.windowMgr.register(win);				
		if (this.linkedNodes) this.win.items.items[0].addPlotItem(N-1,windowResultId);		
		win.show(); 
	     	 
            } else {	     
//update image (OUTPUTNAME!!!!) and timing   in existing Tab result Panel                 
		var linkedNode = this.getLinkedNode();
		//resize window for changed orientation	    		 
		var resultId = linkedNode.get('object').get('folderId'); 
		
	 	//var outputName = linkedNode.get('object').get('outputName');	
		var windowId =  'plot' + linkedNode.get('object').get('tabId') + '-win';
		panelResult = this.getWindowResult(windowId).items.items[0];
			
	 	//if (!outputName) {
		   var outputName = linkedNode.get('object').get('resultId');;
		   panelResult.updateObject(linkedNode.get('object'));
	 	//}
//if orientation was changed : resize window and image
		if (windowResult.mode != orientation) {	
		   var size = this.computeWindowSize(panelResult); 
		   windowResult.setSize(size.width,size.height);
		   windowResult.mode = orientation;
		   var sizeImg = Ext.clone(size);
		   var interactivePlotMgr = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interactive_plot.id);
		   if (interactivePlotMgr)
			   panelResult.panelImage.setSize(sizeImg.width-amdaDesktop.InteractivePlotMgr.imgOffset.x, 
						  sizeImg.height-amdaDesktop.InteractivePlotMgr.imgOffset.y);
		}
		   
		panelResult.panelImage.setSrc('data/'+sessionID +'/RES/'+resultId+'/'+ outputName +'.png');  		
		panelResult.currentStartTime = linkedNode.get('object').get('startDate');
		 
		var stopTime = linkedNode.get('object').get('stopDate');
		panelResult.plotDurationInSec = Ext.Date.getElapsed(panelResult.currentStartTime, stopTime) / 1000;
// reset mire and Start - Stop ONLY if Interactive Plugin is active
		 var interactivePlugin = Ext.getCmp('interactiveInter-win-'+windowResultId);
		 if (interactivePlugin) {
		  panelResult.resetMire();		    		  
		  interactivePlugin.items.getAt(0).getForm().findField('start').setValue('');
		  interactivePlugin.items.getAt(0).getForm().findField('stop').setValue('');             
		 }
				 		
		panelResult.setImageSettings(panelResult.panelImage);
		windowResult.toFront();
// if time interval => update Time in TimeSelector		
		if (configResult.object.get('timesrc')  ==  amdaModel.AmdaTimeObject.inputTimeSrc[1]) {	     
		    var timeSelector = Ext.getCmp('plotTimeSelector'+id);
		    timeSelector.cardContainer.activeItem = 1;		   
		    var intervalSelector = timeSelector.cardContainer.items[1];
		    intervalSelector.setInterval(panelResult.currentStartTime, stopTime);		  
		}
            }
//if plot for time table : set/update info            
            if (configResult.object.get('timesrc')  ==  amdaModel.AmdaTimeObject.inputTimeSrc[0]) {	     
	         panelResult.updateTimeTableInfo(configResult.object);
	    }
	    
// disable buttons if this Tab is checked in the multi plot selector
	    var resWin =  myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.interactive_plot.id);
	    if (!resWin) return;
	    var checked = resWin.items.items[0].checkBoxGroup.getChecked();	  
	    Ext.Array.each(checked, function(item, index){
		if (item.name.toLowerCase() === windowResultId){
		  panelResult.disableButtons(true);
		  return;
		}
	    });   
    },
 
     
    // getter on specific plot Tab result window
	getWindowResult: function(windowResultId){
	    if (!this.windowMgr.get(windowResultId)) return null;
	    return this.windowMgr.get(windowResultId);	    
	},

	addLinkedNode : function (myLinkedNode){
	    if (!this.linkedNodes){
	        this.linkedNodes = new Array();
	    }
	    var obj = myLinkedNode.get('object');	   
	    if (obj.get('tabId')){	     
	        // add new linkedNode to this module
	        this.linkedNodes['plot'+obj.get('tabId') + '-win'] = myLinkedNode;		 
	    }	  
	},
	
	getLinkedNodeByKey: function(linkedNodeKey){
	    if (this.linkedNodes){
	        return this.linkedNodes[linkedNodeKey];
	    } else {
	        return null;
	    }
	},
	
	removeLinkedNode: function(linkedNodeKey){
	    delete this.linkedNodes[linkedNodeKey];
	}
});