Blame view

js/app/models/AliasNode.js 4.16 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
    
05ebfb1e   Elena.Budnik   alias, first commit
21
22
23
24
	constructor : function(config) {
		this.callParent(arguments);     
		if (this.get('leaf')) this.set('iconCls', 'icon-scalar');
	},
16035364   Benjamin Renard   First commit
25
    
05ebfb1e   Elena.Budnik   alias, first commit
26
27
28
29
30
31
32
33
34
35
36
37
38
39
	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   	
		}];
16035364   Benjamin Renard   First commit
40

05ebfb1e   Elena.Budnik   alias, first commit
41
42
		return menuItems;
	}, 
d18b535d   elena   catalog draft + c...
43
       
05ebfb1e   Elena.Budnik   alias, first commit
44
45
46
47
48
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
	create: function(alias, param, component_info) {
		//if (!Ext.Object.isEmpty(component_info))) 
		AmdaAction.createObject({ name: alias, param: param, component_info : component_info,
			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);
							this.set('component_info',component_info);
						}
					} 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); 
16035364   Benjamin Renard   First commit
76
	},
16035364   Benjamin Renard   First commit
77
	
05ebfb1e   Elena.Budnik   alias, first commit
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
	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);
						
16035364   Benjamin Renard   First commit
129
		var paramNode = rootNode.findChild('id', this.get('id').substr(6),true);
05ebfb1e   Elena.Budnik   alias, first commit
130
131
132
133
134
135
136
137
				
		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);
	}   
16035364   Benjamin Renard   First commit
138
});