Blame view

js/app/views/PlotComponents/PlotElementPanel.js 4.38 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
 * Project   : AMDA-NG
 * Name      : PlotElementPanel.js
 * @class   amdaPlotComp.PlotElementPanel
 * @extends Ext.form.Panel
 * @brief   Element of a plot request definition
 * @author  Benjamin Renard
 * @version $Id: PlotElementPanel.js benjamin $
 */

Ext.define('amdaPlotComp.PlotElementPanel', {
	extend: 'Ext.form.Panel',
	
abe09878   Benjamin Renard   Add panels and ax...
14
15
	elementFormsManager : new Ext.AbstractManager(),
	
abe09878   Benjamin Renard   Add panels and ax...
16
17
	crtTree   : null,
	
437c4dbc   Benjamin Renard   First implementat...
18
19
20
21
22
	constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
	},
	
a971060f   Benjamin Renard   Fix some bugs
23
24
25
26
27
28
29
	destroy: function() {
		this.elementFormsManager.each(function (key, value, length) {
			this.elementFormsManager.unregister(value);
    	}, this);
		this.callParent();
	},
	
abe09878   Benjamin Renard   Add panels and ax...
30
31
	setElement: function(type, object, tree) {
		this.removeAll(false);
437c4dbc   Benjamin Renard   First implementat...
32
		
17433635   Benjamin Renard   Add series and sp...
33
		this.crtTree   = tree;
437c4dbc   Benjamin Renard   First implementat...
34
		
dbb7bcbe   Benjamin Renard   Add curves defint...
35
36
37
38
39
40
41
		var me =this;
		this.getElementForm(type, function (elementForm) {
			me.add(elementForm);
			elementForm.crtTree = tree;
			if (elementForm.setObject)
				elementForm.setObject(object);
		});
437c4dbc   Benjamin Renard   First implementat...
42
43
44
	},
	
	resetElement: function() {
17433635   Benjamin Renard   Add series and sp...
45
		this.setElement('',null,null);
abe09878   Benjamin Renard   Add panels and ax...
46
47
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
48
	getElementForm: function(type, onFormReady) {
abe09878   Benjamin Renard   Add panels and ax...
49
50
51
		var formId = type;
		if (type == '')
			formId = 'none';
17433635   Benjamin Renard   Add series and sp...
52

abe09878   Benjamin Renard   Add panels and ax...
53
		formId += '-element-form';
dbb7bcbe   Benjamin Renard   Add curves defint...
54
55
56
		
		if (this.rendered)
			this.getEl().mask();
17433635   Benjamin Renard   Add series and sp...
57
			
dbb7bcbe   Benjamin Renard   Add curves defint...
58
		var me = this;
abe09878   Benjamin Renard   Add panels and ax...
59
60
61
		if (!this.elementFormsManager.get(formId))
		{
			//Create element form
0a295c3e   Benjamin Renard   Dynamic load of p...
62
63
			var element_name = '';
			var element_text = '';
abe09878   Benjamin Renard   Add panels and ax...
64
65
66
			switch (type)
			{
			case 'page' :
0a295c3e   Benjamin Renard   Dynamic load of p...
67
				element_name = 'amdaPlotComp.PlotPageForm';
abe09878   Benjamin Renard   Add panels and ax...
68
69
				break;
			case 'panel' :
0a295c3e   Benjamin Renard   Dynamic load of p...
70
				element_name = 'amdaPlotComp.PlotPanelForm';
abe09878   Benjamin Renard   Add panels and ax...
71
72
				break;
			case 'time-axis' :
0a295c3e   Benjamin Renard   Dynamic load of p...
73
				element_name = 'amdaPlotComp.PlotTimeAxisForm';
abe09878   Benjamin Renard   Add panels and ax...
74
75
				break;
			case 'epoch-axis' :
0a295c3e   Benjamin Renard   Dynamic load of p...
76
				element_name = 'amdaPlotComp.PlotEpochAxisForm';
abe09878   Benjamin Renard   Add panels and ax...
77
78
				break;
			case 'color-axis' :
0a295c3e   Benjamin Renard   Dynamic load of p...
79
				element_name = 'amdaPlotComp.PlotColorAxisForm';
abe09878   Benjamin Renard   Add panels and ax...
80
81
82
83
				break;
			case 'x-axis' :
			case 'y-left-axis' :
			case 'y-right-axis' :
0a295c3e   Benjamin Renard   Dynamic load of p...
84
				element_name = 'amdaPlotComp.PlotBaseAxisForm';
abe09878   Benjamin Renard   Add panels and ax...
85
				break;
17433635   Benjamin Renard   Add series and sp...
86
			case 'param' :
0a295c3e   Benjamin Renard   Dynamic load of p...
87
				element_name = 'amdaPlotComp.PlotParamForm';
17433635   Benjamin Renard   Add series and sp...
88
				break;
003ba315   Benjamin Renard   Add Epoch Plot an...
89
			case 'layout' :
0a295c3e   Benjamin Renard   Dynamic load of p...
90
				element_name = 'amdaPlotComp.PlotLayoutForm';
003ba315   Benjamin Renard   Add Epoch Plot an...
91
				break;
94abdb37   Benjamin Renard   Add params legend...
92
			case 'series-legend' :
0a295c3e   Benjamin Renard   Dynamic load of p...
93
				element_name = 'amdaPlotComp.PlotLegendSeriesForm';
94abdb37   Benjamin Renard   Add params legend...
94
				break;
339866c4   Benjamin Renard   Add text legend d...
95
			case 'text-legend' :
0a295c3e   Benjamin Renard   Dynamic load of p...
96
				element_name = 'amdaPlotComp.PlotLegendTextForm';
339866c4   Benjamin Renard   Add text legend d...
97
98
				break;
			case 'text-legends' :
0a295c3e   Benjamin Renard   Dynamic load of p...
99
				element_name = 'amdaPlotComp.PlotLegendsTextForm';
339866c4   Benjamin Renard   Add text legend d...
100
				break;
829160b3   Benjamin Renard   Add constants def...
101
			case 'drawing-objects' :
0a295c3e   Benjamin Renard   Dynamic load of p...
102
				element_name = 'amdaPlotComp.PlotDrawingObjectForm';
829160b3   Benjamin Renard   Add constants def...
103
104
				break;
			case 'constant' :
0a295c3e   Benjamin Renard   Dynamic load of p...
105
				element_name = 'amdaPlotComp.PlotConstantForm';
829160b3   Benjamin Renard   Add constants def...
106
				break;
a8c54fb9   Benjamin Renard   Add text object p...
107
			case 'text-obj' :
0a295c3e   Benjamin Renard   Dynamic load of p...
108
				element_name = 'amdaPlotComp.PlotTextForm';
dbb7bcbe   Benjamin Renard   Add curves defint...
109
110
				break;
			case 'curve' :
0a295c3e   Benjamin Renard   Dynamic load of p...
111
				element_name = 'amdaPlotComp.PlotCurveForm';
a8c54fb9   Benjamin Renard   Add text object p...
112
				break;
486cc3c7   Benjamin Renard   Add fill elements...
113
			case 'fills' :
0a295c3e   Benjamin Renard   Dynamic load of p...
114
				element_name = 'amdaPlotComp.PlotFillsForm';
486cc3c7   Benjamin Renard   Add fill elements...
115
116
				break;
			case 'fill' :
0a295c3e   Benjamin Renard   Dynamic load of p...
117
				element_name = 'amdaPlotComp.PlotFillForm';
486cc3c7   Benjamin Renard   Add fill elements...
118
				break;
abe09878   Benjamin Renard   Add panels and ax...
119
			case '' :
0a295c3e   Benjamin Renard   Dynamic load of p...
120
121
				element_name = 'Ext.form.Label';
				element_text = 'Select an element in the tree to show options';
abe09878   Benjamin Renard   Add panels and ax...
122
123
				break;
			default :
0a295c3e   Benjamin Renard   Dynamic load of p...
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
				element_name = 'Ext.form.Label';
				element_text = 'No available options for this element';
			}
			
			var create_func = function() {
				var formArgs = {
						id: formId
				};
				
				if (element_text != '')
					formArgs.text = element_text;
				
				var new_element_form = Ext.create(element_name, formArgs);
				me.elementFormsManager.register(new_element_form);
				
				if (new_element_form.updateElement) {
					new_element_form.updateElement(function () {
						if (onFormReady != null)
							onFormReady(me.elementFormsManager.get(formId));
						if (me.rendered)
							me.getEl().unmask();
					});
				}
				else {
					if (onFormReady != null)
						onFormReady(me.elementFormsManager.get(formId));
					if (me.rendered)
						me.getEl().unmask();
				}
			};
			
			if (!Ext.ClassManager.get(element_name)) {
				var me = this;
				//Load class source code
				Ext.require(element_name, function() {
					//Create element
					create_func();
				});
abe09878   Benjamin Renard   Add panels and ax...
162
			}
0a295c3e   Benjamin Renard   Dynamic load of p...
163
164
165
166
			else
				//Create element
				create_func();
				
dbb7bcbe   Benjamin Renard   Add curves defint...
167
			return;
abe09878   Benjamin Renard   Add panels and ax...
168
		}
dbb7bcbe   Benjamin Renard   Add curves defint...
169
170
171
172
173
174
		
		if (this.rendered)
			this.getEl().unmask();
		
		if (onFormReady != null)
			onFormReady(this.elementFormsManager.get(formId));
437c4dbc   Benjamin Renard   First implementat...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
	},
	
	init : function(config) {
		var me = this;
		
		var myConf = {
				title : 'Selected element options',
	        	bodyStyle: { background : '#dfe8f6' },
	        	autoScroll: true,
				defaults: {
					border: false
				}
		};
		
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
});