PlotModule.js 8.26 KB
/** 
 * Project   : AMDA-NG
 * Name      : PlotModule.js
 * @class    amdaDesktop.PlotModule
 * @extends  amdaDesktop.InteractiveModule
 * @brief    Plot Module controller definition 
 * @author   Caroline DARMON
 * $Id: PlotModule.js 2152 2014-02-28 16:32:22Z elena $
 */

Ext.define('amdaDesktop.PlotModule', {
    
    extend: 'amdaDesktop.InteractiveModule',
    
    requires: [
         'amdaUI.TabPlotUI' 
    ],
    
    contentId : 'tabPlotUI',
    linkedNode : null,
    //array of linked nodes (TabPanel!!!)	
    linkedNodes : null,
    
        
    /**
    * @cfg {String} data models
    * @required
    */
    nodeDataModel : 'amdaModel.PlotNode',
    
    /**
     * @cfg {String} window definitions
     * @required
     */
    height:   680,
    width:     850,
    uiType :    'tabPlot',
    helpTitle : 'Help on Plot Module',    

    /**
    * Window Creation method of the Module
    */
    createWindow : function () {
        // init Result Win 	   
        var win = myDesktopApp.desktop.getWindow(this.id); 
	    
        if (!win) 
        {	       
            win = myDesktopApp.desktop.createWindow({
                            id : this.id,
                            title : this.title,
                            width : this.width,
                            //	minWidth : this.width,
                            height : this.height,
                            minHeight: this.height,
                            iconCls : this.icon,
                            border : false,
                            constrainHeader : true,
                            layout : 'fit',
                            stateful : true,
                            stateId  : this.id,
                            stateEvents: ['move','show','resize'],
                            tools: [
                                {
                                    type:'help',
                                    qtip: this.helpTitle,			        	                                          
                                    scope:this,
                                    handler: function(event, toolEl, panel){
                                    	var me = this;
                                        myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function (module) {
                                        	module.createWindow('plotStart', me.helpTitle);
                                        });                                         
                                    }  					  				  
                                    }			        
                            ],
                                items : [ 
                                    {
                                            xtype :  this.uiType,									    
                                            id : this.contentId
                                    }	
                                ]
                        });
                        this.closed = false;
                        win.on({
                                scope: this,
                                activate: function(){
                                    // order to pin this Module with WsExplorer
                                    this.pin();
                                },
                                show: function(){
                                    var multiMgrWin = myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.interactive_plot.id);
                                
                                    if (!multiMgrWin) {
                                        myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interactive_plot.id, true, function (module) {
                                        	module.createWindow();   
                                        	module.win.show();
                                        });
                                    }
                                    
                                },
                                // on window closing event
                                beforeclose: function(){	
                                    
                                        this.saveState(); 
                                        
                                        var isDirty = win.down('form').getForm().isDirty();
                                        if (!this.closed && isDirty) {
                                        Ext.Msg.confirm('Close', 'Current window has been modified.\nDo you want to close the window ?' , function (btn, text){  
                                            if (btn == 'yes'){ 
                                                // mark this.closed as true before the call to close() as that will fire the beforeclose event again
                                                this.closed = true; 
                                                win.close();
                                            } 
                                            },this); 
                                            } else if (!isDirty) {
                                                    this.closed = true;
                                            }
                                        if (this.closed) {
                                                // close Interactive Plot Mgr Window if exists
                                            var multiMgrWin = myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.interactive_plot.id);
                                            if (multiMgrWin) multiMgrWin.close();
                                            if (this.linkedNodes) this.linkedNodes.clear();  
                                            this.linkedNode.set('object','');
                                            // unlink Node
                                            this.setLinkedNode(null);  
                                            this.unpin();
                                        } 
                                // Don't automatically close if the form is dirty, let the call to this.close() within the confirm box close the window.
                                return this.closed;					    
                                }
                        }); 		  		
            } // if !win
            win.show();
            
            this.linkedNode = this.getLinkedNode();
            
            if (!this.linkedNode) {
                    this.createLinkedNode(); 
                    this.createObject(); 		  
            }
            
            var tabId = this.getUiContent().tabPanel.getActiveTab().id;	      
            var editedNode = this.getTabNode(tabId);
            if (editedNode !== this.linkedNode) {
                this.getUiContent().setObject(this.linkedNode.get('object'));
            }
            // add  linked node to the array of nodes and set object to UI (TabPlotUI)		 	   
            this.addLinkedNode(this.linkedNode, null);	    
    },	

    /**
     * add the current node in this module
     * @param {amdaModel.InteractiveNode} myLinkedNode
     */
    addLinkedNode : function (myLinkedNode, tabId)
    {
        
        if (!this.linkedNodes){
            this.linkedNodes = new Ext.util.HashMap();
        }
        //TODO link the same request node to multi tabs - or interdit???	
   
            if (!tabId) tabId = this.getUiContent().tabPanel.getActiveTab().id;		 
            this.linkedNodes.replace(tabId,myLinkedNode);	   
    },
        
    /**
     * get  active Tab linked node in Plot module
     * 
     */
    getTabNode : function (tabId)
    {        
        if (!this.linkedNodes){
            return null;
        }
        //   var tabId = this.getUiContent().tabPanel.getActiveTab().id;                  
        var linkedNode = this.linkedNodes.get(tabId);	    
        return linkedNode;
    },
         	  
    saveState: function() {
            var uiContent = this.getUiContent();               
            var form = uiContent.tabPanel.getActiveTab().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'); 
    }
    
});