Blame view

js/app/views/PlotComponents/PlotStandardForm.js 11.2 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
23
24
25
26
27
28

	//Object associated to this form
	object: null,

	//Link to the tree
	crtTree: null,
	desableTickNumber: true,
	desableTickSpacing: true,

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

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

437c4dbc   Benjamin Renard   First implementat...
38
	//To override to add form components
4dbd97ec   Menouard AZIB   Goal is reached b...
39
	getFormItems: function () {
437c4dbc   Benjamin Renard   First implementat...
40
41
		return [];
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
42

0a295c3e   Benjamin Renard   Dynamic load of p...
43
	//Function called after element creation by PlotElementPanel
4dbd97ec   Menouard AZIB   Goal is reached b...
44
45
46
47
48
49
50
	updateElement: function (onAfterUpdate) {
		if (onAfterUpdate)
			onAfterUpdate();
	},

	//
	addStandardText: function (name, label, onChange) {
437c4dbc   Benjamin Renard   First implementat...
51
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
52
53
54
55
56
57
58
59
60
61
62
63
			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...
64
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
65
66

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

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

a3ed599f   Hacene SI HADJ MOHAND   rm 6954 ok
90
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
			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...
109
	},
afb7b464   Benjamin Renard   Fix decimal preci...
110

4dbd97ec   Menouard AZIB   Goal is reached b...
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 {
afb7b464   Benjamin Renard   Fix decimal preci...
115
116
117
			xtype: 'textfield',
			name: name,
			fieldLabel: label,
4dbd97ec   Menouard AZIB   Goal is reached b...
118
119
			regex: /[-+]?(?:\d*\.?\d+|\d+\.?\d*)(?:[eE][-+]?\d+)?/,
			hidden: (hidden) ? true : false,
afb7b464   Benjamin Renard   Fix decimal preci...
120
121
122
123
124
125
126
127
128
129
130
			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;
				}
4dbd97ec   Menouard AZIB   Goal is reached b...
131

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

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

437c4dbc   Benjamin Renard   First implementat...
151
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
			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...
169
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
170
171

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

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

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

	addStandardFont: function (namePrefix) {
437c4dbc   Benjamin Renard   First implementat...
233
		var fontItems = [
4dbd97ec   Menouard AZIB   Goal is reached b...
234
235
236
237
			this.addStandardCombo(namePrefix + '-name', 'Name', amdaPlotObj.PlotObjectConfig.availableFontNames),
			{
				xtype: 'toolbar',
				bodyStyle: { background: '#dfe8f6' },
437c4dbc   Benjamin Renard   First implementat...
238
				border: false,
4dbd97ec   Menouard AZIB   Goal is reached b...
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
				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...
283
		];
4dbd97ec   Menouard AZIB   Goal is reached b...
284
285

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

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

437c4dbc   Benjamin Renard   First implementat...
294
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
			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...
325
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
326
327

	addStandardParamDropTarget: function (name, label, onChange) {
17433635   Benjamin Renard   Add series and sp...
328
		return {
4dbd97ec   Menouard AZIB   Goal is reached b...
329
330
331
332
333
334
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
			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...
364
									case 'amdaModel.DerivedParamComponentNode':
4dbd97ec   Menouard AZIB   Goal is reached b...
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
										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...
385
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

	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...
404
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
405
406

	addStandardLineItems: function (namePrefix) {
24b02d83   Benjamin Renard   Add definition of...
407
		return [
4dbd97ec   Menouard AZIB   Goal is reached b...
408
409
			this.addStandardCombo(namePrefix + '-style', 'Style', amdaPlotObj.PlotObjectConfig.availableLinesStyles),
			this.addStandardFloat(namePrefix + '-width', 'Width', 1, 10),
f34c9c5a   Benjamin Renard   Finalize color pi...
410
                        this.addColorsPicker(namePrefix + '-color', 'Color', amdaPlotObj.PlotObjectConfig.availableColorsNew, 'auto')
24b02d83   Benjamin Renard   Add definition of...
411
412
		];
	},
4dbd97ec   Menouard AZIB   Goal is reached b...
413
414

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

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

437c4dbc   Benjamin Renard   First implementat...
435
		var myConf = {
4dbd97ec   Menouard AZIB   Goal is reached b...
436
437
438
439
440
441
442
443
444
			bodyPadding: 5,
			bodyStyle: { background: '#dfe8f6' },
			border: false,
			layout: {
				type: 'vbox',
				pack: 'start',
				align: 'stretch'
			},
			items: this.getFormItems()
437c4dbc   Benjamin Renard   First implementat...
445
		};
4dbd97ec   Menouard AZIB   Goal is reached b...
446
447

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