Blame view

js/app/views/ParameterUI.js 22.3 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
/**
 * Project   : AMDA-NG
 * Name      : ParameterUI.js
 * @class 	 amdaUI.ParameterUI
 * @extends  Ext.container.Container
 * @brief	 Parameter  Module UI definition (View)
 * @author 	  
3ab0bee9   Elena.Budnik   aprams with args ...
8
 * @version  $Id: ParameterUI.js 2257 2014-04-02 12:21:27Z elena $             
16035364   Benjamin Renard   First commit
9
10
 */

3ab0bee9   Elena.Budnik   aprams with args ...
11
12
Ext.define('amdaUI.ParameterUI', 
{
16035364   Benjamin Renard   First commit
13
	extend: 'Ext.container.Container',
3ab0bee9   Elena.Budnik   aprams with args ...
14

16035364   Benjamin Renard   First commit
15
16
17
	alias: 'widget.panelParam',
	
	requires: [
3ab0bee9   Elena.Budnik   aprams with args ...
18
19
20
		'amdaUI.AliasUI',     
		'amdaUI.CalculatorUI',
		'extensions.SelectableTextArea',
9abfbee9   Benjamin Renard   Add some frames
21
22
		'amdaUI.ParamArgumentsPlug',
                'amdaModel.RequestParamObject'
3ab0bee9   Elena.Budnik   aprams with args ...
23
	],
16035364   Benjamin Renard   First commit
24
	
3ab0bee9   Elena.Budnik   aprams with args ...
25
26
27
28
29
30
31
	constructor: function(config) 
	{    
		this.init(config);
		this.callParent(arguments);
		// load object into form
		this.formPanel.getForm().loadRecord(this.object);
		var paramArgsPlug = this.getPlugin('derived-param-arguments-plugin');
3ab0bee9   Elena.Budnik   aprams with args ...
32
33
34
		if (paramArgsPlug)
			paramArgsPlug.onApply = this.onApplyParameterArgs;
	},
16035364   Benjamin Renard   First commit
35

3ab0bee9   Elena.Budnik   aprams with args ...
36
37
38
39
40
41
42
	addParamInEditor : function(param) 
	{
		var selection = this.constructionField.getSelection();
		this.constructionField.setValue(selection.beforeText + param + selection.afterText);
		this.constructionField.focus();
		this.constructionField.setCaretPosition(this.constructionField.getValue().length);
	},
33ce72a7   Benjamin Renard   Do not show argum...
43
    
3ab0bee9   Elena.Budnik   aprams with args ...
44
45
46
47
48
	onApplyParameterArgs : function(uiScope, paramRequestObject) 
	{
		var fullParam = paramRequestObject.getParamFullName();
		uiScope.addParamInEditor(fullParam);
	},
7ac3ce50   Benjamin Renard   First implementat...
49
    
3ab0bee9   Elena.Budnik   aprams with args ...
50
51
	addParam : function(newParamName, isLeaf, needArgs, components) 
	{
9b36ce29   Benjamin Renard   clean up
52
		//if (!isLeaf || needArgs || components)
370af70e   Elena.Budnik   ParamArgs plugin ...
53
54
55
		if ( needArgs )
			this.editParameterArgs(newParamName, components);
		else
3ab0bee9   Elena.Budnik   aprams with args ...
56
57
			this.addParamInEditor(newParamName);
	},
16035364   Benjamin Renard   First commit
58
    
3ab0bee9   Elena.Budnik   aprams with args ...
59
60
	editParameterArgs: function(name, components) 
	{
29dfb596   Benjamin Renard   Rework of ParamAr...
61
62
		var paramObj = amdaModel.RequestParamObject.getEmptyObj(); 
		paramObj.paramid = name;
3ab0bee9   Elena.Budnik   aprams with args ...
63
64
65
66
67
68
69
70
71
72
73
74
75
76
	
		if (components) 
		{
			if (components['index1']) {
				paramObj['dim1-index'] = components['index1'];
				++paramObj['type'];
			}
			
			if (components['index2']) {
				paramObj['dim2-index'] = components['index2'];
				++paramObj['type'];
			}
		}
	
7ac3ce50   Benjamin Renard   First implementat...
77
		var paramArgsPlug = this.getPlugin('derived-param-arguments-plugin');
bb6e93d9   Benjamin Renard   Implement templat...
78
		if (paramArgsPlug) {
690e0a87   Benjamin Renard   Add sum in table ...
79
			var workinRequestParamObject = Ext.create('amdaModel.RequestParamObject', paramObj);
bb6e93d9   Benjamin Renard   Implement templat...
80
81
			paramArgsPlug.show('derived-param-arguments-plugin', workinRequestParamObject);
		}
7ac3ce50   Benjamin Renard   First implementat...
82
83
	},
    
3ab0bee9   Elena.Budnik   aprams with args ...
84
85
86
	setObject : function (object) 
	{
		this.object = object; 
7cab5983   Benjamin Renard   Add modif. time f...
87
		// load object into form
3ab0bee9   Elena.Budnik   aprams with args ...
88
89
		this.formPanel.getForm().loadRecord(this.object);
	},
16035364   Benjamin Renard   First commit
90
       
3ab0bee9   Elena.Budnik   aprams with args ...
91
92
93
94
95
96
97
98
	/**
	* update this.object from form
	*/
	updateObject : function()
	{    
		// get the basic form
		var basicForm = this.formPanel.getForm();        
		var updateStatus = true;
16035364   Benjamin Renard   First commit
99

3ab0bee9   Elena.Budnik   aprams with args ...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
		var fieldsWithoutName = basicForm.getFields().items;
		Ext.Array.each(fieldsWithoutName, function(item, index,allItems)
		{
			if(item !== this.fieldName) 
			{ 		     
				if (!item.isValid()) {
					// set update isn't allowed
					updateStatus = false;    
				}
			}
		}, this);
		// if the update is allowed
		if (updateStatus) {
			/// real object update
			// update TimeTable object with the content of form
			basicForm.updateRecord(this.object);	
16035364   Benjamin Renard   First commit
116
		}
3ab0bee9   Elena.Budnik   aprams with args ...
117
118
119
		// return the update status
		return updateStatus;	    
	},
16035364   Benjamin Renard   First commit
120
 
3ab0bee9   Elena.Budnik   aprams with args ...
121
122
	updateConstruct : function(oldval,newval) 
	{
16035364   Benjamin Renard   First commit
123
124
125
126
127
		// update constructionField (Construct parameter) in window parameter
		var expression = this.constructionField.value;
		oldval = oldval.replace(/[(]/g,"\\(");
		oldval = oldval.replace(/[)]/g,"\\)");	
		var reg=new RegExp(oldval, "g");
3ab0bee9   Elena.Budnik   aprams with args ...
128
129
		expression = expression.replace(reg, newval);
		this.constructionField.setValue(expression);
16035364   Benjamin Renard   First commit
130
131
	},
    
8ba47f72   Benjamin Renard   rest actualisatio...
132
133
134
135
        
        /** 
 	 * Generate info for parameter desplay
         */
9b36ce29   Benjamin Renard   clean up
136
        generateParamInfo : function(onSuccess)
8ba47f72   Benjamin Renard   rest actualisatio...
137
138
139
140
141
        {
	   var me = this;
	   var paramModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id);
     
           var obj = {
9b36ce29   Benjamin Renard   clean up
142
143
                        paramId : 'ws_'+this.object.get('name'),
                        buildchain:this.object.get('buildchain'),
7cab5983   Benjamin Renard   Add modif. time f...
144
145
146
                        timestep:this.object.get('timestep'),
			reference_param: this.object.get('reference_param'),
			sampling_mode: this.object.get('sampling_mode')
8ba47f72   Benjamin Renard   rest actualisatio...
147
                };
f85f44e4   Benjamin Renard   us okkkkkkkkkk
148
                 loadMask.show();
8ba47f72   Benjamin Renard   rest actualisatio...
149
150
151
                AmdaAction.generateParamInfo(obj, function (result, e) {
	 if (!result || !result.success)
                        {
f85f44e4   Benjamin Renard   us okkkkkkkkkk
152
                            loadMask.hide();
8ba47f72   Benjamin Renard   rest actualisatio...
153
154
155
156
157
158
                                if (result.message)
                                        myDesktopApp.warningMsg(result.message);
                                else
                                        myDesktopApp.warningMsg('Unknown error during parameter compilation');
                                return;
                        }
f85f44e4   Benjamin Renard   us okkkkkkkkkk
159
	loadMask.hide();	
8ba47f72   Benjamin Renard   rest actualisatio...
160
                    paramModule.linkedNode.get('object').set('dim_1', parseInt(result.dimensions.dim_1));
eb0ba55f   Benjamin Renard   reste refreche ar...
161
                    paramModule.linkedNode.get('object').set('dim_2', parseInt(result.dimensions.dim_2));  
9b36ce29   Benjamin Renard   clean up
162
163
164
                    if (onSuccess)
                        onSuccess();
/*                    paramModule.linkedNode.update({scope : me, 
8ba47f72   Benjamin Renard   rest actualisatio...
165
166
167
168
                        failure: function(record, operation) {
                            
                        },
                        callback: function() {
eb0ba55f   Benjamin Renard   reste refreche ar...
169
                                                   }
8ba47f72   Benjamin Renard   rest actualisatio...
170
                    });
9b36ce29   Benjamin Renard   clean up
171
    */              			
8ba47f72   Benjamin Renard   rest actualisatio...
172
173
174
                });
        },

3ab0bee9   Elena.Budnik   aprams with args ...
175
176
177
178
	/**
	* save method called by Save button
	*/
	saveProcess : function(toRename)
7cab5983   Benjamin Renard   Add modif. time f...
179
	{
3ab0bee9   Elena.Budnik   aprams with args ...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
		if(this.object.dirty) 
		{
			// Parameter Module
			var paramModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id);            
			// if the name has been modified this is a creation
			if (this.object.isModified('name'))
			{                
				// if object already has an id : it's a 'rename' of an existing TimeTable
				if (this.object.get('id'))
				{
					// the context Node is the parent node of current edited one
					var contextNode = paramModule.linkedNode.parentNode;
					// link a new node to the TimeTableModule
					paramModule.createLinkedNode();
					// set the contextNode
					paramModule.linkedNode.set('contextNode',contextNode);
					// create a new object linked		   		  
					paramModule.createObject(this.object.getJsonValues());
					var paramobj = paramModule.linkedNode.get('object');
					//synchronize objects
					this.object = paramobj;
					if (toRename) paramModule.linkedNode.toRename = true;
9b36ce29   Benjamin Renard   clean up
202
				} 
9b36ce29   Benjamin Renard   clean up
203
204
205
				this.generateParamInfo(function () {
                                                                                    paramModule.linkedNode.set('isParameter', true); 
                                                                                    paramModule.linkedNode.create({scope : this, callback : function() {
9b36ce29   Benjamin Renard   clean up
206
207
                                                                                    }});
                                                                                });   
3ab0bee9   Elena.Budnik   aprams with args ...
208
209
210
			} else 
			{            
				paramModule.linkedNode.set('contextNode',paramModule.contextNode); 
9b36ce29   Benjamin Renard   clean up
211
212
                                                                                this.generateParamInfo(function () {
                                                                                    paramModule.linkedNode.update({scope : this, callback : function() {
9b36ce29   Benjamin Renard   clean up
213
214
                                                                                    }});
                                                                                });   
3ab0bee9   Elena.Budnik   aprams with args ...
215
			}
f85f44e4   Benjamin Renard   us okkkkkkkkkk
216
		}   
3ab0bee9   Elena.Budnik   aprams with args ...
217
	},
