Blame view

js/app/views/PlotComponents/PlotStandardForm.js 11.6 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
/**
 * 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',
4dbd97ec   Menouard AZIB   Goal is reached b...
13
14
15

	requires: [
		'amdaPlotObj.PlotObjectConfig',
ba2fd748   Hacene SI HADJ MOHAND   selector ok
16
		'amdaPlotComp.EraseTrigger',
f34c9c5a   Benjamin Renard   Finalize color pi...
17
                'amdaPlotComp.PlotColorPicker'
437c4dbc   Benjamin Renard   First implementat...
18
	],
4dbd97ec   Menouard AZIB   Goal is reached b...
19
20
21
22

	//Object associated to this form
	object: null,

59d845ce   Benjamin Renard   Keep parentObject...
23
24
	parentObject: null,

4dbd97ec   Menouard AZIB   Goal is reached b...
25
26
27
28
29
30
	//Link to the tree
	crtTree: null,
	desableTickNumber: true,
	desableTickSpacing: true,

	constructor: function (config) {
437c4dbc   Benjamin Renard   First implementat...
31
32
33
		this.init(config);
		this.callParent(arguments);
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
34
35

	setObject: function (object) {
437c4dbc   Benjamin Renard   First implementat...
36
37
38
		this.object = object;
		this.loadRecord(this.object);
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
39

59d845ce   Benjamin Renard   Keep parentObject...
40
41
42
43
	setParentObject: function (parentObject) {
		this.parentObject = parentObject;
	},

437c4dbc   Benjamin Renard   First implementat...
44
	//To override to add form components
4dbd97ec   Menouard AZIB   Goal is reached b...
45
	getFormItems: function () {
437c4dbc   Benjamin Renard   First implementat...
46
47
		return [];
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
48

0a295c3e   Benjamin Renard   Dynamic load of p...
49
	//Function called after element creation by PlotElementPanel
4dbd97ec   Menouard AZIB   Goal is reached b...
50
51
52
53
54
55
56
	updateElement: function (onAfterUpdate) {
		if (onAfterUpdate)
			onAfterUpdate();
	},

	//
	addStandardText: function (name, label, onChange) {
437c4dbc   Benjamin Renard   First implementat...
57
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
58
59
60
61
62
63
64
65
66
67
68
69
			xtype: 'textfield',
			name: name,
			fieldLabel: label,
			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...
70
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
71
72

	addStandardFloat: function (name, label, min, max, allowBlank, onChange) {
003ba315   Benjamin Renard   Add Epoch Plot an...
73
		allowBlank = (typeof allowBlank !== 'undefined') ? allowBlank : false;
4dbd97ec   Menouard AZIB   Goal is reached b...
74

437c4dbc   Benjamin Renard   First implementat...
75
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
			xtype: 'numberfield',
			name: name,
			fieldLabel: label,
			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);
				},
				scope: this
			}
		};
a3ed599f   Hacene SI HADJ MOHAND   rm 6954 ok
92
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
93
	addStandardInteger: function (name, label, min, max, allowBlank, hidden, onChange) {
a3ed599f   Hacene SI HADJ MOHAND   rm 6954 ok
94
		allowBlank = (typeof allowBlank !== 'undefined') ? allowBlank : false;
4dbd97ec   Menouard AZIB   Goal is reached b...
95

a3ed599f   Hacene SI HADJ MOHAND   rm 6954 ok
96
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
			xtype: 'numberfield',
			name: name,
			fieldLabel: label,
			hidden: (hidden) ? true : false,
			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);
				},
				scope: this
			}
		};
437c4dbc   Benjamin Renard   First implementat...
115
	},
afb7b464   Benjamin Renard   Fix decimal preci...
116

4dbd97ec   Menouard AZIB   Goal is reached b...
117
	addStandardFloat2: function (name, label, min, max, allowBlank, hidden, onChange) {
6e83f9b9   Erdogan Furkan   Done
118
		allowBlank = (typeof allowBlank !== 'undefined' || allowBlank == null) ? allowBlank : false;
afb7b464   Benjamin Renard   Fix decimal preci...
119
120

		return {
afb7b464   Benjamin Renard   Fix decimal preci...
121
122
123
			xtype: 'textfield',
			name: name,
			fieldLabel: label,
4dbd97ec   Menouard AZIB   Goal is reached b...
124
125
			regex: /[-+]?(?:\d*\.?\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/,
			hidden: (hidden) ? true : false,
afb7b464   Benjamin Renard   Fix decimal preci...
126
127
128
129
130
			validator: function (val) {
				var errMsg = null;
				if (!allowBlank && Ext.isEmpty(val)) {
					errMsg = 'Blank value not allowed';
				}
6e83f9b9   Erdogan Furkan   Done
131
				else if ((typeof min !== 'undefined' &&  min !== null) && (parseFloat(val) < min)) {
afb7b464   Benjamin Renard   Fix decimal preci...
132
133
					errMsg = 'Min. allowed value is ' + min;
				}
6e83f9b9   Erdogan Furkan   Done
134
				else if ((typeof max !== 'undefined' && max !== null) && (parseFloat(val) > max)) {
afb7b464   Benjamin Renard   Fix decimal preci...
135
136
					errMsg = 'Max. allowed value is ' + max;
				}
4dbd97ec   Menouard AZIB   Goal is reached b...
137

afb7b464   Benjamin Renard   Fix decimal preci...
138
139
140
				return errMsg ? errMsg : true;
			},
			listeners: {
4dbd97ec   Menouard AZIB   Goal is reached b...
141
				change: function (field, newValue, oldValue, eOpts) {
afb7b464   Benjamin Renard   Fix decimal preci...
142
143
144
145
146
147
148
149
					this.object.set(name, newValue);
					if (onChange != null)
						onChange(name, newValue, oldValue);
				},
				scope: this
			}
		};
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
150
151

	addStandardCombo: function (name, label, availableData, onChange) {
437c4dbc   Benjamin Renard   First implementat...
152
		var comboStore = Ext.create('Ext.data.Store', {
4dbd97ec   Menouard AZIB   Goal is reached b...
153
154
			fields: [amdaPlotObj.PlotObjectConfig.fieldComboBox.key, amdaPlotObj.PlotObjectConfig.fieldComboBox.value],
			data: availableData
437c4dbc   Benjamin Renard   First implementat...
155
		});
4dbd97ec   Menouard AZIB   Goal is reached b...
156

437c4dbc   Benjamin Renard   First implementat...
157
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
			xtype: 'combo',
			name: name,
			fieldLabel: label,
			store: comboStore,
			queryMode: 'local',
			displayField: 'value',
			valueField: 'key',
			editable: false,
			listeners: {
				change: function (combo, newValue, oldValue, eOpts) {
					if (onChange != null)
						onChange(name, newValue, oldValue);
					this.object.set(name, newValue);
				},
				scope: this
			}
		};
437c4dbc   Benjamin Renard   First implementat...
175
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
176
177

	addStandardCheck: function (name, label, onChange, tooltip) {
d1bed2e2   Benjamin Renard   Change Isotropic ...
178

437c4dbc   Benjamin Renard   First implementat...
179
		return {
d1bed2e2   Benjamin Renard   Change Isotropic ...
180
181
182
183
			xtype: 'checkbox',
			name: name,
			boxLabel: label,
			listeners: {
4dbd97ec   Menouard AZIB   Goal is reached b...
184
				change: function (combo, newValue, oldValue, eOpts) {
d1bed2e2   Benjamin Renard   Change Isotropic ...
185
186
187
188
					this.object.set(name, newValue);
					if (onChange != null)
						onChange(name, newValue, oldValue);
				},
4dbd97ec   Menouard AZIB   Goal is reached b...
189
				render: function (c) {
d1bed2e2   Benjamin Renard   Change Isotropic ...
190
191
192
193
					if (tooltip) {
						Ext.create('Ext.tip.ToolTip', {
							target: c.getEl(),
							dismissDelay: 0,
4dbd97ec   Menouard AZIB   Goal is reached b...
194
							html: tooltip
d1bed2e2   Benjamin Renard   Change Isotropic ...
195
196
197
198
199
200
						});
					}
				},
				scope: this
			}
		};
437c4dbc   Benjamin Renard   First implementat...
201
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
202

f34c9c5a   Benjamin Renard   Finalize color pi...
203
	addStandardFieldSet: function (title, checkboxName, items, onChangeCheck) {
437c4dbc   Benjamin Renard   First implementat...
204
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
205
206
207
208
			xtype: 'fieldset',
			cls: 'child-fieldset',
			title: title,
			collapsible: true,
f34c9c5a   Benjamin Renard   Finalize color pi...
209
			collapsed: true,
4dbd97ec   Menouard AZIB   Goal is reached b...
210
211
212
213
214
215
			checkboxName: checkboxName,
			checkboxToggle: checkboxName != '',
			layout: {
				type: 'vbox',
				pack: 'start',
				align: 'stretch'
437c4dbc   Benjamin Renard   First implementat...
216
217
218
			},
			items: items,
			listeners: {
4dbd97ec   Menouard AZIB   Goal is reached b...
219
220
				expand: function (fieldset, eOpts) {
					if (checkboxName != '') {
437c4dbc   Benjamin Renard   First implementat...
221
						this.object.set(checkboxName, true);
dbb7bcbe   Benjamin Renard   Add curves defint...
222
223
224
						if (onChangeCheck != null)
							onChangeCheck(checkboxName, true, false);
					}
437c4dbc   Benjamin Renard   First implementat...
225
				},
4dbd97ec   Menouard AZIB   Goal is reached b...
226
227
				collapse: function (fieldset, eOpts) {
					if (checkboxName != '') {
437c4dbc   Benjamin Renard   First implementat...
228
						this.object.set(checkboxName, false);
dbb7bcbe   Benjamin Renard   Add curves defint...
229
230
231
						if (onChangeCheck != null)
							onChangeCheck(checkboxName, false, true);
					}
437c4dbc   Benjamin Renard   First implementat...
232
233
234
				},
				scope: this
			}
4dbd97ec   Menouard AZIB   Goal is reached b...
235
		};
437c4dbc   Benjamin Renard   First implementat...
236
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
237
238

	addStandardFont: function (namePrefix) {
437c4dbc   Benjamin Renard   First implementat...
239
		var fontItems = [
4f728fd9   Erdogan Furkan   For now 2
240
			this.addStandardCombo(namePrefix + '-name', 'Name', amdaDefaultConfigs.availableFontNames),
4dbd97ec   Menouard AZIB   Goal is reached b...
241
242
243
			{
				xtype: 'toolbar',
				bodyStyle: { background: '#dfe8f6' },
437c4dbc   Benjamin Renard   First implementat...
244
				border: false,
4dbd97ec   Menouard AZIB   Goal is reached b...
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
				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
						}
					}
				]
			}
437c4dbc   Benjamin Renard   First implementat...
289
		];
4dbd97ec   Menouard AZIB   Goal is reached b...
290
291

		return this.addStandardFieldSet('Font', namePrefix + '-activated', fontItems);
437c4dbc   Benjamin Renard   First implementat...
292
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
293
294

	addStandardColor: function (name, label, availableData, onChange) {
437c4dbc   Benjamin Renard   First implementat...
295
		var comboStore = Ext.create('Ext.data.Store', {
4dbd97ec   Menouard AZIB   Goal is reached b...
296
297
			fields: ['color', 'value'],
			data: availableData
437c4dbc   Benjamin Renard   First implementat...
298
		});
4dbd97ec   Menouard AZIB   Goal is reached b...
299

437c4dbc   Benjamin Renard   First implementat...
300
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
			xtype: 'combo',
			name: name,
			fieldLabel: label,
			store: comboStore,
			queryMode: 'local',
			displayField: 'value',
			valueField: 'color',
			editable: false,
			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)
						onChange(name, newValue, oldValue);
				},
				scope: this
			}
		};
437c4dbc   Benjamin Renard   First implementat...
331
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
332
333

	addStandardParamDropTarget: function (name, label, onChange) {
17433635   Benjamin Renard   Add series and sp...
334
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
			xtype: 'erasetrigger',
			name: name,
			fieldLabel: label,
			emptyText: 'Drop a parameter',
			listeners: {
				change: function (field, newValue, oldValue, eOpts) {
					this.object.set(name, newValue);
					if (onChange != null)
						onChange(name, newValue, oldValue);
				},
				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':
5a4eed99   Benjamin Renard   Split param compo...
370
									case 'amdaModel.DerivedParamComponentNode':
4dbd97ec   Menouard AZIB   Goal is reached b...
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
										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
			}
		};
17433635   Benjamin Renard   Add series and sp...
391
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409

	addStandardDate: function (name, label, onChange) {
		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);
					if (onChange != null)
						onChange(name, newValue, oldValue);
				},
				scope: this
			}
		};
6a801541   Benjamin Renard   Add possibility t...
410
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
411
412

	addStandardLineItems: function (namePrefix) {
24b02d83   Benjamin Renard   Add definition of...
413
		return [
4f728fd9   Erdogan Furkan   For now 2
414
			this.addStandardCombo(namePrefix + '-style', 'Style', amdaDefaultConfigs.availableLinesStyles),
4dbd97ec   Menouard AZIB   Goal is reached b...
415
			this.addStandardFloat(namePrefix + '-width', 'Width', 1, 10),
4f728fd9   Erdogan Furkan   For now 2
416
                        this.addColorsPicker(namePrefix + '-color', 'Color', amdaDefaultConfigs.availableColorsNew, 'auto')
24b02d83   Benjamin Renard   Add definition of...
417
418
		];
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
419
420

	addStandardSymbolsItems: function (namePrefix) {
24b02d83   Benjamin Renard   Add definition of...
421
		return [
4f728fd9   Erdogan Furkan   For now 2
422
			this.addStandardCombo(namePrefix + '-type', 'Type', amdaDefaultConfigs.availableSymbolsTypes),
4dbd97ec   Menouard AZIB   Goal is reached b...
423
			this.addStandardFloat(namePrefix + '-size', 'Size', 1, 10),
4f728fd9   Erdogan Furkan   For now 2
424
			this.addColorsPicker(namePrefix + '-color', 'Color', amdaDefaultConfigs.availableColorsNew, 'auto')
4dbd97ec   Menouard AZIB   Goal is reached b...
425
		];
24b02d83   Benjamin Renard   Add definition of...
426
	},
48fdb91e   Hacene SI HADJ MOHAND   us ok pour lines ...
427
        
f34c9c5a   Benjamin Renard   Finalize color pi...
428
429
430
431
	addColorsPicker: function (name, label, availableColors, mode) {
		if (!mode) {
			mode = 'standard';
		}
7faaee3c   Benjamin Renard   wip
432
		var me =this;
f34c9c5a   Benjamin Renard   Finalize color pi...
433
		return new amdaPlotComp.PlotColorPicker({name: name, label: label, mode: mode, colors: availableColors, onChange: function(name, newValue, oldValue) {
7faaee3c   Benjamin Renard   wip
434
			me.object.set(name, newValue);
7faaee3c   Benjamin Renard   wip
435
		}});
ba2fd748   Hacene SI HADJ MOHAND   selector ok
436
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
437

9162d169   Benjamin Renard   Add symbolic link...
438
	addColorMapCombo: function (name, onChange) {
1c1417db   Benjamin Renard   Fix bug after merge
439
		var me = this;
9b67ae6b   Benjamin Renard   Merge FER_10934 i...
440
441
		return {
			xtype: 'colormap',
9162d169   Benjamin Renard   Add symbolic link...
442
			name: name,
1c1417db   Benjamin Renard   Fix bug after merge
443
			size: 26,
b350c87a   Benjamin Renard   Fix color map sel...
444
			hideFieldLabel: false,
1c1417db   Benjamin Renard   Fix bug after merge
445
446
447
448
			onValueChange: function(name, newValue, oldValue) {
				me.object.set(name, newValue);
				if (onChange != null)
					onChange(name, newValue, oldValue);
9b67ae6b   Benjamin Renard   Merge FER_10934 i...
449
450
			}
		};
9162d169   Benjamin Renard   Add symbolic link...
451
452
	},

4dbd97ec   Menouard AZIB   Goal is reached b...
453
	init: function (config) {
437c4dbc   Benjamin Renard   First implementat...
454
		var me = this;
4dbd97ec   Menouard AZIB   Goal is reached b...
455

437c4dbc   Benjamin Renard   First implementat...
456
		var myConf = {
4dbd97ec   Menouard AZIB   Goal is reached b...
457
458
459
460
461
462
463
464
465
			bodyPadding: 5,
			bodyStyle: { background: '#dfe8f6' },
			border: false,
			layout: {
				type: 'vbox',
				pack: 'start',
				align: 'stretch'
			},
			items: this.getFormItems()
437c4dbc   Benjamin Renard   First implementat...
466
		};
4dbd97ec   Menouard AZIB   Goal is reached b...
467
468

		Ext.apply(this, Ext.apply(arguments, myConf));
437c4dbc   Benjamin Renard   First implementat...
469
	}
e0648247   Benjamin Renard   Set decimal preci...
470
});