1 | <%@ page import="com.ether.EtherPlotServiceImpl" %> |
---|
2 | <script type="text/javascript"> |
---|
3 | var InterfaceSimulation = Class.create( { |
---|
4 | |
---|
5 | initialize: function( jsonSimulations ) |
---|
6 | { |
---|
7 | // Values |
---|
8 | this.jsonSimulations = jsonSimulations || null; |
---|
9 | this.selectedModel = false; |
---|
10 | this.selectedVariable = false; |
---|
11 | this.beginDate = false; |
---|
12 | this.endDate = false; |
---|
13 | |
---|
14 | /** *********** CONTAINERS *********** **/ |
---|
15 | this.containerModels = $( "#containerModels" ); |
---|
16 | this.containerVariables = $( "#containerVariables" ); |
---|
17 | this.containerButtons = $( "#containerButtons" ); |
---|
18 | this.containerOptionDates = $( "#containerOptionDates" ); |
---|
19 | this.containerOptionLevels = $( "#containerOptionLevels" ); |
---|
20 | this.containerOptionTypes = $( "#containerOptionTypes" ); |
---|
21 | this.containerPlateforms = $( "#containerSimulationPlateforms" ); |
---|
22 | |
---|
23 | /** *********** LOADING *********** **/ |
---|
24 | // Create loading object for plateforms |
---|
25 | var param = new Object(); |
---|
26 | param.parent = this.containerModels; |
---|
27 | this.loadingModels = new Loading( param ); |
---|
28 | this.loadingModels.display(); |
---|
29 | |
---|
30 | param.parent = this.containerVariables; |
---|
31 | this.loadingVariables = new Loading( param ); |
---|
32 | this.loadingVariables.display(); |
---|
33 | |
---|
34 | param.parent = this.containerPlateforms; |
---|
35 | this.loadingPlateforms = new Loading( param ); |
---|
36 | |
---|
37 | this.createOptions(); |
---|
38 | this.displayModels(); |
---|
39 | }, |
---|
40 | |
---|
41 | // CREATES ******************************************************** |
---|
42 | createOptions: function() |
---|
43 | { |
---|
44 | // Type select |
---|
45 | this.containerOptionTypes.empty(); |
---|
46 | var paramSelect = new Object(); |
---|
47 | paramSelect.parent = this.containerOptionTypes; |
---|
48 | this.selectTypes = new Select( paramSelect ); |
---|
49 | this.selectTypes.add( false, interfaceTexts["simulation.raster"] ); |
---|
50 | this.selectTypes.add( true, interfaceTexts["simulation.raster_contour"] ); |
---|
51 | this.selectTypes.selectFirst( false ); |
---|
52 | |
---|
53 | // Bind checkbox displayRealData |
---|
54 | $( "#displayRealData" ).live( "change", jQuery.proxy( this.onCheckRealData, this ) ); |
---|
55 | $( "#displayRealData" ).attr( "disabled", true ); |
---|
56 | |
---|
57 | // Visualize Button |
---|
58 | this.visualizeButton = new Button( {value:interfaceTexts["simulation.button.visualize"], parent:this.containerButtons, id:"button_visualize", onClick:jQuery.proxy( this.onClickVisualize, this )} ); |
---|
59 | this.visualizeButton.disable(); |
---|
60 | }, |
---|
61 | |
---|
62 | createSelectDates:function() |
---|
63 | { |
---|
64 | if( !this.selectedModel ) |
---|
65 | return; |
---|
66 | |
---|
67 | this.containerOptionDates.empty(); |
---|
68 | |
---|
69 | var paramSelect = new Object(); |
---|
70 | paramSelect.parent = this.containerOptionDates; |
---|
71 | this.selectDates = new Select( paramSelect ); |
---|
72 | jQuery.each( this.selectedModel.jsonElement.dates, jQuery.proxy( function ( i, date ) |
---|
73 | { |
---|
74 | this.selectDates.add( i, date ); |
---|
75 | }, this ) ); |
---|
76 | this.selectDates.selectFirst( false ); |
---|
77 | }, |
---|
78 | |
---|
79 | createSelectLevels: function() |
---|
80 | { |
---|
81 | if( !this.selectedModel ) |
---|
82 | return; |
---|
83 | |
---|
84 | this.containerOptionLevels.empty(); |
---|
85 | |
---|
86 | var paramSelect = new Object(); |
---|
87 | paramSelect.parent = this.containerOptionLevels; |
---|
88 | this.selectLevels = new Select( paramSelect ); |
---|
89 | jQuery.each( this.selectedModel.jsonElement.levels, jQuery.proxy( function ( i, level ) |
---|
90 | { |
---|
91 | this.selectLevels.add( i, level ); |
---|
92 | }, this ) ); |
---|
93 | this.selectLevels.selectFirst( false ); |
---|
94 | }, |
---|
95 | |
---|
96 | // REQUESTS ******************************************************** |
---|
97 | requestVariablesByModel: function() |
---|
98 | { |
---|
99 | if( this.selectedModel ) |
---|
100 | $.ajax( { |
---|
101 | url: "simulation?methodName=searchVariablesByModel&id=" + this.selectedModel.getId(), |
---|
102 | success:jQuery.proxy( this.handleVariablesBySelectedModel, this ) |
---|
103 | } ); |
---|
104 | }, |
---|
105 | |
---|
106 | requestPlateformsByVariable: function() |
---|
107 | { |
---|
108 | this.loadingPlateforms.display(); |
---|
109 | if( this.selectedVariable ) |
---|
110 | $.ajax( { |
---|
111 | url: "simulation?methodName=searchMobilePlateformsByVariable&code=" + this.selectedVariable.getName(), |
---|
112 | success:jQuery.proxy( this.handlePlateformsByVariable, this ) |
---|
113 | } ); |
---|
114 | }, |
---|
115 | |
---|
116 | // HANDLES ******************************************************** |
---|
117 | handleVariablesBySelectedModel: function( result ) |
---|
118 | { |
---|
119 | this.jsonVariables = jQuery.parseJSON( result ).variables; |
---|
120 | this.displayVariables(); |
---|
121 | }, |
---|
122 | |
---|
123 | handlePlateformsByVariable: function( result ) |
---|
124 | { |
---|
125 | this.jsonPlateforms = jQuery.parseJSON( result ).plateforms; |
---|
126 | this.displayPlateforms(); |
---|
127 | }, |
---|
128 | |
---|
129 | // DISPLAYS ******************************************************** |
---|
130 | displayModels: function() |
---|
131 | { |
---|
132 | var models = new ListModels( this.jsonSimulations, new Object() ); |
---|
133 | |
---|
134 | models.addOpenListener( jQuery.proxy( this.onSelectModel, this ) ); |
---|
135 | this.loadingModels.hide(); |
---|
136 | models.display( this.containerModels, "NoModel", interfaceTexts["simulation.noModel"] ); |
---|
137 | |
---|
138 | // Select the first model by default |
---|
139 | if( models && models.array && models.array[0] ) |
---|
140 | { |
---|
141 | var modelToSelect = models.getItemById( models.array[0].jsonElement.id ); |
---|
142 | this.onSelectModel( modelToSelect.divItem ); |
---|
143 | this.selectedModel = modelToSelect.divItem; |
---|
144 | } |
---|
145 | }, |
---|
146 | |
---|
147 | displayVariables: function() |
---|
148 | { |
---|
149 | var variables = new ListVariables( this.jsonVariables, new Object() ); |
---|
150 | |
---|
151 | variables.addOpenListener( jQuery.proxy( this.onSelectVariable, this ) ); |
---|
152 | this.loadingVariables.hide(); |
---|
153 | variables.display( this.containerVariables, "NoVariable", interfaceTexts["visualization.noVariable"] ); |
---|
154 | }, |
---|
155 | |
---|
156 | displayPlateforms: function() |
---|
157 | { |
---|
158 | this.loadingPlateforms.hide(); |
---|
159 | |
---|
160 | if( 0 < this.jsonPlateforms.length ) |
---|
161 | { |
---|
162 | var paramSelect = new Object(); |
---|
163 | paramSelect.parent = this.containerPlateforms; |
---|
164 | this.selectPlateforms = new Select( paramSelect ); |
---|
165 | jQuery.each( this.jsonPlateforms, jQuery.proxy( function ( i, plateform ) |
---|
166 | { |
---|
167 | this.selectPlateforms.add( plateform.id, plateform.name ); |
---|
168 | }, this ) ); |
---|
169 | this.selectPlateforms.selectFirst( false ); |
---|
170 | } |
---|
171 | else |
---|
172 | this.containerPlateforms.html( interfaceTexts["simulation.noRealData"] ); |
---|
173 | }, |
---|
174 | |
---|
175 | // EVENTS ******************************************************** |
---|
176 | onSelectModel: function( objModel ) |
---|
177 | { |
---|
178 | if( this.selectedModel && objModel.getId() == this.selectedModel.getId() ) |
---|
179 | return; |
---|
180 | |
---|
181 | // Unselect old model |
---|
182 | if( this.selectedModel ) |
---|
183 | this.selectedModel.unselect(); |
---|
184 | |
---|
185 | this.selectedModel = objModel; |
---|
186 | this.selectedModel.select(); |
---|
187 | |
---|
188 | // Unselect old variable |
---|
189 | if( this.selectedVariable ) |
---|
190 | this.selectedVariable = false; |
---|
191 | |
---|
192 | // Unselect old plateform |
---|
193 | this.selectPlateforms = false; |
---|
194 | |
---|
195 | // Change title |
---|
196 | $( "#textareaTitle" ).html( this.selectedModel.getName() + " _ " + this.selectedModel.jsonElement.version ); |
---|
197 | |
---|
198 | this.createSelectDates(); |
---|
199 | this.createSelectLevels(); |
---|
200 | this.requestVariablesByModel(); |
---|
201 | this.testAllFields(); |
---|
202 | }, |
---|
203 | |
---|
204 | onSelectVariable: function( objVariable ) |
---|
205 | { |
---|
206 | if( this.selectedVariable && objVariable.getId() == this.selectedVariable.getId() ) |
---|
207 | return; |
---|
208 | |
---|
209 | // Unselect old variable |
---|
210 | if( this.selectedVariable ) |
---|
211 | this.selectedVariable.unselect(); |
---|
212 | |
---|
213 | this.selectedVariable = objVariable; |
---|
214 | this.selectedVariable.select(); |
---|
215 | |
---|
216 | // Unselect old plateform |
---|
217 | this.selectPlateforms = false; |
---|
218 | |
---|
219 | // Change title |
---|
220 | $( "#textareaTitle" ).html( this.selectedModel.getName() + " _ " + this.selectedModel.jsonElement.version + " - " + this.selectedVariable.getName() ); |
---|
221 | |
---|
222 | // Init plateforms |
---|
223 | this.containerPlateforms.empty(); |
---|
224 | $( "#displayRealData" ).attr( "checked", false ); |
---|
225 | |
---|
226 | this.testAllFields(); |
---|
227 | }, |
---|
228 | |
---|
229 | onCheckRealData: function() |
---|
230 | { |
---|
231 | if( $( "#displayRealData" ).attr( 'checked' ) ) |
---|
232 | this.requestPlateformsByVariable(); |
---|
233 | else |
---|
234 | this.containerPlateforms.empty(); |
---|
235 | }, |
---|
236 | |
---|
237 | onClickVisualize: function() |
---|
238 | { |
---|
239 | if( this.selectedModel && this.selectedVariable ) |
---|
240 | { |
---|
241 | var parameters = "dateBegin=" + this.beginDate |
---|
242 | + "&dateEnd=" + this.endDate |
---|
243 | + "&modelId=" + this.selectedModel.getId() |
---|
244 | + "&variableId=" + this.selectedVariable.getId() |
---|
245 | + "&variableName=" + this.selectedVariable.getName() |
---|
246 | + "&dateNumber=" + this.selectDates.getValue() |
---|
247 | + "&date=" + this.selectDates.getName() |
---|
248 | + "&level=" + this.selectLevels.getValue() |
---|
249 | + "&isRasterContour=" + this.selectTypes.getValue() |
---|
250 | + "&isRealDataToDisplay=" + $( "#displayRealData" ).attr( 'checked' ) |
---|
251 | + "&title=" + encodeURIComponent( $( "#textareaTitle" ).val() ); |
---|
252 | |
---|
253 | if( this.selectPlateforms && this.selectPlateforms.getValue() ) |
---|
254 | parameters += "&plateformId=" + this.selectPlateforms.getValue(); |
---|
255 | |
---|
256 | var url = "simulation/simulationPlotEther?" + parameters; |
---|
257 | var $dialog = $( '<div></div>' ) |
---|
258 | .html( '<img src=' + url + ' />' ) |
---|
259 | .dialog( { |
---|
260 | autoOpen: false, |
---|
261 | title: interfaceTexts["app.title"] + "-" + interfaceTexts["simulation.quicklook"], |
---|
262 | minHeight: <%=EtherPlotServiceImpl.getMaxHeight()%>, |
---|
263 | minWidth: <%=EtherPlotServiceImpl.getMaxWidth()%> + 28 |
---|
264 | } ); |
---|
265 | } |
---|
266 | else |
---|
267 | { |
---|
268 | var $dialog = $( '<div></div>' ) |
---|
269 | .html( '<BR/><center>' + interfaceTexts["visualization.graph.noPlot"] + '</center>' ) |
---|
270 | .dialog( { |
---|
271 | autoOpen: false, |
---|
272 | title: interfaceTexts["app.title"] + "-" + interfaceTexts["visualization.quicklook"], |
---|
273 | height: 50, |
---|
274 | width: 400 |
---|
275 | } ); |
---|
276 | } |
---|
277 | |
---|
278 | $dialog.dialog( 'open' ); |
---|
279 | }, |
---|
280 | |
---|
281 | // OTHERS ******************************************************** |
---|
282 | testAllFields: function() |
---|
283 | { |
---|
284 | if( !this.selectedModel || !this.selectedVariable ) |
---|
285 | { |
---|
286 | this.visualizeButton.disable(); |
---|
287 | $( "#displayRealData" ).attr( "checked", false ); |
---|
288 | $( "#displayRealData" ).attr( "disabled", true ); |
---|
289 | return; |
---|
290 | } |
---|
291 | |
---|
292 | this.visualizeButton.enable(); |
---|
293 | $( "#displayRealData" ).attr( "disabled", false ); |
---|
294 | } |
---|
295 | |
---|
296 | } ); |
---|
297 | |
---|
298 | </script> |
---|