16035364   Benjamin Renard   First commit
218

3ab0bee9   Elena.Budnik   aprams with args ...
219
220
221
222
223
224
225
226
227
228
	/**
	* overwrite metod called by Save button
	*/
	overwriteProcess : function(btn)
	{
		if (btn == 'cancel') return; 
			
		this.fieldName.clearInvalid();  
		this.saveProcess(true);        
	},
16035364   Benjamin Renard   First commit
229
    
3ab0bee9   Elena.Budnik   aprams with args ...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
	/**
	*   Check if brackets are balanced
	*/   
	isBalanced : function(str)
	{  
		str =  (""+str).replace(/[^()\[\]{}]/g, ""); 
		var bracket = {
						"]": "[",
						"}": "{",
						")": "("
					},
			openBrackets = [], 
			isClean = true,
			i = 0,
			len = str.length;
16035364   Benjamin Renard   First commit
245

3ab0bee9   Elena.Budnik   aprams with args ...
246
247
248
249
250
251
252
253
254
255
256
257
258
		for(; isClean && i<len; i++ )
		{                
			if( bracket[ str[ i ] ] ){
				isClean = ( openBrackets.pop() === bracket[ str[ i ] ] );
			} else {
				openBrackets.push(str[i]);
			}
		}
		if (!(isClean && !openBrackets.length)) return 'Brackets are not balanced';
		
		return true; 
	},
	
