Blame view

js/app/views/ParamArgumentsUI.js 19.1 KB
7ac3ce50   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * Project   : AMDA-NG
 * Name      : ParamArgumentsUI.js
 * @class   amdaUI.ParamArgumentsUI
 * @extends Ext.container.Container
 * @brief   Parameter arguments definition (View)
 * @author  Benjamin Renard
 * @version $Id: ParamArgumentsUI.js benjamin $
 */


Ext.define('amdaUI.ParamArgumentsUI', {
	extend: 'Ext.container.Container',
	alias: 'widget.paramArguments',
	
51b7c77c   Benjamin Renard   Add templated par...
16
17
	regexp_istemplate: /^template_(.*)/,
	
bb6e93d9   Benjamin Renard   Implement templat...
18
	paramRequestObject: null,
7ac3ce50   Benjamin Renard   First implementat...
19
	onChange: null,
690e0a87   Benjamin Renard   Add sum in table ...
20
21
	onModifyHeight: null,
	pluginOwner: null,
eac92219   Benjamin Renard   Do not call onCha...
22
	inRebuild : false,
7ac3ce50   Benjamin Renard   First implementat...
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
	
	constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
	},
	
	init : function(config) {
		var myConf = {
			layout: {
				type: 'vbox',
				align: 'stretch'
			},	
		};
		
		Ext.apply (this , Ext.apply (arguments, myConf));
	},
	
bb6e93d9   Benjamin Renard   Implement templat...
40
	editParameter: function(paramRequestObject, uiScope, onReady) {
bb6e93d9   Benjamin Renard   Implement templat...
41
		this.paramRequestObject = paramRequestObject;
29dfb596   Benjamin Renard   Rework of ParamAr...
42

7ac3ce50   Benjamin Renard   First implementat...
43
		var me = this;
7bc1d734   Benjamin Renard   Fix bug in derive...
44
		me.getEl().mask();
29dfb596   Benjamin Renard   Rework of ParamAr...
45
		me.resetArguments();
0314bd32   Benjamin Renard   Keep a registry o...
46
    	
29dfb596   Benjamin Renard   Rework of ParamAr...
47
		var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
0314bd32   Benjamin Renard   Keep a registry o...
48
    	
29dfb596   Benjamin Renard   Rework of ParamAr...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
		if (explorerModule) {
			explorerModule.getParamInfo(paramRequestObject.get('paramid'), function (paramInfo) {
				if (paramInfo) {
					if (!paramRequestObject.get('is-init')) {
						if (paramInfo.data && paramInfo.data.dimensions) {
							//Init each dimensions and set parameter type (0: scalar, 1: vector or 2: Tab2D)
							paramRequestObject.set('type',0);
							if (me.initDimension('dim1', paramInfo.data)) {
								paramRequestObject.set('type',paramRequestObject.get('type')+1);
							}
							if (me.initDimension('dim2', paramInfo.data)) {
								paramRequestObject.set('type',paramRequestObject.get('type')+1);
							}
							if (paramRequestObject.get('type') == 2) {
								//Tab2D
								var dim2RelatedTable = me.getRelatedTableFromDim('dim2',paramInfo.data.tables);
								if (!dim2RelatedTable.variable) {
									paramRequestObject.set('dim2-index', 0);
								}
367b8867   Benjamin Renard   Select sum in ran...
68
69
70
								else {
									paramRequestObject.set('dim2-sum-type', 1);
								}
29dfb596   Benjamin Renard   Rework of ParamAr...
71
							}
29dfb596   Benjamin Renard   Rework of ParamAr...
72
						}
eac92219   Benjamin Renard   Do not call onCha...
73
						paramRequestObject.set('is-init', true);
29dfb596   Benjamin Renard   Rework of ParamAr...
74
75
76
					}
					me.rebuildAll(paramInfo, uiScope);
				}
bb6e93d9   Benjamin Renard   Implement templat...
77
				if (onReady)
0314bd32   Benjamin Renard   Keep a registry o...
78
					onReady(uiScope);
7bc1d734   Benjamin Renard   Fix bug in derive...
79
				me.getEl().unmask();
29dfb596   Benjamin Renard   Rework of ParamAr...
80
81
82
			});  
		}
		else
7bc1d734   Benjamin Renard   Fix bug in derive...
83
			me.getEl().unmask();
29dfb596   Benjamin Renard   Rework of ParamAr...
84
	},
dc9e2c14   Elena.Budnik   init + message + ...
85

29dfb596   Benjamin Renard   Rework of ParamAr...
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
	initDimension: function(relatedDim, data) {
		if (!data || !data.dimensions || !data.dimensions[relatedDim] || this.paramRequestObject.get('is-init')) {
			return false;
		}
		if (data.dimensions[relatedDim] && (parseInt(data.dimensions[relatedDim]) > 1)) {
			var relatedTable = this.getRelatedTableFromDim(relatedDim, data.tables);
			if (relatedTable) {
				var minmax = this.getDimensionMinMaxValues(relatedDim, data);
				if (!minmax) {
					myDesktopApp.warningMsg('Min/Max '+this.getDimensionTitle(relatedDim, data)+' values are undefined<br/>Arbitrary values are taken');
					minmax = {
						'min': 10,
						'max': 10000
					};
				}
				this.paramRequestObject.set(relatedDim+'-min-value', minmax['min']);
				this.paramRequestObject.set(relatedDim+'-max-value', minmax['max']);
				this.paramRequestObject.set(relatedDim+'-min-index', 0);
				this.paramRequestObject.set(relatedDim+'-max-index', parseInt(data.dimensions[relatedDim])-1);
			}
			return true;
		}
		return false;
	},

	getDimensionMinMaxValues: function(relatedDim, data) {
		var relatedTable = this.getRelatedTableFromDim(relatedDim, data.tables);
		if (relatedTable.variable) {
			if (Ext.Object.isEmpty(relatedTable.minmax)) {
				//Not defined
				return null;
			}
			return {
				'min': relatedTable.minmax.min,
				'max': relatedTable.minmax.max
			};
		}
		var minValue = null;
		var maxValue = null;
		Ext.Object.each(relatedTable.channels, function (argKey, argDef) {
			var crtMin = (parseFloat(argDef.min) < parseFloat(argDef.max)) ? parseFloat(argDef.min) : parseFloat(argDef.max);
			if (!minValue || minValue > crtMin) {
				minValue = crtMin;
			}
			var crtMax = (parseFloat(argDef.max) > parseFloat(argDef.min)) ? parseFloat(argDef.max) : parseFloat(argDef.min);
			if (!maxValue || maxValue < crtMax) {
				maxValue = crtMax;
			}
		});
		return {
			'min': (minValue < maxValue) ? minValue : maxValue,
			'max': (maxValue > minValue) ? maxValue : minValue
		};
	},

	getDimensionTitle: function(relatedDim, data) {
		var relatedTable = this.getRelatedTableFromDim(relatedDim, data.tables);
		var title = 'Unknown';
		if (relatedTable) {
			title = relatedTable.name;
			if (relatedTable.units != '')
				title += ' (' + relatedTable.units + ')';
		}
		else if (relatedDim == "dim1") {
			title = 'Dim. 1';
		}
		else if (relatedDim == "dim2") {
			title = 'Dim. 2';
		}
		return title;
	},
7ac3ce50   Benjamin Renard   First implementat...
157
    
29dfb596   Benjamin Renard   Rework of ParamAr...
158
	rebuildAll: function(paramInfoResult , uiScope) {
eac92219   Benjamin Renard   Do not call onCha...
159
		this.inRebuild = true;
29dfb596   Benjamin Renard   Rework of ParamAr...
160
		//Rebuild arguments selection
0314bd32   Benjamin Renard   Keep a registry o...
161
		this.rebuildArguments(paramInfoResult, uiScope);
bb6e93d9   Benjamin Renard   Implement templat...
162
163
164
165
		//Add default template args values
		var templateArgsValues = this.paramRequestObject.get('template_args');
		if (!templateArgsValues)
			templateArgsValues = {};
0cefcae2   Benjamin Renard   il reste click droit
166
		if (paramInfoResult.template && paramInfoResult.template.arguments) {                      
0314bd32   Benjamin Renard   Keep a registry o...
167
168
			//Add default template args definition if needed
			Ext.Object.each(paramInfoResult.template.arguments, function (argKey, argDef) {
bb6e93d9   Benjamin Renard   Implement templat...
169
170
				if (!templateArgsValues[argKey])
					templateArgsValues[argKey] = argDef['default'];
0314bd32   Benjamin Renard   Keep a registry o...
171
			}, this);
bb6e93d9   Benjamin Renard   Implement templat...
172
173
			
			this.paramRequestObject.set('template_args', templateArgsValues);
0314bd32   Benjamin Renard   Keep a registry o...
174
		}
bb6e93d9   Benjamin Renard   Implement templat...
175
176
177
178
		
		
		//Init values in interface
		this.items.each(function (item) {
29dfb596   Benjamin Renard   Rework of ParamAr...
179
180
181
182
			if (!item.argId)
				return;
			if (this.regexp_istemplate.test(item.argId)) {
				var arg_key = this.regexp_istemplate.exec(item.argId)[1];
bb6e93d9   Benjamin Renard   Implement templat...
183
    			
29dfb596   Benjamin Renard   Rework of ParamAr...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
				if (this.paramRequestObject.get('template_args') && this.paramRequestObject.get('template_args')[arg_key])
					item.setValue(this.paramRequestObject.get('template_args')[arg_key]);
			}
			else if (item.argId == 'dim1' || item.argId == 'dim2') {
				item.setValue(this.paramRequestObject.get(item.argId+'-index'));
				var sumInRangeField = item.up().down('[name=sum_fieldset_'+item.argId +']');
				if (sumInRangeField) {
					//Fill fields
					sumInRangeField.down('textfield[name=value_min_' + item.argId + ']').setValue(this.paramRequestObject.get(item.argId+'-min-value'));
					sumInRangeField.down('textfield[name=value_max_' + item.argId + ']').setValue(this.paramRequestObject.get(item.argId+'-max-value'));
					sumInRangeField.down('textfield[name=index_min_' + item.argId + ']').setValue(this.paramRequestObject.get(item.argId+'-min-index'));
					sumInRangeField.down('textfield[name=index_max_' + item.argId + ']').setValue(this.paramRequestObject.get(item.argId+'-max-index'));
					if (this.paramRequestObject.get(item.argId+'-sum-type') > 0) {
						sumInRangeField.expand();
					}
					else {
						sumInRangeField.collapse();
					}
690e0a87   Benjamin Renard   Add sum in table ...
202
203
204
				}
    		}
    		else
bb6e93d9   Benjamin Renard   Implement templat...
205
    			item.setValue(this.paramRequestObject.get(item.argId));
eac92219   Benjamin Renard   Do not call onCha...
206
		this.inRebuild = false;
7ac3ce50   Benjamin Renard   First implementat...
207
208
    	}, this);
    },
29dfb596   Benjamin Renard   Rework of ParamAr...
209

7ac3ce50   Benjamin Renard   First implementat...
210
    getValues: function() {
29dfb596   Benjamin Renard   Rework of ParamAr...
211
    	var values = {type : paramRequestObject.get('type')};
7ac3ce50   Benjamin Renard   First implementat...
212
    	this.items.each(function(item) {
bb6e93d9   Benjamin Renard   Implement templat...
213
    		if (!item.argId)
51b7c77c   Benjamin Renard   Add templated par...
214
    			return;
bb6e93d9   Benjamin Renard   Implement templat...
215
216
    		if (this.regexp_istemplate.test(item.argId)) {
    			var arg_key = this.regexp_istemplate.exec(item.argId)[1];
51b7c77c   Benjamin Renard   Add templated par...
217
218
219
220
221
    			if (!values['template_args'])
    				values['template_args'] = {};
    			values['template_args'][arg_key] = item.getValue();
    		}
    		else
bb6e93d9   Benjamin Renard   Implement templat...
222
    			values[item.argId] = item.getValue();
51b7c77c   Benjamin Renard   Add templated par...
223
    	}, this);
7ac3ce50   Benjamin Renard   First implementat...
224
225
226
227
228
229
    	
    	return values;
    },
    
    resetValues: function() {
    	this.items.each(function (item) {
690e0a87   Benjamin Renard   Add sum in table ...
230
231
    		if (item.reset)
    			item.reset();
7ac3ce50   Benjamin Renard   First implementat...
232
233
234
235
236
237
    	});
    },
    
    resetArguments: function(noArgsMsg) {
    	this.removeAll();
    	if (!noArgsMsg)
bb6e93d9   Benjamin Renard   Implement templat...
238
    		this.add(new Ext.form.Label({text: 'No argument for this parameter', argId: null}));
7ac3ce50   Benjamin Renard   First implementat...
239
240
    },
    
51b7c77c   Benjamin Renard   Add templated par...
241
    rebuildArguments: function(result, uiScope) {
7ac3ce50   Benjamin Renard   First implementat...
242
243
    	this.resetArguments(true);
    	
51b7c77c   Benjamin Renard   Add templated par...
244
    	if (result.data && result.data.dimensions) {
690e0a87   Benjamin Renard   Add sum in table ...
245
    		if (result.data.dimensions.dim1 && (parseInt(result.data.dimensions.dim1) > 1) || this.getRelatedTableFromDim('dim1',result.data.tables)) {
bb6e93d9   Benjamin Renard   Implement templat...
246
    			this.buildDimIndexSelection("dim1", result.data, uiScope);
7ac3ce50   Benjamin Renard   First implementat...
247
    		}
690e0a87   Benjamin Renard   Add sum in table ...
248
    		if (result.data.dimensions.dim2 && (parseInt(result.data.dimensions.dim2) > 1) || this.getRelatedTableFromDim('dim2',result.data.tables)) {
bb6e93d9   Benjamin Renard   Implement templat...
249
    			this.buildDimIndexSelection("dim2", result.data, uiScope);
7ac3ce50   Benjamin Renard   First implementat...
250
251
    		}
    	}
33ce72a7   Benjamin Renard   Do not show argum...
252
    	
51b7c77c   Benjamin Renard   Add templated par...
253
254
255
256
    	var isTemplate = (result.template && result.template.arguments);
    	if (isTemplate)
    		this.buildTemplateArguments(result.template.arguments, uiScope);
    	
29dfb596   Benjamin Renard   Rework of ParamAr...
257
    	if ((this.paramRequestObject.get('type') == 0) && !isTemplate)
33ce72a7   Benjamin Renard   Do not show argum...
258
259
    		//Add no args message
    		this.resetArguments(false);
7ac3ce50   Benjamin Renard   First implementat...
260
261
    },
    
690e0a87   Benjamin Renard   Add sum in table ...
262
263
264
265
    getRelatedTableFromDim : function(relatedDim, tables) {
    	var relatedTable = null;
		if (tables) {
			Ext.each(tables, function(table, index) {
7ac3ce50   Benjamin Renard   First implementat...
266
267
268
269
				if (table.relatedDim == relatedDim)
					relatedTable = table;
			}, this);
		}
690e0a87   Benjamin Renard   Add sum in table ...
270
271
		return relatedTable;
    },
29dfb596   Benjamin Renard   Rework of ParamAr...
272

690e0a87   Benjamin Renard   Add sum in table ...
273
    buildDimIndexSelection: function(relatedDim, data, uiScope) {
13ecb94a   Elena.Budnik   ruler for rm 8574
274
275
276
277
278
279
        var ruler = {
            xtype: 'box',
            autoEl : {
             tag : 'hr'
            }
        };
690e0a87   Benjamin Renard   Add sum in table ...
280
281
    	//Check if this dimension is attached to a table
		var relatedTable = this.getRelatedTableFromDim(relatedDim, data.tables);
1df8e90c   Benjamin Renard   Add selection for...
282
		var dimSize = data.dimensions[relatedDim];
690e0a87   Benjamin Renard   Add sum in table ...
283
		
29dfb596   Benjamin Renard   Rework of ParamAr...
284
		var title = this.getDimensionTitle(relatedDim, data);
7ac3ce50   Benjamin Renard   First implementat...
285
286
287
288
289
		
		var indexes = [];
		indexes.push({'key' : '*', 'value' : 'All'});
		
		if (relatedTable) {
690e0a87   Benjamin Renard   Add sum in table ...
290
			//If it's not a variable table => enable channel selection
690e0a87   Benjamin Renard   Add sum in table ...
291
292
293
294
			if (!relatedTable.variable)
				Ext.Object.each(relatedTable.channels, function (index, channel) {
					indexes.push({'key' : index.toString(), 'value' : index + ' : [' + channel.min + ', ' + channel.max + ']'});
				});
7ac3ce50   Benjamin Renard   First implementat...
295
296
297
		}
		else {
			//Else, use components
7ac3ce50   Benjamin Renard   First implementat...
298
			Ext.Object.each(data.components, function (index, component) {
bb6e93d9   Benjamin Renard   Implement templat...
299
				if (relatedDim == "dim1" && component.index_1 != "")
7ac3ce50   Benjamin Renard   First implementat...
300
					indexes.push({'key' : component.index_1, 'value' : index + ' : ' + component.name});
bb6e93d9   Benjamin Renard   Implement templat...
301
				else if (relatedDim == "dim2" && component.index_2 != "")
7ac3ce50   Benjamin Renard   First implementat...
302
303
304
					indexes.push({'key' : component.index_2, 'value' : index + ' : ' + component.name});
			});
		}
dc9e2c14   Elena.Budnik   init + message + ...
305

7ac3ce50   Benjamin Renard   First implementat...
306
307
308
309
310
311
		//Add combo box
		var indexesStore = Ext.create('Ext.data.Store', {
		    fields: ['key', 'value'],
		    data : indexes
		});

7ac3ce50   Benjamin Renard   First implementat...
312
313
314
315
316
317
		var indexesCombo = Ext.create('Ext.form.ComboBox', {
		    fieldLabel: title,
		    store: indexesStore,
		    queryMode: 'local',
		    displayField: 'value',
		    valueField: 'key',
dc9e2c14   Elena.Budnik   init + message + ...
318
			 value: '*',
7ac3ce50   Benjamin Renard   First implementat...
319
		    editable: false,
bb6e93d9   Benjamin Renard   Implement templat...
320
		    argId: relatedDim,
690e0a87   Benjamin Renard   Add sum in table ...
321
		    hidden: (relatedTable ? relatedTable.variable : false),
7ac3ce50   Benjamin Renard   First implementat...
322
		    listeners: {
29dfb596   Benjamin Renard   Rework of ParamAr...
323
            		change: function(field, newValue, oldValue, eOpts) {
eac92219   Benjamin Renard   Do not call onCha...
324
325
326
327
            			this.paramRequestObject.set(relatedDim+'-index', newValue); 
            			if (!this.inRebuild && (this.onChange != null))
            				this.onChange(uiScope, relatedDim, newValue, oldValue, false);
            		},
7ac3ce50   Benjamin Renard   First implementat...
328
329
330
331
332
333
            	scope: this
            }
		    
		});
		
		this.add(indexesCombo);
13ecb94a   Elena.Budnik   ruler for rm 8574
334
	
690e0a87   Benjamin Renard   Add sum in table ...
335
		if (relatedTable) {
29dfb596   Benjamin Renard   Rework of ParamAr...
336
			var sumTypes = Ext.create('Ext.data.Store', {
1df8e90c   Benjamin Renard   Add selection for...
337
338
				fields: ['type', 'name'],
				data: [
29dfb596   Benjamin Renard   Rework of ParamAr...
339
340
					{'type': 1, 'name': 'Between Values'},
					{'type': 2, 'name': 'Between Indexes'}
1df8e90c   Benjamin Renard   Add selection for...
341
342
				]
			});
29dfb596   Benjamin Renard   Rework of ParamAr...
343
			var sumItems = [
690e0a87   Benjamin Renard   Add sum in table ...
344
                {
1df8e90c   Benjamin Renard   Add selection for...
345
			xtype: 'combobox',
29dfb596   Benjamin Renard   Rework of ParamAr...
346
347
			name: 'sum_type_'+relatedDim,
			store: sumTypes,
1df8e90c   Benjamin Renard   Add selection for...
348
349
350
351
352
353
354
355
			queryMode: 'local',
			editable: false,
			displayField: 'name',
			valueField: 'type',
			fieldLabel: 'Type',
			value: 1,
			listeners: {
				change: function(field, newValue, oldValue, eOpts) {
29dfb596   Benjamin Renard   Rework of ParamAr...
356
357
358
					this.paramRequestObject.set(relatedDim+'-sum-type',newValue);
					field.up().down('[name=value_min_'+relatedDim+']').setVisible(newValue == 1);
					field.up().down('[name=value_max_'+relatedDim+']').setVisible(newValue == 1);
1df8e90c   Benjamin Renard   Add selection for...
359
360
					field.up().down('[name=index_min_'+relatedDim+']').setVisible(newValue == 2);
					field.up().down('[name=index_max_'+relatedDim+']').setVisible(newValue == 2);
eac92219   Benjamin Renard   Do not call onCha...
361
					if (!this.inRebuild && (this.onChange != null))
1df8e90c   Benjamin Renard   Add selection for...
362
363
364
365
366
367
						this.onChange(uiScope, relatedDim, newValue, oldValue, false);
				},
				scope: this
			}
                },
                {
690e0a87   Benjamin Renard   Add sum in table ...
368
                	xtype: 'numberfield',
29dfb596   Benjamin Renard   Rework of ParamAr...
369
                	name: 'value_min_'+relatedDim,
690e0a87   Benjamin Renard   Add sum in table ...
370
371
372
373
374
                	fieldLabel: 'Min.',
                	decimalPrecision : 3,
                	value: 0.,
                	listeners: {
                		change: function(field, newValue, oldValue, eOpts) {
29dfb596   Benjamin Renard   Rework of ParamAr...
375
                			this.paramRequestObject.set(relatedDim+'-min-value', newValue);
eac92219   Benjamin Renard   Do not call onCha...
376
    	            			if (!this.inRebuild && (this.onChange != null))
29dfb596   Benjamin Renard   Rework of ParamAr...
377
    	            				this.onChange(uiScope, relatedDim, newValue, oldValue, false);
690e0a87   Benjamin Renard   Add sum in table ...
378
379
380
381
382
383
                		},
                		scope: this
                	}
                },
                {
                	xtype: 'numberfield',
29dfb596   Benjamin Renard   Rework of ParamAr...
384
                	name: 'value_max_'+relatedDim,
690e0a87   Benjamin Renard   Add sum in table ...
385
386
387
388
389
                	fieldLabel: 'Max.',
                	decimalPrecision : 3,
                	value: 0.,
                	listeners: {
                		change: function(field, newValue, oldValue, eOpts) {
29dfb596   Benjamin Renard   Rework of ParamAr...
390
                			this.paramRequestObject.set(relatedDim+'-max-value', newValue);
eac92219   Benjamin Renard   Do not call onCha...
391
    	            			if (!this.inRebuild && (this.onChange != null))
29dfb596   Benjamin Renard   Rework of ParamAr...
392
    	            				this.onChange(uiScope, relatedDim, newValue, oldValue, false);
690e0a87   Benjamin Renard   Add sum in table ...
393
394
395
                		},
                		scope: this
                	}
1df8e90c   Benjamin Renard   Add selection for...
396
397
398
399
400
401
402
403
404
405
406
                },
		{
                        xtype: 'numberfield',
                        name: 'index_min_'+relatedDim,
                        fieldLabel: 'Min.',
                        allowDecimals: false,
                        value: 0,
			minValue: 0,
			hidden: true,
                        listeners: {
                                change: function(field, newValue, oldValue, eOpts) {
29dfb596   Benjamin Renard   Rework of ParamAr...
407
                                        this.paramRequestObject.set(relatedDim+'-min-index', newValue);
eac92219   Benjamin Renard   Do not call onCha...
408
                                	if (!this.inRebuild && (this.onChange != null))
29dfb596   Benjamin Renard   Rework of ParamAr...
409
                                        	this.onChange(uiScope, relatedDim, newValue, oldValue, false);
1df8e90c   Benjamin Renard   Add selection for...
410
411
412
413
414
415
416
417
418
419
420
421
422
423
                                },
                                scope: this
                        }
                },
                {
                        xtype: 'numberfield',
                        name: 'index_max_'+relatedDim,
                        fieldLabel: 'Max.',
                        allowDecimals: false,
                        value: 0,
			minValue: 0,
			hidden: true,
                        listeners: {
                                change: function(field, newValue, oldValue, eOpts) {
29dfb596   Benjamin Renard   Rework of ParamAr...
424
                                        this.paramRequestObject.set(relatedDim+'-max-index', newValue);
eac92219   Benjamin Renard   Do not call onCha...
425
                                	if (!this.inRebuild && (this.onChange != null))
29dfb596   Benjamin Renard   Rework of ParamAr...
426
                                        	this.onChange(uiScope, relatedDim, newValue, oldValue, false);
1df8e90c   Benjamin Renard   Add selection for...
427
428
429
                                },
                                scope: this
                        }
690e0a87   Benjamin Renard   Add sum in table ...
430
431
432
                }
			];
			
9a9c6ebf   Elena.Budnik   sum in variable r...
433
434
			var sumRangeFieldSet = Ext.create('Ext.form.FieldSet', {
				title: relatedTable.variable ? title + " - Sum. in range" : "Sum. in range",
690e0a87   Benjamin Renard   Add sum in table ...
435
				collapsed: true,
29dfb596   Benjamin Renard   Rework of ParamAr...
436
				checkboxName: 'sum_checkbox_'+relatedDim,
9a9c6ebf   Elena.Budnik   sum in variable r...
437
				checkboxToggle: true,
29dfb596   Benjamin Renard   Rework of ParamAr...
438
				name: 'sum_fieldset_'+relatedDim,
9a9c6ebf   Elena.Budnik   sum in variable r...
439
440
441
442
				layout: {
						type: 'vbox',
						pack: 'start',
						align: 'stretch'
690e0a87   Benjamin Renard   Add sum in table ...
443
				},
29dfb596   Benjamin Renard   Rework of ParamAr...
444
				items: sumItems,
690e0a87   Benjamin Renard   Add sum in table ...
445
				listeners: {
690e0a87   Benjamin Renard   Add sum in table ...
446
					expand: function(fieldset, eOpts) {
29dfb596   Benjamin Renard   Rework of ParamAr...
447
448
							if (this.paramRequestObject.get(relatedDim+'-sum-type') == 0) {
								this.paramRequestObject.set(relatedDim+'-sum-type',1);
925f2ce0   Elena.Budnik   error msg if sum-...
449
							}
29dfb596   Benjamin Renard   Rework of ParamAr...
450
							fieldset.down('[name=sum_type_'+relatedDim+']').setValue(this.paramRequestObject.get(relatedDim+'-sum-type'));
9a9c6ebf   Elena.Budnik   sum in variable r...
451
							indexesCombo.setDisabled(true);
eac92219   Benjamin Renard   Do not call onCha...
452
							if (!this.inRebuild && (this.onChange != null))
29dfb596   Benjamin Renard   Rework of ParamAr...
453
								this.onChange(uiScope, relatedDim, true, false, false);
9a9c6ebf   Elena.Budnik   sum in variable r...
454
							if (this.onModifyHeight)
29dfb596   Benjamin Renard   Rework of ParamAr...
455
								this.onModifyHeight(this.pluginOwner);
690e0a87   Benjamin Renard   Add sum in table ...
456
457
					},
					collapse: function(fieldset, eOpts) {
29dfb596   Benjamin Renard   Rework of ParamAr...
458
459
							indexesCombo.setDisabled(false);	
							this.paramRequestObject.set(relatedDim+'-sum-type', 0);
eac92219   Benjamin Renard   Do not call onCha...
460
							if (!this.inRebuild && (this.onChange != null))
29dfb596   Benjamin Renard   Rework of ParamAr...
461
								this.onChange(uiScope, relatedDim, false, true, false);
9a9c6ebf   Elena.Budnik   sum in variable r...
462
							if (this.onModifyHeight)
29dfb596   Benjamin Renard   Rework of ParamAr...
463
464
465
								this.onModifyHeight(this.pluginOwner);
					},
					scope: this
690e0a87   Benjamin Renard   Add sum in table ...
466
				}
9a9c6ebf   Elena.Budnik   sum in variable r...
467
			});
690e0a87   Benjamin Renard   Add sum in table ...
468
			this.add(sumRangeFieldSet);
13ecb94a   Elena.Budnik   ruler for rm 8574
469
            this.add(ruler);
690e0a87   Benjamin Renard   Add sum in table ...
470
		}
7ac3ce50   Benjamin Renard   First implementat...
471
		return indexesCombo;
9a9c6ebf   Elena.Budnik   sum in variable r...
472
	},
51b7c77c   Benjamin Renard   Add templated par...
473
474
475
476
477
478
479
    
    buildTemplateArguments: function(arguments, uiScope) {
    	var me = this;
    	Ext.Object.each(arguments, function (key, argument) {
    		switch (argument.type) {
    		case 'float' :
    			var argumentField = Ext.create('Ext.form.NumberField', {
bb6e93d9   Benjamin Renard   Implement templat...
480
    				argId: 'template_' + key,
51b7c77c   Benjamin Renard   Add templated par...
481
482
483
484
485
486
    				fieldLabel: argument.name,
    				decimalPrecision : 3,
    				allowBlank       : false,
    				value: parseFloat(argument.default),
    				listeners: {
    					change: function(field, newValue, oldValue, eOpts) {
bb6e93d9   Benjamin Renard   Implement templat...
487
488
489
490
491
    						var template_args = me.paramRequestObject.get('template_args');
    						if (!template_args)
    	            			template_args = {};
    						template_args[key] = newValue;
    						me.paramRequestObject.set('template_args', template_args);
eac92219   Benjamin Renard   Do not call onCha...
492
    						if (!this.inRebuild && (me.onChange != null))
51b7c77c   Benjamin Renard   Add templated par...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
    							me.onChange(uiScope, key, newValue, oldValue, true);
    					},
    					scope: me
    				}
                });
    			
    			me.add(argumentField);  
    			break;
    		case 'list' :
    			var items = [];
    			Ext.Object.each(argument.items, function (itemKey, itemName) {
    				items.push({'key' : itemKey, 'value' : itemName});
    			});
    			
    			var itemsStore = Ext.create('Ext.data.Store', {
    			    fields: ['key', 'value'],
    			    data : items
    			});
    			
    			var itemsCombo = Ext.create('Ext.form.ComboBox', {
    			    fieldLabel: argument.name,
    			    store: itemsStore,
    			    queryMode: 'local',
    			    displayField: 'value',
    			    valueField: 'key',
    			    value: argument.default,
    			    editable: false,
bb6e93d9   Benjamin Renard   Implement templat...
520
    				argId: 'template_' + key,
51b7c77c   Benjamin Renard   Add templated par...
521
522
    			    listeners: {
    	            	change: function(field, newValue, oldValue, eOpts) {
bb6e93d9   Benjamin Renard   Implement templat...
523
524
525
526
527
    	            		var template_args = me.paramRequestObject.get('template_args');
    	            		if (!template_args)
    	            			template_args = {};
    						template_args[key] = newValue;
    						me.paramRequestObject.set('template_args', template_args);
eac92219   Benjamin Renard   Do not call onCha...
528
    						if (!this.inRebuild && (me.onChange != null))
51b7c77c   Benjamin Renard   Add templated par...
529
530
531
532
533
534
535
536
537
    	            			me.onChange(uiScope, key, newValue, oldValue, true);
    	            	},
    	            	scope: me
    	            }
    			    
    			});
    			
    			me.add(itemsCombo);    			
    			break;
54be8b2e   Benjamin Renard   Add boolean argum...
538
539
540
541
542
543
544
545
546
547
548
549
    		case 'bool' :
    			var argumentField = Ext.create('Ext.form.Checkbox', {
    				argId: 'template_' + key,
    				fieldLabel: argument.name,
    				value: (parseInt(argument.default) == 1),
    				listeners: {
    					change: function(field, newValue, oldValue, eOpts) {
    						var template_args = me.paramRequestObject.get('template_args');
    						if (!template_args)
    	            			template_args = {};
    						template_args[key] = newValue;
    						me.paramRequestObject.set('template_args', template_args);
eac92219   Benjamin Renard   Do not call onCha...
550
    						if (!this.inRebuild && (me.onChange != null))
54be8b2e   Benjamin Renard   Add boolean argum...
551
552
553
554
555
556
557
558
    							me.onChange(uiScope, key, newValue, oldValue, true);
    					},
    					scope: me
    				}
                });
    			
    			me.add(argumentField);  
    			break;
51b7c77c   Benjamin Renard   Add templated par...
559
560
561
562
    		default:
    			console.log('Template argument type not yet implemented: '+argument.type);	
    		}
    	});
7ac3ce50   Benjamin Renard   First implementat...
563
    }
bf776dc8   Benjamin Renard   working
564
});