AliasUI.js
5.78 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/**
* Project : AMDA-NG
* Name : AliasUI.js
* @class amdaUI.AliasUI
* @extends Ext.form.FieldSet
* @brief Alias UI definition (View)
* @author Myriam
* @version $Id: AliasUI.js 966 2012-07-03 14:50:05Z elena $
********************************************************************************
* FT Id : Date : Name - Description
*******************************************************************************
* 08/06/2011: Myriam - Migration extjs4
*/
Ext.define('amdaUI.AliasUI',{
extend: 'Ext.form.Panel',
alias: 'widget.alias',
/**
* @cfg {String} data models
* @required
*/
nodeDataModel : 'amdaModel.AliasNode',
setAlias : function(obj) {
var paramValue = obj ? obj.get('id') : null;
var aliasValue = obj && obj.get('alias') ? obj.get('alias') : null;
this.parameterField.setValue(paramValue);
this.aliasField.setValue(aliasValue);
},
setAliasJson : function(obj) {
var paramValue = obj ? obj.id : null;
var aliasValue = obj && obj.alias ? obj.alias : null;
this.parameterField.setValue(paramValue);
this.aliasField.setValue(aliasValue);
},
setLinkedNode : function (myLinkedNode){
this.linkedNode = myLinkedNode;
},
setParamNode : function (paramNode){
this.paramNode = paramNode;
if (this.paramNode.get('alias') && amdaModel.AliasNode.deletedAliases) {
this.checkDeleted(this.paramNode.get('id'));
}
},
// check if alias was deleted in this session => set param alias == null
checkDeleted : function(paramId) {
var itemIndex = -1;
Ext.Array.each(amdaModel.AliasNode.deletedAliases,
function(name, index, item) {
if (name === paramId) {
itemIndex = index;
return false;
}
}
);
if (itemIndex >= 0) {
Ext.Array.erase(amdaModel.AliasNode.deletedAliases, itemIndex, 1);
}
},
createLinkedNode : function (){
var newNode = Ext.create(this.nodeDataModel, {
leaf : true,
contextNode : this.contextNode
});
this.setLinkedNode(newNode);
},
validate : function(alias,param) {
var aliasNodeByName = this.linkedNode.get('rootNode').findChild('text', alias);
if (aliasNodeByName) {
//TODO process
var paramId = aliasNodeByName.get('id').substr(6);
Ext.Msg.alert('Alias','Alias '+ alias +' already exists for parameter\n' + paramId);
return false;
}
return true;
},
updateConstruct : function(oldval,newval) {
Ext.Array.each(myDesktopApp.paramModulesID, function(id){
var targetModule = myDesktopApp.getLoadedModule(id);
if (targetModule)
targetModule.getUiContent().updateConstruct(oldval,newval);
});
},
saveAlias: function() {
if (this.parameterField.value.match(/[a-z,0-9]/gi) == null) {
Ext.Msg.show({title:'No Parameter', msg: 'Please select parameter to create alias for',
icon: Ext.Msg.WARNING, buttons: Ext.Msg.OK});
return;
}
var tree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
var rootNode = tree.getRootNode().findChild('id','alias-treeRootNode',true);
if (!rootNode.isExpanded()) rootNode.expand(false);
if (!this.paramNode.get('alias')) {
this.createLinkedNode();
var isNew = true;
}
else {
var aliasNode = rootNode.findChild('text', this.paramNode.get('alias'));
if (!aliasNode) {//TODO error
alert('NOT FOUND');
}
this.setLinkedNode(aliasNode);
var isNew = false;
}
this.linkedNode.set('rootNode', rootNode);
var alias = this.aliasField.value;
var param = this.parameterField.value;
// now validation
if (this.validate(alias,param)) {
if (isNew) {
if (alias.match(/[a-z,0-9]/gi) == null) {
Ext.Msg.show({title:'No Alias', msg: 'No alias was created for parameter '+ param,
icon: Ext.Msg.WARNING, buttons: Ext.Msg.OK});
}
else {
// create alias
this.linkedNode.create(alias, param);
this.updateConstruct(param,"#"+alias);
}
}
else if (alias.match(/[a-z,0-9]/gi) == null) {
var alias = this.paramNode.get('alias');
Ext.Msg.confirm('Delete', 'Are you sure you want to delete this alias ?', function(btn, text){
if (btn == 'yes'){
// remove alias
this.updateConstruct("#"+alias,param);
this.linkedNode.deleteNode();
}
},this);
}
else {
// rename alias
this.linkedNode.renameNode(this.paramNode.get('alias'),alias, param);
this.updateConstruct("#"+this.paramNode.get('alias'),"#"+alias);
}
// Delete alias from array of deleted aliases
this.checkDeleted(this.paramNode.get('id'));
this.paramNode.set('alias',alias);
}
var win = myDesktopApp.getDesktop().getWindow('alias-win');
if (win) win.close();
},
initComponent : function (){
if (this.initialConfig.paramNode)
this.setParamNode(this.initialConfig.paramNode);
this.parameterField = new Ext.form.field.Text({
fieldLabel: 'AMDA Parameter', name:'param', labelAlign: 'top',
disabled: true, width : '90%', padding : '10px 0 0 10px', allowBlank: false
});
this.aliasField = new Ext.form.field.Text({
fieldLabel: 'Your Alias', padding : '10px 0 0 10px', width : '90%',
labelWidth: 70, allowBlank: false
});
this.setAlias(this.paramNode);
var config = {
defaultType: 'textfield',
bodyStyle: 'background:#ddecfe;',
items: [
this.parameterField,
this.aliasField
],
fbar: [
{
text: 'Save Alias',
scope: this,
handler: this.saveAlias
}
]
};
Ext.apply (this , Ext.apply(this.initialConfig, config));
this.callParent(arguments);
}
});