16035364   Benjamin Renard   First commit
259
260
261
262
	/**
	 * Check if changes were made before closing window 
	 * @return true if changes
	 */	   
3ab0bee9   Elena.Budnik   aprams with args ...
263
264
	fclose : function() 
	{
16035364   Benjamin Renard   First commit
265
266
267
268
		var isDirty = this.formPanel.getForm().isDirty();
		return isDirty;
	},
	
3ab0bee9   Elena.Budnik   aprams with args ...
269
270
	init: function(config) 
	{		
16035364   Benjamin Renard   First commit
271
		this.fieldName = new Ext.form.field.Text({
3ab0bee9   Elena.Budnik   aprams with args ...
272
				labelAlign: 'top', itemId: 'formParamName',
7cab5983   Benjamin Renard   Add modif. time f...
273
				labelPad: 0,
5e6d074f   Elena.Budnik   infobull for para...
274
				fieldLabel: 'Parameter Name',
3ab0bee9   Elena.Budnik   aprams with args ...
275
276
				name : 'name',
				allowBlank : false, //blankText : 'Name is required',
5e6d074f   Elena.Budnik   infobull for para...
277
				emptyText: 'Please only low case!',
3ab0bee9   Elena.Budnik   aprams with args ...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
				width: 150,
				validateOnChange: false,
				validateOnBlur: false,
				enableKeyEvents: true,
				validFlag: false,
				validator : function() 
				{
					return this.validFlag;
				},
				stripCharsRe: /(^\s+|\s+$)/g,
				listeners : 
				{
					keyUp : function(field, e, opt) 
					{
						this.setValue(this.getValue().toLowerCase());
					}
				}
16035364   Benjamin Renard   First commit
295
		});
3ab0bee9   Elena.Budnik   aprams with args ...
296
	
16035364   Benjamin Renard   First commit
297
298
		this.constructionField = new extensions.SelectableTextArea({
			labelAlign: 'top',
7cab5983   Benjamin Renard   Add modif. time f...
299
			labelPad: 0,
16035364   Benjamin Renard   First commit
300
			itemId: 'formParamConstructParameter',
5e6d074f   Elena.Budnik   infobull for para...
301
			fieldLabel:'<img amda_clicktip="constructParameter"  src="js/resources/images/16x16/info_mini.png"/>&nbsp;Construct Parameter',
16035364   Benjamin Renard   First commit
302
303
		 	allowBlank : false, blankText : 'Construct Parameter is required',
			name : 'buildchain',
7cab5983   Benjamin Renard   Add modif. time f...
304
			flex: 0.6,
16035364   Benjamin Renard   First commit
305
306
			validateOnChange: false,
			validateOnBlur: false,
3ab0bee9   Elena.Budnik   aprams with args ...
307
			validator : this.isBalanced,
16035364   Benjamin Renard   First commit
308
309
			listeners :
			{
3ab0bee9   Elena.Budnik   aprams with args ...
310
311
312
313
314
315
316
317
318
319
				render : function(o,op)
				{
					var me = this;
					var meEl = me.bodyEl;
					var dropTarget = Ext.create('Ext.dd.DropTarget', meEl, 
					{
						ddGroup: 'explorerTree',
						notifyEnter : function(ddSource, e, data) {},
						notifyOver  : function(ddSource, e, data)
						{
8497e83c   Elena.Budnik   redmine 5515
320
							if (data.records[0].get('nodeType') == 'localParam' && data.records[0].get('notyet')) 
3ab0bee9   Elena.Budnik   aprams with args ...
321
322
323
324
325
							{
								this.valid = false;
								return this.dropNotAllowed;   
							}
							
8497e83c   Elena.Budnik   redmine 5515
326
327
328
329
330
331
332
							if (((data.records[0].get('nodeType') == 'localParam')   ||
								(data.records[0].get('nodeType') == 'remoteParam') ||
								(data.records[0].get('nodeType') == 'remoteSimuParam') ||
								(data.records[0].get('nodeType') == 'derivedParam') ||
								(data.records[0].get('nodeType')== 'myDataParam') ||
								(data.records[0].get('nodeType') == 'alias')) &&
								(data.records[0].isLeaf() || data.records[0].get('isParameter')) && 
3ab0bee9   Elena.Budnik   aprams with args ...
333
334
335
336
337
338
339
340
341
								!(data.records[0].data.disable))
							{
								this.valid = true;
								return this.dropAllowed;
							}
							this.valid = false;
							return this.dropNotAllowed;
						},
						notifyDrop  : function(ddSource, e, data)
9b36ce29   Benjamin Renard   clean up
342
						{	
3ab0bee9   Elena.Budnik   aprams with args ...
343
344
345
							if (!this.valid)
								return false;
							var nameToSent;
9b36ce29   Benjamin Renard   clean up
346
							var components = null;                                                                                                                                            
8497e83c   Elena.Budnik   redmine 5515
347
							switch (data.records[0].get('nodeType'))
3ab0bee9   Elena.Budnik   aprams with args ...
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
							{
								case 'localParam' :
								case 'remoteParam' :
								case 'remoteSimuParam' :    
									nameToSent = data.records[0].get('id');
									if (data.records[0].get('alias')!= "" )
										var nameToSent = "#"+data.records[0].get('alias');
									var component_info = data.records[0].get('component_info');
									if (component_info && component_info.parentId) 
									{													
										if ( component_info.index1 && component_info.index2 )
										{															 
											nameToSent = component_info.parentId;
											components = [];												
											if (component_info.index1)
												components['index1'] = component_info.index1;
											if (component_info.index2)
												components['index2'] = component_info.index2;
										}	
										if ( data.records[0].get('needsArgs') )
										{															
											nameToSent = component_info.parentId;	
											if (component_info.index1)
											{
												components = [];	
												components['index1'] = component_info.index1;
											}
										}													
									}
									break;
								case 'alias' :
									nameToSent = "#"+data.records[0].get('text');
									break;
								case 'derivedParam' :
									nameToSent = "ws_"+data.records[0].get('text');
									break;
								case 'myDataParam' :
									var name = data.records[0].get('text');
									nameToSent = "wsd_"+name;
3ab0bee9   Elena.Budnik   aprams with args ...
387
388
									break;
								default :
9b36ce29   Benjamin Renard   clean up
389
                                                                                                                                                              
3ab0bee9   Elena.Budnik   aprams with args ...
390
391
392
393
									return false;
							}
							var paramModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id);
							if (paramModule) {
b1fab76f   Benjamin Renard   Give the possibil...
394
395
396
397
398
399
400
401
								if (data.records[0].get('predefinedArgs')) {
									paramModule.parseTemplatedParam(nameToSent, function(param_info) {
										paramModule.addParam(param_info.paramid, data.records[0].get('leaf'), true, components, param_info.template_args);
									});
								}
								else {
									paramModule.addParam(nameToSent, data.records[0].get('leaf'), data.records[0].get('needsArgs'), components);
								}
3ab0bee9   Elena.Budnik   aprams with args ...
402
403
404
405
406
							}
							return true;
						}
					});
				}
16035364   Benjamin Renard   First commit
407
408
409
410
411
412
413
414
			}
            //TODO: ?validator on formula structure?
//			listener : {
//				valid : function(field) {
//
//				}
//			}
		});
