Blame view

js/app/views/PlotComponents/PlotStandardForm.js 9.29 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * 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 : [                
		        'amdaPlotObj.PlotObjectConfig'
	],
	
    //Object associated to this form
    object: null,
    
17433635   Benjamin Renard   Add series and sp...
21
22
23
    //Link to the tree
    crtTree: null,
    
437c4dbc   Benjamin Renard   First implementat...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
    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 [];
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
39
	addStandardText: function(name, label, onChange) {
437c4dbc   Benjamin Renard   First implementat...
40
41
42
43
44
45
46
		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...
47
48
            		if (onChange != null)
            			onChange(name, newValue, oldValue);
437c4dbc   Benjamin Renard   First implementat...
49
50
51
52
53
54
            	},
            	scope: this
            }
        };
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
55
	addStandardFloat: function(name, label, min, max, allowBlank, onChange) {
003ba315   Benjamin Renard   Add Epoch Plot an...
56
57
		allowBlank = (typeof allowBlank !== 'undefined') ? allowBlank : false;
		
437c4dbc   Benjamin Renard   First implementat...
58
59
60
61
62
63
64
		return {
	        xtype: 'numberfield',
	        name: name,
	        fieldLabel: label,
	        decimalPrecision : 3,
	        minValue         : min,
	        maxValue         : max,
003ba315   Benjamin Renard   Add Epoch Plot an...
65
	        allowBlank       : allowBlank,
437c4dbc   Benjamin Renard   First implementat...
66
67
68
	        listeners: {
            	change: function(field, newValue, oldValue, eOpts) {
            		this.object.set(name, newValue);
dbb7bcbe   Benjamin Renard   Add curves defint...
69
70
            		if (onChange != null)
            			onChange(name, newValue, oldValue);
437c4dbc   Benjamin Renard   First implementat...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
            	},
            	scope: this
            }
	    };
	},
	
	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...
91
            editable: false,
437c4dbc   Benjamin Renard   First implementat...
92
93
94
95
            listeners: {
            	change: function(combo, newValue, oldValue, eOpts) {
            		this.object.set(name, newValue);
            		if (onChange != null)
a8c54fb9   Benjamin Renard   Add text object p...
96
            			onChange(name, newValue, oldValue);
437c4dbc   Benjamin Renard   First implementat...
97
98
99
100
101
102
            	},
            	scope: this
            }
        };
	},
	
003ba315   Benjamin Renard   Add Epoch Plot an...
103
	addStandardCheck: function(name, label, onChange) {
437c4dbc   Benjamin Renard   First implementat...
104
105
106
107
108
109
110
		return {
        	xtype: 'checkbox',
        	name: name,
        	boxLabel: label,
            listeners: {
            	change: function(combo, newValue, oldValue, eOpts) {
            		this.object.set(name, newValue);
003ba315   Benjamin Renard   Add Epoch Plot an...
111
            		if (onChange != null)
a8c54fb9   Benjamin Renard   Add text object p...
112
            			onChange(name, newValue, oldValue);
437c4dbc   Benjamin Renard   First implementat...
113
114
115
116
117
118
            	},
            	scope: this
            }
        };
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
119
	addStandardFieldSet: function(title, checkboxName, items, onChangeCheck) {
437c4dbc   Benjamin Renard   First implementat...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
		return {
        	xtype: 'fieldset',
        	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...
136
					{
437c4dbc   Benjamin Renard   First implementat...
137
						this.object.set(checkboxName, true);
dbb7bcbe   Benjamin Renard   Add curves defint...
138
139
140
						if (onChangeCheck != null)
							onChangeCheck(checkboxName, true, false);
					}
437c4dbc   Benjamin Renard   First implementat...
141
142
143
				},
				collapse: function(fieldset, eOpts) {
					if (checkboxName != '')
dbb7bcbe   Benjamin Renard   Add curves defint...
144
					{
437c4dbc   Benjamin Renard   First implementat...
145
						this.object.set(checkboxName, false);
dbb7bcbe   Benjamin Renard   Add curves defint...
146
147
148
						if (onChangeCheck != null)
							onChangeCheck(checkboxName, false, true);
					}
437c4dbc   Benjamin Renard   First implementat...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
				},
				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...
225
            editable: false,
437c4dbc   Benjamin Renard   First implementat...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
            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...
243
            			onChange(name, newValue, oldValue);
437c4dbc   Benjamin Renard   First implementat...
244
245
246
247
248
249
            	},
            	scope: this
            }
        };
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
250
	addStandardParamDropTarget: function(name, label, onChange) {
17433635   Benjamin Renard   Add series and sp...
251
252
253
254
255
256
257
258
259
		return {
	        xtype: 'textfield',
	        name: name,
	        fieldLabel: label,
	        readOnly: true,
	        emptyText: 'Drop a parameter',
	        listeners: {
            	change: function(field, newValue, oldValue, eOpts) {
            		this.object.set(name, newValue);
dbb7bcbe   Benjamin Renard   Add curves defint...
260
261
            		if (onChange != null)
            			onChange(name, newValue, oldValue);
17433635   Benjamin Renard   Add series and sp...
262
263
264
265
266
267
268
269
270
271
272
            	},
            	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];

            						field.setValue(selectedRecord.get('id'));
dbb7bcbe   Benjamin Renard   Add curves defint...
273
            						
17433635   Benjamin Renard   Add series and sp...
274
275
276
277
278
279
280
281
282
283
            						return true;
            					}
            				}
            		);
            	},
            	scope: this
            }
	    };
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
284
	addStandardDate: function(name, label, onChange) {
6a801541   Benjamin Renard   Add possibility t...
285
286
287
288
289
290
291
292
293
294
		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...
295
296
            		if (onChange != null)
            			onChange(name, newValue, oldValue);
6a801541   Benjamin Renard   Add possibility t...
297
298
299
300
301
302
            	},
                scope : this
            } 
        };
	},
	
24b02d83   Benjamin Renard   Add definition of...
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
	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...
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
	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));
	}
});