1 | <script type="text/javascript"> |
---|
2 | var InterfaceTapas = Class.create( { |
---|
3 | |
---|
4 | initialize: function( jsonFileFormats, jsonYesNos, jsonObservatories ) |
---|
5 | { |
---|
6 | /** *********** CONTAINERS *********** **/ |
---|
7 | this.containerForm = $( "#formulaire" ); |
---|
8 | this.containerErrors = $( "#errors" ); |
---|
9 | |
---|
10 | this.jsonFileFormats = jsonFileFormats || null; |
---|
11 | this.jsonYesNos = jsonYesNos || null; |
---|
12 | this.jSonObservatories = jsonObservatories || null; |
---|
13 | //this.jSonSelectUnits = jsonSelectUnits || null; |
---|
14 | |
---|
15 | this.containerErrors.hide(); |
---|
16 | |
---|
17 | this.createForm(); |
---|
18 | |
---|
19 | }, |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | // CREATES ******************************************************** |
---|
24 | createCalendar: function( containerCalendar ) |
---|
25 | { |
---|
26 | // Create input for date text |
---|
27 | var inputDateId = "iobservation_date"; |
---|
28 | var inputDate = $( document.createElement( "input" ) ); |
---|
29 | inputDate.attr( {id:inputDateId, size:"17"} ); |
---|
30 | containerCalendar.append( inputDate ); |
---|
31 | |
---|
32 | // Calendar |
---|
33 | this.calendarFormat = "%Y-%m-%d %H:%i:%s"; |
---|
34 | this.calendarConverter = new AnyTime.Converter( { format: this.calendarFormat } ); |
---|
35 | |
---|
36 | AnyTime.picker( inputDateId, { format: this.calendarFormat, firstDOW: 1, |
---|
37 | labelTitle: "Select Date", labelYear: "Year", labelMonth: "Month", labelDayOfMonth: "Day", |
---|
38 | labelHour: "Hour", labelMinute: "Minute", labelSecond: "Second" |
---|
39 | } ); |
---|
40 | |
---|
41 | var currentDate = new Date(); |
---|
42 | $( "#observationDate" ).val( this.calendarConverter.format( currentDate ) ); |
---|
43 | }, |
---|
44 | |
---|
45 | createTr: function( texte, inputId, container ) |
---|
46 | { |
---|
47 | var tr = $( document.createElement( "tr" ) ); |
---|
48 | var td1 = $( document.createElement( "td" ) ); |
---|
49 | var td2 = $( document.createElement( "td" ) ); |
---|
50 | var input = $( document.createElement( "input" ) ); |
---|
51 | |
---|
52 | |
---|
53 | input.attr( {id: inputId} ); |
---|
54 | td1.html( texte ); |
---|
55 | tr.append( td1 ); |
---|
56 | td2.append( input ); |
---|
57 | tr.append( td2 ); |
---|
58 | container.append( tr ); |
---|
59 | }, |
---|
60 | |
---|
61 | |
---|
62 | createTrList: function( texte, inputId, container, type ) |
---|
63 | { |
---|
64 | var tr = $( document.createElement( "tr" ) ); |
---|
65 | var td1 = $( document.createElement( "td" ) ); |
---|
66 | var td2 = $( document.createElement( "td" ) ); |
---|
67 | var input = $( document.createElement( "input" ) ); |
---|
68 | |
---|
69 | input.attr( {id: inputId} ); |
---|
70 | td1.html( texte ); |
---|
71 | tr.append( td1 ); |
---|
72 | if( type == 'format' ) this.displayFileFormats( td2 ); |
---|
73 | else if( type == 'yesno' ) this.displayYesNo( td2, inputId ); |
---|
74 | else if( type == 'observatories' ) this.displayObservatories( td2 ); |
---|
75 | else if( type == 'spectralUnit' ) this.displaySpectralUnits( td2 ); |
---|
76 | |
---|
77 | tr.append( td2 ); |
---|
78 | container.append( tr ); |
---|
79 | }, |
---|
80 | |
---|
81 | |
---|
82 | createForm: function() |
---|
83 | { |
---|
84 | |
---|
85 | //Creation div / tab |
---|
86 | var divPreference = $( document.createElement( "div" ) ); |
---|
87 | var tabPreference = $( document.createElement( "table" ) ); |
---|
88 | |
---|
89 | var divObservation = $( document.createElement( "div" ) ); |
---|
90 | var tabObservation = $( document.createElement( "table" ) ); |
---|
91 | |
---|
92 | this.createTrList( "File format", "iformat", tabPreference, 'format' ); |
---|
93 | this.createTr( "Rayleigh extinction", "irextinction", tabPreference ); |
---|
94 | this.createTrList( "H20 extinction", "ih2oe", tabPreference, 'yesno' ); |
---|
95 | this.createTrList( "O3 extinction", "io3e", tabPreference, 'yesno' ); |
---|
96 | this.createTrList( "O2 extinction", "io2e", tabPreference, 'yesno' ); |
---|
97 | this.createTrList( "CO2 extinction", "ico2e", tabPreference, 'yesno' ); |
---|
98 | |
---|
99 | this.createTrList( "Observatory", "iobservatory", tabObservation, 'observatories' ); |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | this.createCalendar( tabObservation ); |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | this.createTr( "Right LOS ascension", "ira", tabObservation ); |
---|
108 | this.createTr( "LOS declension", "ide", tabObservation ); |
---|
109 | this.createTr( "Zenith angle", "iza", tabObservation ); |
---|
110 | // this.createTrList("Spectral unit", "ispectral_choice", tabObservation, 'spectralUnit'); |
---|
111 | this.createTr( "Spectral range", "ispectral_ranger", tabObservation ); |
---|
112 | |
---|
113 | |
---|
114 | divPreference.append( tabPreference ); |
---|
115 | this.containerForm.append( divPreference ); |
---|
116 | |
---|
117 | divObservation.append( tabObservation ); |
---|
118 | this.containerForm.append( divObservation ); |
---|
119 | |
---|
120 | //jQuery.proxy permet d'envoyer le contexte this courant |
---|
121 | var submitButton = new Button( {value:tapasTexts["label.submitButton"], parent:this.containerForm, id:"button_submit", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickSubmit, this )} ); |
---|
122 | |
---|
123 | }, |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | // REQUESTS ******************************************************** |
---|
128 | requestCreateXML: function() |
---|
129 | { |
---|
130 | var tapasForm = this.createTapasObject(); |
---|
131 | //passage de javascript a json grace au jquery |
---|
132 | var jsonTapasForm = $.toJSON( tapasForm ); |
---|
133 | |
---|
134 | if( jsonTapasForm ) |
---|
135 | $.ajax( { |
---|
136 | url: "data?methodName=createUserRequest&jsonTapas=" + jsonTapasForm, |
---|
137 | success:jQuery.proxy( this.handleCreateXML, this ), |
---|
138 | error: jQuery.proxy( this.showErrors, this ) |
---|
139 | } ); |
---|
140 | }, |
---|
141 | |
---|
142 | // HANDLES ******************************************************** = retours ajax |
---|
143 | handleCreateXML: function( result ) |
---|
144 | { |
---|
145 | var bob = jQuery.parseJSON( result ).result; |
---|
146 | alert( bob ); |
---|
147 | }, |
---|
148 | |
---|
149 | |
---|
150 | // EVENTS ******************************************************** |
---|
151 | onClickSubmit: function() |
---|
152 | { |
---|
153 | this.containerErrors.hide(); |
---|
154 | this.requestCreateXML(); |
---|
155 | }, |
---|
156 | |
---|
157 | |
---|
158 | // OTHERS ******************************************************** |
---|
159 | displayFileFormats: function( container ) |
---|
160 | { |
---|
161 | var paramSelect = new Object(); |
---|
162 | paramSelect.id = "select_formats"; |
---|
163 | paramSelect.parent = container; |
---|
164 | this.selectFormats = new Select( paramSelect ); |
---|
165 | jQuery.each( this.jsonFileFormats, jQuery.proxy( function ( i, jsonFileFormat ) |
---|
166 | { |
---|
167 | this.selectFormats.add( jsonFileFormat.value, jsonFileFormat.text ); |
---|
168 | }, this ) ); |
---|
169 | this.selectFormats.selectFirst( false ); |
---|
170 | }, |
---|
171 | |
---|
172 | |
---|
173 | displayYesNo: function( container, name ) |
---|
174 | { |
---|
175 | var paramSelect = new Object(); |
---|
176 | paramSelect.id = "select_" + name; |
---|
177 | paramSelect.parent = container; |
---|
178 | this.selectYesNos = new Select( paramSelect ); |
---|
179 | jQuery.each( this.jsonYesNos, jQuery.proxy( function ( i, jsonYesNo ) |
---|
180 | { |
---|
181 | this.selectYesNos.add( jsonYesNo.value, jsonYesNo.text ); |
---|
182 | }, this ) ); |
---|
183 | this.selectYesNos.selectFirst( false ); |
---|
184 | }, |
---|
185 | |
---|
186 | |
---|
187 | displayObservatories: function( container ) |
---|
188 | { |
---|
189 | var paramSelect = new Object(); |
---|
190 | paramSelect.id = "select_observatory"; |
---|
191 | paramSelect.parent = container; |
---|
192 | this.selectObservatories = new Select( paramSelect ); |
---|
193 | //ajouter select vide avec add |
---|
194 | this.selectObservatories.add( "-1", "-- Select an observatory --" ); |
---|
195 | jQuery.each( this.jSonObservatories, jQuery.proxy( function ( i, jsonObservatory ) |
---|
196 | { |
---|
197 | this.selectObservatories.add( jsonObservatory.id, jsonObservatory.name ); |
---|
198 | }, this ) ); |
---|
199 | this.selectObservatories.selectFirst( true ); |
---|
200 | }, |
---|
201 | |
---|
202 | |
---|
203 | displaySpectralUnits: function( container ) |
---|
204 | { |
---|
205 | var paramSelect = new Object(); |
---|
206 | paramSelect.id = "select_spectral_unit"; |
---|
207 | paramSelect.parent = container; |
---|
208 | this.selectSpectralUnits = new Select( paramSelect ); |
---|
209 | //ajouter select vide avec add |
---|
210 | this.selectSpectralUnits.add( "-1", "-- Select unit --" ); |
---|
211 | jQuery.each( this.jSonSpectralUnit, jQuery.proxy( function ( i, jsonSpectralUnit ) |
---|
212 | { |
---|
213 | this.selectSpectralUnits.add( jsonSpectralUnit.id, jsonSpectralUnit.name ); |
---|
214 | }, this ) ); |
---|
215 | this.selectSpectralUnits.selectFirst( true ); |
---|
216 | }, |
---|
217 | |
---|
218 | showErrors: function( result ) |
---|
219 | { |
---|
220 | this.containerErrors.show(); |
---|
221 | this.containerErrors.html( tapasTexts[result.responseText] ); |
---|
222 | }, |
---|
223 | |
---|
224 | createTapasObject: function() |
---|
225 | { |
---|
226 | // PREFERENCE |
---|
227 | var preference = new Object(); |
---|
228 | |
---|
229 | preference.format = new Object(); |
---|
230 | //toutes les valeurs possibles |
---|
231 | //preference.format.firstValue = $( "#select_formats" ).val(); |
---|
232 | preference.format.firstValue = this.selectFormats.getValues(); |
---|
233 | //la valeur selectionnee |
---|
234 | preference.format.secondValue = this.selectFormats.getValue(); |
---|
235 | |
---|
236 | |
---|
237 | var pair = new Object(); |
---|
238 | pair.firstValue = "YES,NO"; |
---|
239 | pair.secondValue = this.selectFormats.getValue(); |
---|
240 | |
---|
241 | preference.rayleighExtinction = new Object(); |
---|
242 | ; |
---|
243 | preference.h2oExtinction = pair; |
---|
244 | preference.o3Extinction = pair; |
---|
245 | preference.o2Extinction = pair; |
---|
246 | preference.co2Extinction = pair; |
---|
247 | |
---|
248 | // OBSERVATION |
---|
249 | // Observatory |
---|
250 | var observatory = new Object(); |
---|
251 | //observatory.name = this.selectFormats.name; |
---|
252 | |
---|
253 | observatory.longitude = this.longitude.value; |
---|
254 | observatory.latitude = this.latitude.value; |
---|
255 | observatory.altitude = this.altitude.value; |
---|
256 | |
---|
257 | |
---|
258 | // Los |
---|
259 | var los = new Object(); |
---|
260 | los.raJ2000 = "04:32:43"; |
---|
261 | los.decJ2000 = "-43:12:10.22"; |
---|
262 | |
---|
263 | los.zenithAngle = new Object(); |
---|
264 | los.zenithAngle.min = "0"; |
---|
265 | los.zenithAngle.max = "90"; |
---|
266 | los.zenithAngle.value = 60; |
---|
267 | |
---|
268 | // Instrument |
---|
269 | var instrument = new Object(); |
---|
270 | |
---|
271 | instrument.spectralChoice = new Object(); |
---|
272 | instrument.spectralChoice.firstValue = "Vacuum Wavelength (nm),Standard Wavelength (nm),Wavenumber (cm-1)"; |
---|
273 | instrument.spectralChoice.secondValue = "Standard Wavelength (nm)"; |
---|
274 | instrument.spectralRange = "1180 1200"; |
---|
275 | instrument.ilsfChoice = new Object(); |
---|
276 | instrument.ilsfChoice.firstValue = "-1,0,1"; |
---|
277 | instrument.ilsfChoice.secondValue = 0; |
---|
278 | instrument.ilsfPath = "/home/ferron/tmp/tapas/ilsf.txt"; |
---|
279 | instrument.resolvingPower = new Object(); |
---|
280 | instrument.resolvingPower.firstValue = "0"; |
---|
281 | instrument.resolvingPower.secondValue = 1000000; |
---|
282 | instrument.samplingRatio = new Object(); |
---|
283 | instrument.samplingRatio.firstValue = "0"; |
---|
284 | instrument.samplingRatio.secondValue = 3; |
---|
285 | |
---|
286 | var observation = new Object(); |
---|
287 | observation.date = this.calendarConverter.parse( $( "#iobservation_date" ).val() ).getTime(); |
---|
288 | observation.observatory = observatory; |
---|
289 | observation.los = los; |
---|
290 | observation.instrument = instrument; |
---|
291 | |
---|
292 | // ATMOSPHERE |
---|
293 | var atmosphere = new Object(); |
---|
294 | atmosphere.reference = new Object(); |
---|
295 | atmosphere.reference.firstValue = "0,1,2,3,4,5,6"; |
---|
296 | atmosphere.reference.secondValue = 6; |
---|
297 | |
---|
298 | atmosphere.arlettyFile = new Array(); |
---|
299 | atmosphere.arlettyFile[0] = "/home/ferron/tmp/tapas/Reims_070402.ARL.txt"; |
---|
300 | atmosphere.arlettyFile[1] = "/home/ferron/tmp/tapas/Reims_070402.ARL.txt22"; |
---|
301 | |
---|
302 | atmosphere.ecmwfFile = new Array(); |
---|
303 | atmosphere.ecmwfFile[0] = "/home/ferron/tmp/tapas/ecmwf12.txt"; |
---|
304 | |
---|
305 | |
---|
306 | // REQUEST |
---|
307 | var request = new Object(); |
---|
308 | request.id = 1; |
---|
309 | request.preference = preference; |
---|
310 | request.observation = observation; |
---|
311 | request.atmosphere = atmosphere; |
---|
312 | |
---|
313 | var requests = new Array(); |
---|
314 | requests[0] = request; |
---|
315 | |
---|
316 | // TAPAS |
---|
317 | var tapas = new Object(); |
---|
318 | tapas.id = "Ether_TAPAS_0000001"; |
---|
319 | tapas.requests = requests; |
---|
320 | |
---|
321 | return tapas; |
---|
322 | } |
---|
323 | |
---|
324 | } ); |
---|
325 | |
---|
326 | |
---|
327 | </script> |
---|