Blame view

js/app/views/ParamArgumentsUI.js 19 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;
29dfb596   Benjamin Renard   Rework of ParamAr...
44
45
		me.mask();
		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);
bb6e93d9   Benjamin Renard   Implement templat...
79
				me.unmask();
29dfb596   Benjamin Renard   Rework of ParamAr...
80
81
82
83
84
			});  
		}
		else
			me.unmask();
	},
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
274
275
    buildDimIndexSelection: function(relatedDim, data, uiScope) {
    	//Check if this dimension is attached to a table
		var relatedTable = this.getRelatedTableFromDim(relatedDim, data.tables);
1df8e90c   Benjamin Renard   Add selection for...
276
		var dimSize = data.dimensions[relatedDim];
690e0a87   Benjamin Renard   Add sum in table ...
277
		
29dfb596   Benjamin Renard   Rework of ParamAr...
278
		var title = this.getDimensionTitle(relatedDim, data);
7ac3ce50   Benjamin Renard   First implementat...
279
280
281
282
283
		
		var indexes = [];
		indexes.push({'key' : '*', 'value' : 'All'});
		
		if (relatedTable) {
690e0a87   Benjamin Renard   Add sum in table ...
284
			//If it's not a variable table => enable channel selection
690e0a87   Benjamin Renard   Add sum in table ...
285
286
287
288
			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...
289
290
291
		}
		else {
			//Else, use components
7ac3ce50   Benjamin Renard   First implementat...
292
			Ext.Object.each(data.components, function (index, component) {
bb6e93d9   Benjamin Renard   Implement templat...
293
				if (relatedDim == "dim1" && component.index_1 != "")
7ac3ce50   Benjamin Renard   First implementat...
294
					indexes.push({'key' : component.index_1, 'value' : index + ' : ' + component.name});
bb6e93d9   Benjamin Renard   Implement templat...
295
				else if (relatedDim == "dim2" && component.index_2 != "")
7ac3ce50   Benjamin Renard   First implementat...
296
297
298
					indexes.push({'key' : component.index_2, 'value' : index + ' : ' + component.name});
			});
		}
dc9e2c14   Elena.Budnik   init + message + ...
299

7ac3ce50   Benjamin Renard   First implementat...
300
301
302
303
304
305
		//Add combo box
		var indexesStore = Ext.create('Ext.data.Store', {
		    fields: ['key', 'value'],
		    data : indexes
		});

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