7cab5983   Benjamin Renard   Add modif. time f...
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433

	        var samplingmode_store = new Ext.data.ArrayStore({
			fields: ['id', 'name'],
			data: [
				['timestep', 'Time Step'],
				['refparam', 'Ref. Parameter']
			]
		});

		this.timeStepField = new Ext.form.NumberField({
			fieldLabel: '<img amda_clicktip="resamplingStep" src="js/resources/images/16x16/info_mini.png"/>&nbsp;Time Step (sec)',
			labelAlign: 'top',
			labelPad: 0,
			blankText : 'Time Step is required',
			name : 'timestep',
			minValue : 0.001,
			decimalPrecision : 10,
			hideTrigger: true,
			width: 150,
b78325f1   Benjamin Renard   Add validation fo...
434
435
436
437
438
439
440
441
442
443
444
445
446
			validateOnBlur: false,
			allowBlank: false,
			isValid: function() {
				var me = this,
					disabled = me.disabled,
					validate = me.forceValidation || !disabled;

				if (!me.isVisible()) {
					return true;
				}

				return validate ? me.validateValue(me.processRawValue(me.getRawValue())) : disabled;
			}
7cab5983   Benjamin Renard   Add modif. time f...
447
448
449
450
451
452
453
454
455
		});

		this.refParamField = new Ext.form.TextField({
			fieldLabel: '<img amda_clicktip="resamplingRefParam" src="js/resources/images/16x16/info_mini.png"/>&nbsp;Reference Param.',
			labelAlign: 'top',
			labelPad: 0,
			name : 'reference_param',
			width: 150,
			hidden: true,
b78325f1   Benjamin Renard   Add validation fo...
456
			allowBlank: false,
7cab5983   Benjamin Renard   Add modif. time f...
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
			listeners: {
				afterrender: function(field, eOpts ){
					var paramTarget = new Ext.dd.DropTarget(field.el.dom,
						{
							ddGroup: 'explorerTree',
							notifyEnter: function(ddSource, e, data) {
							},
							notifyDrop: function(ddSource, e, data) {
								var selectedRecord = ddSource.dragData.records[0];
								switch (selectedRecord.$className) {
									case 'amdaModel.LocalParamNode'   :
									case 'amdaModel.RemoteParamNode'  :
									case 'amdaModel.RemoteSimuParamNode'  :
										if (!selectedRecord.get('isParameter') || selectedRecord.get('disable'))
											return false;
										if (selectedRecord.get('alias') != "" )
											field.setValue("#"+selectedRecord.get('alias'));
										else
											field.setValue(selectedRecord.get('id'));
										return true;
									case 'amdaModel.AliasNode'        :
										if (!selectedRecord.isLeaf())
											return false;
										field.setValue("#"+selectedRecord.get('text'));
										return true;
									case 'amdaModel.DerivedParamNode' :
										if (!selectedRecord.isLeaf())
											return false;
										field.setValue("ws_"+selectedRecord.get('text'));
										return true;
									case 'amdaModel.MyDataParamNode' :
										if (!selectedRecord.isLeaf())
											return false;
										field.setValue("wsd_"+selectedRecord.get('text'));
										return true;
									default:
										return false;
								}
								return true;
							}
						}
					);
				},
				scope: this
b78325f1   Benjamin Renard   Add validation fo...
501
502
503
504
505
506
507
508
509
510
511
			},
			isValid: function() {
				var me = this,
					disabled = me.disabled,
					validate = me.forceValidation || !disabled;

				if (!me.isVisible()) {
					return true;
				}

				return validate ? me.validateValue(me.processRawValue(me.getRawValue())) : disabled;
7cab5983   Benjamin Renard   Add modif. time f...
512
513
514
515
516
517
518
519
520
521
522
			}
		});

		this.samplingDefContainer = new Ext.container.Container({
			border: false,
			items: [
				this.timeStepField,
				this.refParamField
			],
			width: 150
		});
