SearchParamEditorPlugin.js
8.21 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**
* Project : AMDA-NG
* Name : searchParamEditorPlugin.js
* @plugin amdaUI.ParamEditorPlugin
* @extends Ext.util.Observable
* @ptype searchParamEditorPlugin
* @version $Id: SearchParamEditorPlugin.js 2850 2015-03-31 09:51:58Z elena $
*/
Ext.define('amdaUI.SearchParamEditorPlugin', {
extend: 'Ext.util.Observable',
alias: 'plugin.searchParamEditorPlugin',
requires : [
'amdaModel.ArgGroups'
],
win: null,
confCombo : { width: 100,
labelAlign: 'top',
margin: '5 10 0 0',
queryMode: 'local',
editable: false,
displayField: 'value'
},
confCombo1 : { width: 100,
labelAlign: 'top',
margin: '5 10 0 0',
queryMode: 'local',
editable: false,
displayField: 'value',
valueField: 'arg'
},
confField : { width: 100,
labelAlign: 'top',
allowDecimals : false,
hideTrigger: true,
margin : '5 10 0 0'
},
configFS : {layout:'hbox', height: 70},
confCB : {boxLabel: 'Average', margin: '5 10 0 0'},
init: function(cmp) {
this.hostCmp = cmp;
this.hostCmp.on('openParamEditor', this.onOpen, this);
},
apply: function() {
var args = this.form.getForm().getValues();
// if component - insert before brackets
var bracketPos = this.paramId.indexOf("(");
if (bracketPos > 0) {
if (args.argMax)
this.hostCmp.addParam(Ext.String.insert(this.paramId, '_' +args.argMin +'_'+args.argMax, bracketPos), true);
else
this.hostCmp.addParam(Ext.String.insert(this.paramId, '_' +args.argMin, bracketPos), true);
}
else { // TODO check number of args ; here 2 maximum
if (args.argMax) {
this.hostCmp.addParam(this.paramId + '_' +args.argMin +'_'+args.argMax, true);
}
else {
if (args.argMin == 'all') {
alert('Select channel, pls : ALL not implemeted yet');
return false;
}
// string value
if (isNaN(args.argMin)) {
this.hostCmp.addParam(this.paramId + '_' +args.argMin, true);
}
// Energy channel
else {
arg = args.argMin - 1;
//TODO this is temporary!!!
if (this.paramId.substr(this.paramId.length-2, 2) == '_E') this.paramId = this.paramId.substr(0,this.paramId.length-2);
this.hostCmp.addParam(this.paramId + '(' +arg + ')', true);
}
}
}
this.win.close();
},
reset: function() {
this.form.getForm().reset();
},
onOpen: function(id) {
if (this.win) this.win.close();
this.paramId = id;
this.win = new Ext.Window({
id: 'searchparameditor-win',
width: 280,
height: 150,
x: 0, y: 0,
baseCls:'x-panel',
title: 'Select Arguments for ' + this.paramId,
layout: 'fit',
constrain: true,
ghost: false,
renderTo: this.hostCmp.ownerCt.getId(),
items: this.getFormConfig(),
listeners: {
scope: this,
beforeclose: function(){
Ext.PluginManager.unregister(this);
}
},
getConstrainVector: function(constrainTo){
var me = this;
if (me.constrain || me.constrainHeader) {
constrainTo = constrainTo || (me.floatParent && me.floatParent.getTargetEl()) || me.container || me.el.getScopeParent();
return (me.constrainHeader ? me.header.el : me.el).getConstrainVector(constrainTo);
}
}
});
// this.hostCmp.ownerCt.add(this.win);
this.win.show()
Ext.PluginManager.register(this);
this.win.setPosition(0,0);
},
getFormConfig: function(){
this.form = new Ext.form.Panel( {
frame: true, buttonAlign: 'left', autoScroll: true,
layout: { type: 'vbox', align : 'stretch', autoSize: true},
fbar: [
{
text: 'Apply',
scope : this,
handler: this.apply
},
{
text: 'Reset',
scope : this,
handler: this.reset
}
]
});
// Get parameter arguments from Server
var argStore = Ext.create('Ext.data.Store',{model: 'amdaModel.ArgGroups'});
//is sent to server to find parameter XML description
argStore.getProxy().extraParams.paramID = this.paramId;
argStore.getProxy().extraParams.application = 'search';
argStore.load({
scope : this,
callback: function(records, operation, success) {
if (success && records[0].get('group') != 'nok') {
this.simpleGroup = false;
argStore.each(function(grp){
var isMulti = false;
var args = grp.args();
var units = grp.get('units');
if (grp.get('groupE') || grp.get('groupEmulti')) {
var argsN = args.count();
var argMin = args.first();
var argMax = args.getAt(argsN-1);
var title = grp.get('groupE') || grp.get('groupEmulti');
if (grp.get('groupEmulti')) isMulti = true;
var fieldset = new Ext.form.FieldSet(this.configFS);
var suffix = 'Min';
var argValue = argMin;
for (var i = 0; i < 2; i++) {
var label = title + suffix;
var fieldlabel = label + ' ' +units;
var name = 'arg' + suffix;
if (isMulti){
var config = {name: name, fieldLabel: fieldlabel, minValue: argMin.get('value'), maxValue: argMax.get('value'), value: argValue.get('value')};
Ext.applyIf(config, this.confField);
var combo = new Ext.form.field.Number(config);
}
else {
var config = {name: name, fieldLabel: fieldlabel, store: args, value: argValue};
Ext.applyIf(config, this.confCombo);
var combo = new Ext.form.field.ComboBox(config);
}
fieldset.add(combo);
var suffix = 'Max';
argValue = argMax;
}
// average checkbox
// var config = {name: title + 'CB'};
// Ext.applyIf(config, this.confCB);
// var checkBox = new Ext.form.field.Checkbox(config);
// fieldset.add(checkBox);
this.form.add(fieldset);
}
else {
var title = grp.get('group');
var suffix = this.simpleGroup ? 'Max' : 'Min';
if (title) {
var name = 'arg' + suffix;
title += ' ' + units;
var config = {name: name, fieldLabel: title, store: args, value: args.first()};
if (grp.get('group') == 'ClockAngle') {
Ext.applyIf(config, this.confField);
var newField = new Ext.form.field.Number(config);
}
else {
Ext.applyIf(config, this.confCombo1);
var newField = new Ext.form.field.ComboBox(config);
}
if (!this.simpleGroup) this.fieldsetSimple = new Ext.form.FieldSet(this.configFS);
this.simpleGroup = true;
this.fieldsetSimple.add(newField);
}
}
}, this);
if (this.simpleGroup) this.form.add(this.fieldsetSimple);
}
else {
//TODO process errors
}
}
});
return this.form;
}
});