Blame view

js/app/models/AliasNode.js 4.65 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
/** 
 * 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 $
16035364   Benjamin Renard   First commit
9
10
11
12
 */

Ext.define('amdaModel.AliasNode', {

3a5f60a1   elena   proper use os sta...
13
14
15
16
17
18
19
	extend: 'amdaModel.InteractiveNode',

	statics: {
		nodeType: 'alias',
		objectName: 'Alias',
		deletedAliases : null
	},
16035364   Benjamin Renard   First commit
20
21
22
23
24
    
   fields: [
	    {name: 'isScatter', type: 'boolean', defaultValue: true}
	    ], 
  
3a5f60a1   elena   proper use os sta...
25
26
27
    constructor : function(config)
    {
        this.callParent(arguments);     
16035364   Benjamin Renard   First commit
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
        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;
    }, 
d18b535d   elena   catalog draft + c...
48
       
16035364   Benjamin Renard   First commit
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
    
    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);
      }   
});