AliasNode.js
4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
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
/**
* 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 $
*/
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);
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);
}
});