Blame view

js/app/views/PlotComponents/PlotStandardForm.js 13 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * Project   : AMDA-NG
 * Name      : PlotStandardForm.js
 * @class   amdaPlotComp.PlotStandardForm
 * @extends Ext.form.Panel
 * @brief   Standard Form used to define some options for a plot element
 * @author  Benjamin Renard
 * @version $Id: PlotStandardForm.js benjamin $
 */

Ext.define('amdaPlotComp.PlotStandardForm', {
	extend: 'Ext.form.Panel',
    
	requires : [                
7ef7ea02   Benjamin Renard   Add erase button ...
15
16
		        'amdaPlotObj.PlotObjectConfig',
		        'amdaPlotComp.EraseTrigger'
437c4dbc   Benjamin Renard   First implementat...
17
18
19
20
21
	],
	
    //Object associated to this form
    object: null,
    
17433635   Benjamin Renard   Add series and sp...
22
23
    //Link to the tree
    crtTree: null,
f8dfaec8   Hacene SI HADJ MOHAND   rm_6954 in progress
24
25
    desableTickNumber:true,
    desableTickSpacing:true,
17433635   Benjamin Renard   Add series and sp...
26
    
437c4dbc   Benjamin Renard   First implementat...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    constructor: function(config) {
		this.init(config);
		this.callParent(arguments);
	},
	
	setObject : function(object) {
		this.object = object;
		this.loadRecord(this.object);
	},
	
	//To override to add form components
	getFormItems: function() {
		return [];
	},
	
0a295c3e   Benjamin Renard   Dynamic load of p...
42
43
44
45
46
47
48
	//Function called after element creation by PlotElementPanel
    updateElement: function(onAfterUpdate) {
    	if (onAfterUpdate)
    		onAfterUpdate();
    },
	
    //
dbb7bcbe   Benjamin Renard   Add curves defint...
49
	addStandardText: function(name, label, onChange) {
437c4dbc   Benjamin Renard   First implementat...
50
51
52
53
54
55
56
		return {
        	xtype: 'textfield',
        	name: name,
        	fieldLabel: label,
            listeners: {
            	change: function(field, newValue, oldValue, eOpts) {
            		this.object.set(name, newValue);
dbb7bcbe   Benjamin Renard   Add curves defint...
57
58
            		if (onChange != null)
            			onChange(name, newValue, oldValue);
437c4dbc   Benjamin Renard   First implementat...
59
60
61
62
63
64
            	},
            	scope: this
            }
        };
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
65
	addStandardFloat: function(name, label, min, max, allowBlank, onChange) {
003ba315   Benjamin Renard   Add Epoch Plot an...
66
67
		allowBlank = (typeof allowBlank !== 'undefined') ? allowBlank : false;
		
437c4dbc   Benjamin Renard   First implementat...
68
69
70
71
		return {
	        xtype: 'numberfield',
	        name: name,
	        fieldLabel: label,
e0648247   Benjamin Renard   Set decimal preci...
72
	        decimalPrecision : 20,
437c4dbc   Benjamin Renard   First implementat...
73
74
	        minValue         : min,
	        maxValue         : max,
003ba315   Benjamin Renard   Add Epoch Plot an...
75
	        allowBlank       : allowBlank,
437c4dbc   Benjamin Renard   First implementat...
76
77
78
	        listeners: {
            	change: function(field, newValue, oldValue, eOpts) {
            		this.object.set(name, newValue);
dbb7bcbe   Benjamin Renard   Add curves defint...
79
80
            		if (onChange != null)
            			onChange(name, newValue, oldValue);
a3ed599f   Hacene SI HADJ MOHAND   rm 6954 ok
81
82
83
84
85
            	},
            	scope: this
            }
	    };
	},
c504df71   Hacene SI HADJ MOHAND   #6954 allegment i...
86
        	addStandardInteger: function(name, label, min, max, allowBlank, hidden,onChange) {
a3ed599f   Hacene SI HADJ MOHAND   rm 6954 ok
87
88
89
		allowBlank = (typeof allowBlank !== 'undefined') ? allowBlank : false;
		
		return {
f8dfaec8   Hacene SI HADJ MOHAND   rm_6954 in progress
90
                            id:name,
a3ed599f   Hacene SI HADJ MOHAND   rm 6954 ok
91
92
93
	        xtype: 'numberfield',
	        name: name,
	        fieldLabel: label,
c504df71   Hacene SI HADJ MOHAND   #6954 allegment i...
94
                            hidden : (hidden)? true:false,
a3ed599f   Hacene SI HADJ MOHAND   rm 6954 ok
95
96
97
98
99
100
101
102
103
104
                            regex:/^\d+$/,
	        decimalPrecision : 20,
	        minValue         : min,
	        maxValue         : max,
	        allowBlank       : allowBlank,
	        listeners: {
            	change: function(field, newValue, oldValue, eOpts) {
            		this.object.set(name, newValue);
            		if (onChange != null)
            			onChange(name, newValue, oldValue);
437c4dbc   Benjamin Renard   First implementat...
105
106
107
108
109
            	},
            	scope: this
            }
	    };
	},
afb7b464   Benjamin Renard   Fix decimal preci...
110

c504df71   Hacene SI HADJ MOHAND   #6954 allegment i...
111
	addStandardFloat2: function(name, label, min, max, allowBlank, hidden, onChange) {
afb7b464   Benjamin Renard   Fix decimal preci...
112
113
114
		allowBlank = (typeof allowBlank !== 'undefined') ? allowBlank : false;

		return {
f8dfaec8   Hacene SI HADJ MOHAND   rm_6954 in progress
115
                                                            id:name,
afb7b464   Benjamin Renard   Fix decimal preci...
116
117
118
119
			xtype: 'textfield',
			name: name,
			fieldLabel: label,
			regex :  /[-+]?(?:\d*\.?\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/,
c504df71   Hacene SI HADJ MOHAND   #6954 allegment i...
120
                                                            hidden : (hidden)? true:false,
afb7b464   Benjamin Renard   Fix decimal preci...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
			validator: function (val) {
				var errMsg = null;
				if (!allowBlank && Ext.isEmpty(val)) {
					errMsg = 'Blank value not allowed';
				}
				else if ((typeof min !== 'undefined') && (parseFloat(val) < min)) {
					errMsg = 'Min. allowed value is ' + min;
				}
				else if ((typeof max !== 'undefined') && (parseFloat(val) > max)) {
					errMsg = 'Max. allowed value is ' + max;
				}
				
				return errMsg ? errMsg : true;
			},
			listeners: {
				change: function(field, newValue, oldValue, eOpts) {
					this.object.set(name, newValue);
					if (onChange != null)
						onChange(name, newValue, oldValue);
				},
				scope: this
			}
		};
	},
437c4dbc   Benjamin Renard   First implementat...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	
	addStandardCombo: function(name, label, availableData, onChange) {
		var comboStore = Ext.create('Ext.data.Store', {
		    fields: ['key', 'value'],
		    data : availableData
		});
		
		return {
        	xtype: 'combo',
        	name: name,
        	fieldLabel: label,
        	store: comboStore,
        	queryMode: 'local',
            displayField: 'value',
            valueField: 'key',
abe09878   Benjamin Renard   Add panels and ax...
160
            editable: false,
437c4dbc   Benjamin Renard   First implementat...
161
162
            listeners: {
            	change: function(combo, newValue, oldValue, eOpts) {
437c4dbc   Benjamin Renard   First implementat...
163
            		if (onChange != null)
a8c54fb9   Benjamin Renard   Add text object p...
164
            			onChange(name, newValue, oldValue);
a971060f   Benjamin Renard   Fix some bugs
165
            		this.object.set(name, newValue);
437c4dbc   Benjamin Renard   First implementat...
166
167
168
169
170
171
            	},
            	scope: this
            }
        };
	},
	
003ba315   Benjamin Renard   Add Epoch Plot an...
172
	addStandardCheck: function(name, label, onChange) {
437c4dbc   Benjamin Renard   First implementat...
173
174
175
176
177
178
		return {
        	xtype: 'checkbox',
        	name: name,
        	boxLabel: label,
            listeners: {
            	change: function(combo, newValue, oldValue, eOpts) {
f8dfaec8   Hacene SI HADJ MOHAND   rm_6954 in progress
179
                    
437c4dbc   Benjamin Renard   First implementat...
180
            		this.object.set(name, newValue);
003ba315   Benjamin Renard   Add Epoch Plot an...
181
            		if (onChange != null)
a8c54fb9   Benjamin Renard   Add text object p...
182
            			onChange(name, newValue, oldValue);
437c4dbc   Benjamin Renard   First implementat...
183
184
185
186
187
188
            	},
            	scope: this
            }
        };
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
189
	addStandardFieldSet: function(title, checkboxName, items, onChangeCheck) {
437c4dbc   Benjamin Renard   First implementat...
190
191
		return {
        	xtype: 'fieldset',
4bece920   Elena.Budnik   fieldset colors
192
			cls : 'child-fieldset',
437c4dbc   Benjamin Renard   First implementat...
193
194
195
196
197
198
199
200
201
202
203
204
205
206
        	title: title,
        	collapsible: true,
        	collapsed: true,
        	checkboxName: checkboxName,
        	checkboxToggle: checkboxName != '',
        	layout: {
			    type: 'vbox',
			    pack: 'start',
			    align: 'stretch'
			},
			items: items,
			listeners: {
				expand: function(fieldset, eOpts) {
					if (checkboxName != '')
dbb7bcbe   Benjamin Renard   Add curves defint...
207
					{
437c4dbc   Benjamin Renard   First implementat...
208
						this.object.set(checkboxName, true);
dbb7bcbe   Benjamin Renard   Add curves defint...
209
210
211
						if (onChangeCheck != null)
							onChangeCheck(checkboxName, true, false);
					}
437c4dbc   Benjamin Renard   First implementat...
212
213
214
				},
				collapse: function(fieldset, eOpts) {
					if (checkboxName != '')
dbb7bcbe   Benjamin Renard   Add curves defint...
215
					{
437c4dbc   Benjamin Renard   First implementat...
216
						this.object.set(checkboxName, false);
dbb7bcbe   Benjamin Renard   Add curves defint...
217
218
219
						if (onChangeCheck != null)
							onChangeCheck(checkboxName, false, true);
					}
437c4dbc   Benjamin Renard   First implementat...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
				},
				scope: this
			}
        };
	},
	
	addStandardFont: function(namePrefix) {
		var fontItems = [
		    this.addStandardCombo(namePrefix+'-name', 'Name', amdaPlotObj.PlotObjectConfig.availableFontNames),
		    {
		    	xtype : 'toolbar',
		    	bodyStyle: { background : '#dfe8f6' },  
				border: false,
		    	items : [
		    	      {
		    	    	  xtype: 'numberfield',
		    	    	  name: namePrefix+'-size',
		    	    	  fieldLabel: 'Size',
		    	    	  labelWidth: 60,
		    	    	  width: 150,
		    	    	  maxValue: 32,
		    	          minValue: 6,
		    	          value: 12,
		    	    	  listeners: {
		    	    		  change: function(field, newValue, oldValue, eOpts) {
		    	    			  this.object.set(namePrefix+'-size', newValue);
		    	    		  },
		    	    		  scope: this
		    	    	  }
		    	      },
		    	      ' ',
		    	      {
		    	    	  xtype: 'checkbox',
		    	    	  name: namePrefix+'-bold',
		    	    	  boxLabel: '<b>B</b>',
		    	    	  width: 30,
		    	    	  listeners: {
		    	    		  change: function(combo, newValue, oldValue, eOpts) {
		    	            		this.object.set(namePrefix+'-bold', newValue);
		    	    		  },
		    	    		  scope: this
		    	    	  }
		    	      },
		    	      {
		    	    	  xtype: 'checkbox',
		    	    	  name: namePrefix+'-italic',
		    	    	  boxLabel: '<i>I</i>',
		    	    	  width: 30,
		    	    	  listeners: {
		    	    		  change: function(combo, newValue, oldValue, eOpts) {
		    	            		this.object.set(namePrefix+'-italic', newValue);
		    	    		  },
		    	    		  scope: this
		    	    	  }
		    	      }
		    	]
		    }
		];
		
		return this.addStandardFieldSet('Font', namePrefix+'-activated', fontItems);
	},
	
	addStandardColor: function(name, label, availableData, onChange) {
		var comboStore = Ext.create('Ext.data.Store', {
		    fields: ['color', 'value'],
		    data : availableData
		});
		
		return {
        	xtype: 'combo',
        	name: name,
        	fieldLabel: label,
        	store: comboStore,
        	queryMode: 'local',
            displayField: 'value',
            valueField: 'color',
abe09878   Benjamin Renard   Add panels and ax...
296
            editable: false,
437c4dbc   Benjamin Renard   First implementat...
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
            tpl: Ext.create('Ext.XTemplate',
            		'<ul class="x-list-plain"><tpl for=".">',
            		'<li role="option" class="x-boundlist-item" style="color: {color};">{value}</li>',
            		'</tpl></ul>'
            ),
            // template for the content inside text field
            displayTpl: Ext.create('Ext.XTemplate',
            		'<tpl for=".">',
            			'{value}',
            		 '</tpl>'
            ),
            
            
            listeners: {
            	change: function(combo, newValue, oldValue, eOpts) {
            		this.object.set(name, newValue);
            		if (onChange != null)
a8c54fb9   Benjamin Renard   Add text object p...
314
            			onChange(name, newValue, oldValue);
437c4dbc   Benjamin Renard   First implementat...
315
316
317
318
319
320
            	},
            	scope: this
            }
        };
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
321
	addStandardParamDropTarget: function(name, label, onChange) {
17433635   Benjamin Renard   Add series and sp...
322
		return {
7ef7ea02   Benjamin Renard   Add erase button ...
323
	        xtype: 'erasetrigger',
17433635   Benjamin Renard   Add series and sp...
324
325
	        name: name,
	        fieldLabel: label,
17433635   Benjamin Renard   Add series and sp...
326
327
328
329
	        emptyText: 'Drop a parameter',
	        listeners: {
            	change: function(field, newValue, oldValue, eOpts) {
            		this.object.set(name, newValue);
dbb7bcbe   Benjamin Renard   Add curves defint...
330
331
            		if (onChange != null)
            			onChange(name, newValue, oldValue);
17433635   Benjamin Renard   Add series and sp...
332
333
334
335
336
337
338
339
340
            	},
            	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];
7ef7ea02   Benjamin Renard   Add erase button ...
341
342
343
            						switch (selectedRecord.$className)
            						{
            						case 'amdaModel.LocalParamNode'   :	  
0cefcae2   Benjamin Renard   il reste click droit
344
345
            			    	 	                    case 'amdaModel.RemoteParamNode'  :
            			    	 	                    case 'amdaModel.RemoteSimuParamNode'  : 
7ef7ea02   Benjamin Renard   Add erase button ...
346
347
348
349
            			    	 		if (!selectedRecord.get('isParameter') || selectedRecord.get('disable'))
            			    	 			return false;
            			    	 		if (selectedRecord.get('alias') != "" )
            			    	 			field.setValue("#"+selectedRecord.get('alias'));
0cefcae2   Benjamin Renard   il reste click droit
350
351
            			                                                            else
            			                	                                        field.setValue(selectedRecord.get('id'));
7ef7ea02   Benjamin Renard   Add erase button ...
352
            			    	 		return true;
0cefcae2   Benjamin Renard   il reste click droit
353
            			    	 	                    case 'amdaModel.AliasNode'        :
7ef7ea02   Benjamin Renard   Add erase button ...
354
355
356
357
            			    	 		if (!selectedRecord.isLeaf())
            			    	 			return false;
            			    	 		field.setValue("#"+selectedRecord.get('text'));
            			    	 		return true;
0cefcae2   Benjamin Renard   il reste click droit
358
            			    	 	                    case 'amdaModel.DerivedParamNode' :
7ef7ea02   Benjamin Renard   Add erase button ...
359
360
361
362
363
364
365
366
367
            			    	 		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;
0cefcae2   Benjamin Renard   il reste click droit
368
            					                         default :
7ef7ea02   Benjamin Renard   Add erase button ...
369
370
            						    return false;
            						}
17433635   Benjamin Renard   Add series and sp...
371
372
373
374
375
376
377
378
379
380
            						return true;
            					}
            				}
            		);
            	},
            	scope: this
            }
	    };
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
381
	addStandardDate: function(name, label, onChange) {
6a801541   Benjamin Renard   Add possibility t...
382
383
384
385
386
387
388
389
390
391
		return { 
            xtype: 'datefield',
            name: name,
            format: 'Y/m/d H:i:s',
            enforceMaxLength : true,
            maxLength: 19,
            fieldLabel: label,
            listeners: {
                change: function(field, newValue, oldValue, eOpts) {
            		this.object.set(name, newValue);
dbb7bcbe   Benjamin Renard   Add curves defint...
392
393
            		if (onChange != null)
            			onChange(name, newValue, oldValue);
6a801541   Benjamin Renard   Add possibility t...
394
395
396
397
398
399
            	},
                scope : this
            } 
        };
	},
	
24b02d83   Benjamin Renard   Add definition of...
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
	addStandardLineItems: function(namePrefix) {
		return [
		    this.addStandardCombo(namePrefix+'-style', 'Style', amdaPlotObj.PlotObjectConfig.availableLinesStyles),
		    this.addStandardFloat(namePrefix+'-width', 'Width', 1, 10),
		    this.addStandardColor(namePrefix+'-color', 'Color', amdaPlotObj.PlotObjectConfig.availableColors)
		];
	},
	
	addStandardSymbolsItems: function(namePrefix) {
		return [
		    this.addStandardCombo(namePrefix+'-type', 'Type', amdaPlotObj.PlotObjectConfig.availableSymbolsTypes),
		    this.addStandardFloat(namePrefix+'-size', 'Size', 1, 10),
		    this.addStandardColor(namePrefix+'-color', 'Color', amdaPlotObj.PlotObjectConfig.availableColors)
        ];
	},
	
437c4dbc   Benjamin Renard   First implementat...
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
	init : function(config) {
		var me = this;
		
		var myConf = {
				bodyPadding: 5,
				bodyStyle: { background : '#dfe8f6' },  
				border: false,
				layout: {
				    type: 'vbox',
				    pack: 'start',
				    align: 'stretch'
				},
				items: this.getFormItems()
		};
		
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
e0648247   Benjamin Renard   Set decimal preci...
433
});