16035364   Benjamin Renard   First commit
523
524
525
526
527
528
529
530
531
		
		this.formPanel = new Ext.form.Panel({
			id: 'vbox-paramForm',			
			bodyStyle: {background : '#dfe8f6'},
			border: false,
			buttonAlign: 'left',
			region: 'center',
			trackResetOnLoad: true, //reset to the last loaded record
			layout: {
3ab0bee9   Elena.Budnik   aprams with args ...
532
				type: 'vbox',
7cab5983   Benjamin Renard   Add modif. time f...
533
				defaultMargins: {top: 5, left:5, bottom:10, right:10},			   
3ab0bee9   Elena.Budnik   aprams with args ...
534
				align: 'stretch'
16035364   Benjamin Renard   First commit
535
536
			},
			defaults: {
3ab0bee9   Elena.Budnik   aprams with args ...
537
				border: false
16035364   Benjamin Renard   First commit
538
539
540
			},
			items: [
					{
3ab0bee9   Elena.Budnik   aprams with args ...
541
542
543
544
545
546
547
548
549
						flex: 1,
						xtype: 'container',
						border: false,
						layout: {
							type: 'table',
							columns: 3
						},
						defaultType: 'textfield',
						defaults: {
7cab5983   Benjamin Renard   Add modif. time f...
550
551
							labelAlign: 'top',
							labelPad: 0
3ab0bee9   Elena.Budnik   aprams with args ...
552
553
554
555
556
557
558
						},
						items: [
							this.fieldName,
							{
								xtype:'component', width: 20
							},
							{
7cab5983   Benjamin Renard   Add modif. time f...
559
560
561
								fieldLabel: 'Last modification',
								xtype: 'displayfield',
								name : 'last_update',
0f7460c1   Elena.Budnik   redmine 5518
562
								width: 150,
7cab5983   Benjamin Renard   Add modif. time f...
563
564
565
566
567
568
569
								renderer: function(value, field) {
									var tpl = new Ext.XTemplate('<p style="font-style:italic;color:gray;margin:0;">{date}</>');
									var mod_date = 'Not saved';
									if (value > 0)
										mod_date = Ext.Date.format(new Date(value*1000), "Y-m-d\\TH:i:s");
									return tpl.apply({date: mod_date});
								},
3ab0bee9   Elena.Budnik   aprams with args ...
570
							},
7cab5983   Benjamin Renard   Add modif. time f...
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
                                                        {
                                                                xtype: 'combo',
                                                                fieldLabel: 'Sampling mode',
                                                                name: 'sampling_mode',
                                                                queryMode: 'local',
                                                                editable: false,
								valueField: 'id',
								displayField: 'name',
								store: samplingmode_store,
								value: samplingmode_store.first(),
								listeners: {
									change: function(field, value) {
										this.timeStepField.setVisible(value != 'refparam');
										this.refParamField.setVisible(value == 'refparam');
									},
									scope: this
								}
                                                        },
                                                        {
                                                                xtype:'component', width: 20
                                                        },
							this.samplingDefContainer,
3ab0bee9   Elena.Budnik   aprams with args ...
593
							{
3ab0bee9   Elena.Budnik   aprams with args ...
594
595
596
597
598
599
600
601
								itemId: 'formParamUnit', 
								fieldLabel: 'Units',
								name : 'units',
								width: 150
							},
							{
								xtype:'component', width: 20
							},
0f7460c1   Elena.Budnik   redmine 5518
602
							{								
3ab0bee9   Elena.Budnik   aprams with args ...
603
604
605
606
607
608
								itemId: 'formParamYTitle', 
								fieldLabel: 'Y Title for Plot',
								name : 'ytitle',
								width: 150
							},
							{
3ab0bee9   Elena.Budnik   aprams with args ...
609
610
611
612
613
614
615
616
								itemId: 'formParamDescription',
								name: 'description', 
								xtype: 'textarea', fieldLabel:'Description',
								width: 320,  height: 75,
								colspan: 3
							}]                        
					},
					this.constructionField
16035364   Benjamin Renard   First commit
617
618
619
				],		        
				fbar: [
					{
3ab0bee9   Elena.Budnik   aprams with args ...
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
						text: 'Save',
						scope : this,
						handler: function(){
							if (this.updateObject())
							{
								var paramModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id);	
								if (!paramModule)
									return;
								var me = this;
								paramModule.linkedNode.isValidName(this.fieldName.getValue(), function (res) 
								{
									if (!res)
									{
										me.fieldName.validFlag = 'Error during object validation';
										myDesktopApp.errorMsg(me.fieldName.validFlag);
										me.fieldName.validate();
										return;
									}
16035364   Benjamin Renard   First commit
638
								  
3ab0bee9   Elena.Budnik   aprams with args ...
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
									if (!res.valid)
									{
										if (res.error)
										{
											if (res.error.search('subtree') != -1) {  							
												Ext.MessageBox.show({title:'Warning', 
															msg: res.error+'<br/>Do you want to overwrite it?',
															width: 300,
															buttons: Ext.MessageBox.OKCANCEL, 
															fn : me.overwriteProcess,
															icon: Ext.MessageBox.WARNING,
															scope : me
												});
												me.fieldName.validFlag = true;
											}
											else
												me.fieldName.validFlag = res.error;
										}
										else
										{
											me.fieldName.validFlag = 'Invalid object name';
											myDesktopApp.errorMsg(me.fieldName.validFlag);
										}
										me.fieldName.validate();
										return;
									}
									
									me.fieldName.validFlag = true;
									me.fieldName.validate();
9b36ce29   Benjamin Renard   clean up
668
                                                                                                                                                                                    me.saveProcess(false);
3ab0bee9   Elena.Budnik   aprams with args ...
669
670
671
								});							  
							}
						}
16035364   Benjamin Renard   First commit
672
673
					},
					{
3ab0bee9   Elena.Budnik   aprams with args ...
674
675
676
677
678
679
680
681
682
683
684
685
						text: 'Reset',
						scope: this,
						handler: function()
						{
							var paramModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.param.id);			
							paramModule.createLinkedNode();
							paramModule.createObject();
							this.setObject(paramModule.getLinkedNode().get('object'));
							/* reset with keeping old object
							this.formPanel.getForm().reset();
							*/
						}
16035364   Benjamin Renard   First commit
686
					}
3ab0bee9   Elena.Budnik   aprams with args ...
687
				] 	
