AliasNode.js 5.05 KB
/** 
 * Project  : AMDA-NG4
 * Name     : AliasNode.js
 * @class   amdaModel.AliasNode
 * @extends amdaModel.ExecutableNode
 * @brief   Basic Model of Node corresponding to an alias
 * @author  Myriam
 * @version $Id: AliasNode.js 2615 2014-10-23 15:03:48Z myriam $
 * @todo
 *******************************************************************************
 *    FT Id     :   Date   : Name - Description
 *******************************************************************************
 *  :           :14/10/2011: Myriam  - file creation
 */

Ext.define('amdaModel.AliasNode', {

    extend: 'amdaModel.InteractiveNode',
   
    statics: {
        nodeType: 'alias',
        objectName: 'Alias',
	deletedAliases : null
    },
    
   fields: [
	    {name: 'isScatter', type: 'boolean', defaultValue: true}
	    ], 
  
    constructor : function(config){

        this.callParent(arguments);
        this.set('ownerTreeId',amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
        this.set('nodeType',amdaModel.AliasNode.nodeType);
        if (this.get('leaf')) this.set('iconCls', 'icon-scalar');
    },
    
    allMenuItems : function() {
        var menuItems =
         [{
            fnId : 'leaf-deleteNode',
            text : 'Delete Alias'
         },{
             fnId : 'leaf-plotParam',
             text : 'Plot Parameter',
             hidden : true
         }, {
             fnId : 'leaf-downParam',
             text : 'Download Parameter',
             hidden : true   	
        }];

        return menuItems;
    }, 
       
    
    create: function(alias, param) {
	      AmdaAction.createObject({name: alias, param: param, 
				       nodeType:amdaModel.AliasNode.nodeType, leaf:true}, null, 
					    function(result, e){	  
					      var t = e.getTransaction();
					      if (e.status) {	
						      // SUCCESS 
						      if (result && !result.error) {
							      if ( result  == "OK" ) {
								      Ext.Msg.alert('Complete', 'New alias '+ alias +' has been created');
								      // set text of this node								   
								      this.set('text', alias);	
								      //TODO id from server
								      this.set('id', 'alias_' + param);				            	                
								      // create node in tree as child of contextNode      
								      this.get('rootNode').appendChild(this);											
								      // set the tooltip
				                      this.set('info',param);
							      }
						      } else {
							      // EXCEPTION : 
							      alert(t.action + "." + t.method + " : " + e.message);
						      }
					      }
					      else
					      {
						// FAILURE
						Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
					      }   
					},this); 
	},
	   
     renameNode: function(old_alias,alias, param) {
	     AmdaAction.renameObject({id : param, old_name: old_alias, name: alias,  
	    	 			parent : this.parentNode.get('id'), leaf: this.isLeaf(), nodeType: this.get('nodeType')},
	    	 			function(result, e){	  
						      var t = e.getTransaction();
						      if (e.status) {	
							      // SUCCESS 
							      if (result && !result.error) {
								      if ( result.id ) {
									      Ext.Msg.alert('Complete', 'Alias '+ alias +' has been renamed');
									      // set text of this node								   
									      this.set('text', alias);	
									      //TODO id from server
									      this.set('id', 'alias_' + param);				            	                
									      // create node in tree as child of contextNode      
									      this.get('rootNode').appendChild(this);											
								      
								      }
							      } else {
								      // EXCEPTION : 
								      alert(t.action + "." + t.method + " : " + e.message);
							      }
						      }
						      else
						      {
							// FAILURE
							Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
						      }   
						},this); 	    		 
     },
     
      deleteNode: function() {
	this.callParent();
//temporary array to keep deleted aliases during this session	
	if (!amdaModel.AliasNode.deletedAliases) { 
	      amdaModel.AliasNode.deletedAliases = new Array();
	}  
	amdaModel.AliasNode.deletedAliases.push(this.get('id').substr(6));
	
	// Replace alias by parameter name in active window
	Ext.Array.each(myDesktopApp.paramModulesID, function(id){
		var module = myDesktopApp.getLoadedModule(id);
		if (module) {
			module.getUiContent().updateConstruct("#"+this.get('text'),this.get('id').substr(6));
		 }
	}, this);		
	 	 	
      // Reset alias of parameter in local data tree or in remote data tree
	var tree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
	var rootNode = tree.getRootNode().findChild('id','myLocalData-treeRootNode',true);
      		   
	var paramNode = rootNode.findChild('id', this.get('id').substr(6),true);
			
	if (paramNode == null) {
		var rootNode = tree.getRootNode().findChild('id','myRemoteData-treeRootNode',true);       	
		var paramNode = rootNode.findChild('id', this.get('id').substr(6),true);
	}	 
	if (paramNode) paramNode.set('alias',null);
      }   
});