ParamEditorPlugin.js
13.1 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/**
* Project : AMDA-NG
* Name : ParamEditorPlugin.js
* @plugin amdaUI.ParamEditorPlugin
* @extends Ext.util.Observable
* @ptype paramEditorPlugin
* @brief
* @author
* @version $Id: ParamEditorPlugin.js 2259 2014-04-02 12:22:26Z elena $
********************************************************************************
* FT Id : Date : Name - Description
*******************************************************************************
* :
*/
Ext.define('amdaUI.ParamEditorPlugin', {
extend: 'Ext.AbstractPlugin',
alias: 'plugin.paramEditorPlugin',
requires : [
'amdaModel.ArgGroups'
],
titles: null,
y2axe: null,
win: null,
// calculate number of fieldsets added - to avoid rendering problem
fieldsetNumber: 0,
height : 150,
confCombo : { width: 150,
labelAlign: 'top',
margin: '5 10 0 0',
queryMode: 'local',
editable: false,
displayField: 'value'
},
confField : { width: 150,
labelAlign: 'top',
allowDecimals : false,
hideTrigger: true,
margin : '5 10 0 0'
},
configFS : {layout:'column'},
init: function(cmp) {
this.hostCmp = cmp;
this.hostCmp.on('openParamEditor', this.onOpen, this);
if (!this.titles) {
this.titles = new Ext.util.MixedCollection();
this.titles.addAll([{ name: 'xTitle', label: 'X Title' },
{ name: 'yTitle', label: 'Y Title' }]);
}
if (!this.y2axe) {
this.y2axe = new Ext.util.MixedCollection();
this.y2axe.addAll([{ xtype: 'textfield', name: 'y2Title', label: 'Y2 Title'},
{ xtype: 'numberfield', name: 'y2RangeMin', label: 'Y2min'},
{ xtype: 'numberfield', name: 'y2RangeMax', label: 'Y2max'}]);
}
},
apply: function() {
var args = this.form.getForm().getValues(this.record.isLeaf());
if (this.record.isLeaf()) {
//arguments for some special parameters
if (this.record.get('needsArgs')) {
var argsDownload = this.form.getForm().getValues();
this.record.set('downloadParamArgs',argsDownload);
}
this.record.set('paramArgs',args);
}
else {
var panelArgs = '';
if(args.xTitle) {
this.record.set('xTitle', args.xTitle);
panelArgs += 'Xtitle';
}
if(args.yTitle) {
this.record.set('y1Title', args.yTitle);
panelArgs += ' Ytitle';
}
this.record.set('panelArgs', panelArgs);
}
this.win.close();
},
reset: function() {
this.form.getForm().reset();
},
onOpen: function(record) {
var str = record.get('paramArgs');
if ( str && str !== 'select...')
{
this.values = [];
var arr = str.split('&');
if (arr.length > 1)
{
this.values = [];
Ext.each(arr, function(item)
{
var obj = item.split('=');
this.values.push({ id : obj[0], value: obj[1] });
}, this);
}
else
{
var obj = str.split('=');
this.values.push({id : obj[0], value: obj[1]});
}
}
if ( str && str == 'select...')
this.values = null;
if (this.win)
this.win.close();
this.record = record;
//
this.paramId = record.get('name');
this.getFormConfig(record.isLeaf(), function(items)
{
this.win = new Ext.Window({
id: 'parameditor-win-'+this.hostCmp.id,
width: 550,
height: this.height,
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: items,
listeners: {
scope: this,
beforeclose: function(){
Ext.PluginManager.unregister(this);
},
show: function(){
if (this.values) {
//TODO defer - if not - values are not set - which event to use?
//Ext.Function.defer(function(){
this.form.getForm().setValues(this.values);
//}, 500, this);
}
this.form.doLayout();
}
},
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);
}
}
});
if (this.fieldsetNumber > 0) {
if (this.fieldsetNumber > 1) this.win.setHeight(this.height * this.fieldsetNumber);
this.win.show();
Ext.PluginManager.register(this);
this.fieldsetNumber = 0;
} else {
myDesktopApp.infoMsg("This parameter has no arguments");
this.values = null;
}
});
},
loadArgsStore: function(items,successfn)
{
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 = 'plot';
argStore.load({
scope : this,
callback: function(records, operation, success) {
if (success && records[0].get('group') != 'nok') {
this.simpleGroup = false;
this.settingGroup = false;
argStore.each(function(grp){
var args = grp.args();
var units = grp.get('units');
if (grp.get('groupE') || grp.get('groupEmulti')) {
var fieldsetSpectro = new Ext.form.FieldSet({ layout:'hbox', height: 25 });
//plot type radio group
var radioGroup = new Ext.form.RadioGroup({ layout : 'hbox',
items: [
{boxLabel: 'Spectrogram', name: 'plot', inputValue: 'spectro', checked: true,
listeners: {
scope : this,
change: function (cb, nv, ov) {
if (nv == ov) return;
var fs = Ext.getCmp('energyFieldSet');
if (nv)
fs.disable();
else
fs.enable();
}
}
},
{boxLabel: 'Time Serie', name: 'plot', inputValue: 'serie', margin : '0 0 0 20' }
]});
fieldsetSpectro.add(radioGroup);
var isMulti = false;
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({layout:'hbox', height: 70, id : 'energyFieldSet'});
var suffix = 'Min';
var argValue = argMin;
for (var i = 0; i < 2; i++) {
var label = title + suffix;
var fieldlabel = label + ' ' +units;
if (isMulti){
var config = {name: label, fieldLabel: fieldlabel, minValue: argValue, maxValue: argMax, value: argValue.get('value')};
Ext.applyIf(config, this.confField);
var combo = new Ext.form.field.Number(config);
}
else {
var config = {name: label, fieldLabel: fieldlabel, store: args, value: argValue};
this.confCombo.valueField = 'value';
Ext.applyIf(config, this.confCombo);
var combo = new Ext.form.field.ComboBox(config);
}
fieldset.add(combo);
var suffix = 'Max';
argValue = argMax;
}
fieldset.disable();
this.form.add(fieldsetSpectro);
this.fieldsetNumber++;
this.form.add(fieldset);
}
else
{
var title = grp.get('group') || grp.get('groupS');
if (title)
{
if (units)
label = title + ' ' + units;
else
label = title;
var argsN = args.count();
var argMin = args.first();
if (argsN > 1)
{
//combo
var config =
{
name : title,
fieldLabel : label,
displayField : 'value',
valueField : 'arg',
store : args,
value : args.first().get('arg')
};
Ext.applyIf(config, this.confCombo);
var newField = new Ext.form.field.ComboBox(config);
}
else if (argMin && argMin.get('value'))
{
var config = {name: title, fieldLabel: label, value: argMin.get('value')};
Ext.applyIf(config, this.confField);
//text
if (isNaN(parseInt(argMin.get('value')))) {
var newField = new Ext.form.field.Text(config);
newField.setReadOnly(true);
}
//number
else
var newField = new Ext.form.field.Number(config);
}
else
return;
if (grp.get('group'))
{
if (!this.simpleGroup)
this.fieldsetSimple = new Ext.form.FieldSet(this.configFS);
this.simpleGroup = true;
this.fieldsetSimple.add(newField);
}
else
{
if (!this.settingGroup)
this.fieldsetSetting = new Ext.form.FieldSet(this.configFS);
this.settingGroup = true;
this.fieldsetSetting.add(newField);
}
}
}
}, this);
this.fieldsetNumber++;
if (this.simpleGroup) this.form.add(this.fieldsetSimple);
if (this.settingGroup) this.form.add(this.fieldsetSetting);
if (successfn)
successfn.call(this,items);
}
else {
myDesktopApp.errorMsg("Cannot load parameter arguments!");
}
}
});
},
getFormConfig: function(isParam,successfn){
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
if (isParam)
this.loadArgsStore(this.form,successfn);
// Additional Panel arguments
else {
var fieldset = new Ext.form.FieldSet(this.configFS);
var isDisabled, value;
var plotType = this.record.get('plotType');
this.titles.each(function(item){
isDisabled = (plotType == 'TIME' && item['label'] == 'X Title');
value = isDisabled ? 'Time' : this.record.get(item['name']);
var textField = new Ext.form.field.Text({
width: 150,
labelAlign: 'top',
margin: '5 10 0 0',
name: item['name'],
value: value,
disabled: isDisabled,
fieldLabel: item['label']
});
fieldset.add(textField);
}, this);
this.fieldsetNumber++;
this.form.add(fieldset);
var y2disable = this.record.childNodes.length == 1;
var fieldsetY = new Ext.form.FieldSet(this.configFS);
this.y2axe.each(function(item){
var textField = new Ext.form.field.Text({
width: 100,
labelAlign: 'top',
margin: '5 10 0 0',
name: item['name'],
fieldLabel: item['label'],
disabled: y2disable
});
fieldsetY.add(textField);
}, this);
this.fieldsetNumber++;
this.form.add(fieldsetY);
if (successfn)
successfn.call(this,this.form);
}
return this.form;
}
});