16035364   Benjamin Renard   First commit
688
689
690
691
692
693
694
		});
				
		var myConf = {
				layout: 'border',
				border: false,
				defaults: { layout: 'fit', border: false },
				items: [
3ab0bee9   Elena.Budnik   aprams with args ...
695
696
697
698
699
					this.formPanel,
					{
						xtype: 'panel', region: 'south',
						title: 'Information',
						collapsible: true,
42863f42   Elena.Budnik   collapseMode: "he...
700
						collapseMode: 'header',
3ab0bee9   Elena.Budnik   aprams with args ...
701
702
703
704
705
706
707
708
						height: 100,
						autoHide: false,
						iconCls: 'icon-information',
						bodyStyle: 'padding:5px',
						loader: {
						autoLoad: true,
						url: helpDir+'myParameterHOWTO'
						}
16035364   Benjamin Renard   First commit
709
				} ],
3ab0bee9   Elena.Budnik   aprams with args ...
710
711
712
				plugins: [ 
						{ptype: 'calculator', myBtns:[], context: 'Parameter' }, 
						{ptype: 'paramArgumentsPlugin', pluginId: 'derived-param-arguments-plugin'}
5e6d074f   Elena.Budnik   infobull for para...
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
				],
				listeners:{
					click: {
						element: 'el',
						fn: function(e,t) { 
							var me = t,
							text = me.getAttribute('amda_clicktip');
							if (text) {
								e.preventDefault();
								AmdaAction.getInfo({name : text}, function(res,e) {					    					   
									if (res.success) myDesktopApp.infoMsg(res.result);
								}); 
							}
						}
					}
				}
16035364   Benjamin Renard   First commit
729
			};
5e6d074f   Elena.Budnik   infobull for para...
730
						
16035364   Benjamin Renard   First commit
731
732
733
			Ext.apply(this, Ext.apply(arguments, myConf));
	}
});