source: ether_statistics/web/visualization/visu_simulation-script.jsp @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

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