1 | <script type="text/javascript"> |
---|
2 | |
---|
3 | |
---|
4 | var InterfaceTapas = Class.create( { |
---|
5 | |
---|
6 | initialize: function( jsonFileFormats, jsonYesNos, jsonObservatories, jsonSpectralUnits, jsonInstrumentalFunctions, jsonClimatoReferences ) |
---|
7 | { |
---|
8 | /** *********** CONTAINERS *********** **/ |
---|
9 | this.containerForm = $( "#formulaire" ); |
---|
10 | this.containerErrors = $( "#errForm" ); |
---|
11 | this.containerCenter = $( "#containerCenter" ); |
---|
12 | this.containerTabs = $( "#tab" ); |
---|
13 | |
---|
14 | /** *********** VARIABLES *********** **/ |
---|
15 | this.jSonFileFormats = jsonFileFormats || null; |
---|
16 | this.jSonYesNos = jsonYesNos || null; |
---|
17 | this.jSonObservatories = jsonObservatories || false; |
---|
18 | this.jSonSpectralUnits = jsonSpectralUnits || null; |
---|
19 | this.jSonInstrumentalFunctions = jsonInstrumentalFunctions || null; |
---|
20 | this.jSonClimatoReferences = jsonClimatoReferences || null; |
---|
21 | this.nbRequest = 1; |
---|
22 | this.tabActive = false; |
---|
23 | this.numRequest = 1; |
---|
24 | |
---|
25 | var submitButton = new Button( {value:tapasTexts["label.submitButton"], parent:this.containerCenter, id:"button_submit", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickSubmit, this )} ); |
---|
26 | this.addRequestButton = new Button( {value:tapasTexts["label.addButton"], parent:this.containerCenter, id:"button_add", className: "positive", onClick:jQuery.proxy( this.onClickAdd, this )} ); |
---|
27 | this.delRequestButton = new Button( {value:tapasTexts["label.delButton"], parent:this.containerCenter, id:"button_del", className: "negative", onClick:jQuery.proxy( this.onClickDel, this )} ); |
---|
28 | this.delRequestButton.disable(); |
---|
29 | |
---|
30 | this.createForm(); |
---|
31 | this.tabActive = this.createTab(); |
---|
32 | |
---|
33 | this.containerErrors.hide(); |
---|
34 | }, |
---|
35 | |
---|
36 | |
---|
37 | // CREATES ******************************************************** |
---|
38 | createTab:function() |
---|
39 | { |
---|
40 | var ntab = new Tab( {value:tapasTexts["label.requete"] + " " + this.nbRequest, parent:this.containerTabs, numTab: this.nbRequest, id:"tab_request" + this.nbRequest, className: "tab_class", onClick:jQuery.proxy( this.onClickTab, this )} ); |
---|
41 | ntab.active(); |
---|
42 | return ntab; |
---|
43 | }, |
---|
44 | |
---|
45 | |
---|
46 | createCalendar: function( containerCalendar, texte, inputDateId, currentDate, isTrToCreate ) |
---|
47 | { |
---|
48 | if( isTrToCreate ) |
---|
49 | { |
---|
50 | // Create input for date text |
---|
51 | var tr = $( document.createElement( "tr" ) ); |
---|
52 | var td1 = $( document.createElement( "td" ) ); |
---|
53 | var td2 = $( document.createElement( "td" ) ); |
---|
54 | var inputDate = $( document.createElement( "input" ) ); |
---|
55 | inputDate.attr( {id:inputDateId, size:"17"} ); |
---|
56 | |
---|
57 | td1.html( texte ); |
---|
58 | td1.attr( { class:"containerLabel" } ); |
---|
59 | tr.append( td1 ); |
---|
60 | |
---|
61 | td2.attr( {colspan:4} ); |
---|
62 | td2.append( inputDate ); |
---|
63 | tr.append( td2 ); |
---|
64 | containerCalendar.append( tr ); |
---|
65 | } |
---|
66 | |
---|
67 | // Calendar |
---|
68 | this.calendarFormat = "%Y-%m-%d %H:%i:%s"; |
---|
69 | this.calendarConverter = new AnyTime.Converter( { format: this.calendarFormat } ); |
---|
70 | |
---|
71 | AnyTime.picker( inputDateId, { format: this.calendarFormat, firstDOW: 1, |
---|
72 | labelTitle: "Select Date", labelYear: "Year", labelMonth: "Month", labelDayOfMonth: "Day", |
---|
73 | labelHour: "Hour", labelMinute: "Minute", labelSecond: "Second" |
---|
74 | } ); |
---|
75 | |
---|
76 | // Ajout de la date courrante ds le calendrier SI currentDate non précisée |
---|
77 | if( !currentDate ) |
---|
78 | currentDate = new Date(); |
---|
79 | $( "#" + inputDateId ).val( this.calendarConverter.format( currentDate ) ); |
---|
80 | $( "#" + inputDateId ).addClass( "calendar" ); |
---|
81 | |
---|
82 | }, |
---|
83 | |
---|
84 | |
---|
85 | // CREATES ******************************************************** |
---|
86 | createTime: function( containerCalendar, texte, inputDateId, currentTime, isTrToCreate ) |
---|
87 | { |
---|
88 | if( isTrToCreate ) |
---|
89 | { |
---|
90 | // Create input for date text |
---|
91 | var tr = $( document.createElement( "tr" ) ); |
---|
92 | var td1 = $( document.createElement( "td" ) ); |
---|
93 | var td2 = $( document.createElement( "td" ) ); |
---|
94 | var inputDate = $( document.createElement( "input" ) ); |
---|
95 | inputDate.attr( {id:inputDateId, size:"10"} ); |
---|
96 | |
---|
97 | td1.html( texte ); |
---|
98 | td1.attr( { class:"containerLabel" } ); |
---|
99 | |
---|
100 | tr.append( td1 ); |
---|
101 | |
---|
102 | |
---|
103 | td2.attr( {colspan:3} ); |
---|
104 | td2.append( inputDate ); |
---|
105 | tr.append( td2 ); |
---|
106 | containerCalendar.append( tr ); |
---|
107 | } |
---|
108 | |
---|
109 | // Time |
---|
110 | this.timeFormat = "%H:%i:%s"; |
---|
111 | this.timeConverter = new AnyTime.Converter( { format: this.timeFormat } ); |
---|
112 | |
---|
113 | AnyTime.picker( inputDateId, { format: this.timeFormat, firstDOW: 1, |
---|
114 | labelTitle: "Select hour", labelHour: "Hour", labelMinute: "Minute", labelSecond: "Second" |
---|
115 | } ); |
---|
116 | |
---|
117 | if( !currentTime ) |
---|
118 | currentTime = "00:00:00"; |
---|
119 | // TODO : voir si besoin de convertir format des heures |
---|
120 | // $( "#" + inputDateId ).val( this.timeConverter.format( currentTime ) ); |
---|
121 | $( "#" + inputDateId ).val( currentTime ); |
---|
122 | $( "#" + inputDateId ).addClass( "time" ); |
---|
123 | }, |
---|
124 | |
---|
125 | |
---|
126 | createTr: function( texte, inputId, container, textesup ) |
---|
127 | { |
---|
128 | var tr = $( document.createElement( "tr" ) ); |
---|
129 | var td1 = $( document.createElement( "td" ) ); |
---|
130 | var td2 = $( document.createElement( "td" ) ); |
---|
131 | var td3 = $( document.createElement( "td" ) ); |
---|
132 | var input = $( document.createElement( "input" ) ); |
---|
133 | |
---|
134 | input.attr( {id: inputId, class:"containerText", size:11} ); |
---|
135 | |
---|
136 | td1.html( texte ); |
---|
137 | td1.attr( {class:"containerLabel"} ); |
---|
138 | |
---|
139 | td3.html( textesup ); |
---|
140 | td3.attr( {class:"containerLabel2", colspan:3} ); |
---|
141 | tr.append( td1 ); |
---|
142 | td2.append( input ); |
---|
143 | |
---|
144 | tr.append( td2 ); |
---|
145 | tr.append( td3 ); |
---|
146 | container.append( tr ); |
---|
147 | |
---|
148 | }, |
---|
149 | |
---|
150 | createSelectYesNo: function( container, name ) |
---|
151 | { |
---|
152 | var paramSelect = new Object(); |
---|
153 | paramSelect.id = "select_" + name; |
---|
154 | paramSelect.parent = container; |
---|
155 | var selectYesNos = new Select( paramSelect ); |
---|
156 | jQuery.each( this.jSonYesNos, jQuery.proxy( function ( i, jsonYesNo ) |
---|
157 | { |
---|
158 | selectYesNos.add( jsonYesNo.value, tapasTexts[jsonYesNo.text] ); |
---|
159 | }, this ) ); |
---|
160 | selectYesNos.selectFirst( false ); |
---|
161 | return selectYesNos; |
---|
162 | }, |
---|
163 | |
---|
164 | |
---|
165 | |
---|
166 | createTr2Input: function( texte1, texte2, inputId1, inputId2, container, textesup ) |
---|
167 | { |
---|
168 | var tr = $( document.createElement( "tr" ) ); |
---|
169 | var td1 = $( document.createElement( "td" ) ); |
---|
170 | var td2 = $( document.createElement( "td" ) ); |
---|
171 | var td3 = $( document.createElement( "td" ) ); |
---|
172 | var td4 = $( document.createElement( "td" ) ); |
---|
173 | var td5 = $( document.createElement( "td" ) ); |
---|
174 | var input1 = $( document.createElement( "input" ) ); |
---|
175 | var input2 = $( document.createElement( "input" ) ); |
---|
176 | |
---|
177 | |
---|
178 | input1.attr( {id: inputId1,class:"containerText",size:11} ); |
---|
179 | input2.attr( {id: inputId2,class:"containerText",size:11} ); |
---|
180 | |
---|
181 | td1.html( texte1 ); |
---|
182 | td3.html( texte2 ); |
---|
183 | td5.html( textesup ); |
---|
184 | td1.attr( {class:"containerLabel"} ); |
---|
185 | td3.attr( {class:"containerLabel3"} ); |
---|
186 | td5.attr( {class:"containerLabel2"} ); |
---|
187 | |
---|
188 | td2.append( input1 ); |
---|
189 | //td2.html( texte2 ); |
---|
190 | td4.append( input2 ); |
---|
191 | |
---|
192 | tr.append( td1 ); |
---|
193 | tr.append( td2 ); |
---|
194 | tr.append( td3 ); |
---|
195 | tr.append( td4 ); |
---|
196 | tr.append( td5 ); |
---|
197 | container.append( tr ); |
---|
198 | }, |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | createTrList: function( texte, inputId, container, type ) |
---|
203 | { |
---|
204 | var tr = $( document.createElement( "tr" ) ); |
---|
205 | var td1 = $( document.createElement( "td" ) ); |
---|
206 | var td2 = $( document.createElement( "td" ) ); |
---|
207 | var input = $( document.createElement( "input" ) ); |
---|
208 | |
---|
209 | input.attr( {id: inputId} ); |
---|
210 | |
---|
211 | td1.html( texte ); |
---|
212 | td1.attr( {class:"containerLabel"} ); |
---|
213 | |
---|
214 | tr.append( td1 ); |
---|
215 | if( type == 'format' ) this.displayFileFormats( td2, inputId ); |
---|
216 | else if( type == 'yesno' ) |
---|
217 | { |
---|
218 | if( (/^(ih2oe_[1-9]+)$/.test( inputId ) ) ) this.select_ih2oe = this.createSelectYesNo( td2, inputId ); |
---|
219 | else if( (/^(io2e_[1-9]+)$/.test( inputId ) ) ) this.select_io2e = this.createSelectYesNo( td2, inputId ); |
---|
220 | else if( (/^(io3e_[1-9]+)$/.test( inputId ) ) ) this.select_io3e = this.createSelectYesNo( td2, inputId ); |
---|
221 | else if( (/^(ico2e_[1-9]+)$/.test( inputId ) ) ) this.select_ico2e = this.createSelectYesNo( td2, inputId ); |
---|
222 | else if( (/^(irextinction_[1-9]+)$/.test( inputId ) ) ) this.select_irextinction = this.createSelectYesNo( td2, inputId ); |
---|
223 | } |
---|
224 | else if( type == 'observatories' ) this.displayObservatories( td2, inputId ); |
---|
225 | else if( type == 'spectralUnit' ) |
---|
226 | { |
---|
227 | this.displaySpectralUnits( td2, inputId ); |
---|
228 | //td2.attr({colspan:3}); |
---|
229 | } |
---|
230 | else if( type == 'ilsf' ) this.displayInstrumentalFunctions( td2, inputId ); |
---|
231 | else if( type == 'climatoReference' ) |
---|
232 | { |
---|
233 | this.displayClimatoReferences( td2, inputId ); |
---|
234 | } |
---|
235 | |
---|
236 | td2.attr( {colspan:3} ); |
---|
237 | tr.append( td2 ); |
---|
238 | container.append( tr ); |
---|
239 | }, |
---|
240 | |
---|
241 | |
---|
242 | // REQUESTS ******************************************************** |
---|
243 | requestCreateXML: function() |
---|
244 | { |
---|
245 | var tapasForm = this.createTapasObject(); |
---|
246 | //passage de javascript a json grace au jquery |
---|
247 | var jsonTapasForm = $.toJSON( tapasForm ); |
---|
248 | |
---|
249 | |
---|
250 | if( jsonTapasForm ) |
---|
251 | $.ajax( { |
---|
252 | url: "data?methodName=createUserRequest&jsonTapas=" + jsonTapasForm, |
---|
253 | success:jQuery.proxy( this.handleCreateXML, this ), |
---|
254 | error: jQuery.proxy( this.showErrors, this ) |
---|
255 | } ); |
---|
256 | }, |
---|
257 | |
---|
258 | |
---|
259 | // HANDLES ******************************************************** = retours ajax |
---|
260 | handleCreateXML: function( result ) |
---|
261 | { |
---|
262 | // TODO : gérer le bob ?? |
---|
263 | var bob = jQuery.parseJSON( result ).result; |
---|
264 | alert( bob ); |
---|
265 | }, |
---|
266 | |
---|
267 | |
---|
268 | // EVENTS ******************************************************** |
---|
269 | onClickSubmit: function() |
---|
270 | { |
---|
271 | if( this.validFields() ) |
---|
272 | { |
---|
273 | if( confirm( tapasTexts["confirm"] ) ) |
---|
274 | { |
---|
275 | this.containerErrors.hide(); |
---|
276 | // this.requestCreateXML(); |
---|
277 | } |
---|
278 | } |
---|
279 | }, |
---|
280 | |
---|
281 | |
---|
282 | onClickAdd: function() |
---|
283 | { |
---|
284 | this.containerErrors.hide(); |
---|
285 | this.nbRequest++; |
---|
286 | |
---|
287 | //tabs |
---|
288 | $( ".tab_class" ).removeClass( "activated" ); |
---|
289 | this.tabActive = this.createTab(); |
---|
290 | this.numRequest = this.tabActive.numTab; |
---|
291 | |
---|
292 | //formulaires |
---|
293 | $( ".divAll" ).hide(); |
---|
294 | this.createForm(); |
---|
295 | |
---|
296 | this.updateButtons(); |
---|
297 | }, |
---|
298 | |
---|
299 | |
---|
300 | onClickDel: function() |
---|
301 | { |
---|
302 | if( confirm( "pouet" ) ) |
---|
303 | { |
---|
304 | var numCurrent = this.numRequest; |
---|
305 | var z = 1; |
---|
306 | |
---|
307 | //suppression onglet et form et controles calendrier caché |
---|
308 | $( "#all_" + numCurrent ).remove(); |
---|
309 | $( "#tab_request" + numCurrent ).remove(); |
---|
310 | AnyTime.noPicker( "iobservation_date_" + numCurrent ); |
---|
311 | AnyTime.noPicker( "ira_" + numCurrent ); |
---|
312 | |
---|
313 | this.tabActive.numTab = "1"; |
---|
314 | this.numRequest = "1"; |
---|
315 | |
---|
316 | for( var i = 1; i <= this.nbRequest; i++ ) |
---|
317 | { |
---|
318 | if( i > numCurrent ) |
---|
319 | { |
---|
320 | z = i - 1; |
---|
321 | document.getElementById( "all_" + i ).id = "all_" + z; |
---|
322 | $( "#tab_request" + i ).html( "Request " + z ); |
---|
323 | $( "#tab_request" + i ).attr( {name:z} ); |
---|
324 | //document.getElementById("tab_request"+i).name=z; |
---|
325 | $( "#tab_request" + i ).attr( {id:"tab_request" + z} ); |
---|
326 | $( "#tabObservation_" + i ).attr( {id:"tabObservation_" + z} ); |
---|
327 | $( "#select_iobservatory_" + i ).attr( {id:"select_iobservatory_" + z} ); |
---|
328 | $( "#select_ispectral_choice_" + i ).attr( {id:"select_ispectral_choice_" + z} ); |
---|
329 | $( "#iminspectral_ranger_" + i ).attr( {id:"iminspectral_ranger_" + z} ); |
---|
330 | $( "#imaxspectral_ranger_" + i ).attr( {id:"imaxspectral_ranger_" + z} ); |
---|
331 | $( "#select_ifunction_" + i ).attr( {id:"select_ifunction_" + z} ); |
---|
332 | $( "#select_icr_" + i ).attr( {id:"select_icr_" + z} ); |
---|
333 | $( "#ide_" + i ).attr( {id:"ide_" + z} ); |
---|
334 | $( "#iza_" + i ).attr( {id:"iza_" + z} ); |
---|
335 | $( "#irp_" + i ).attr( {id:"irp_" + z} ); |
---|
336 | $( "#isr_" + i ).attr( {id:"isr_" + z} ); |
---|
337 | $( "#select_iformat_" + i ).attr( {id:"select_iformat_" + z} ); |
---|
338 | $( "#select_irextinction_" + i ).attr( {id:"select_irextinction_" + z} ); |
---|
339 | $( "#select_ih2oe_" + i ).attr( {id:"select_ih2oe_" + z} ); |
---|
340 | $( "#select_io2e_" + i ).attr( {id:"select_io2e_" + z} ); |
---|
341 | $( "#select_io3e_" + i ).attr( {id:"select_io3e_" + z} ); |
---|
342 | $( "#select_ico2e_" + i ).attr( {id:"select_ico2e_" + z} ); |
---|
343 | |
---|
344 | // Supression du calendrier puis re-création en insérant l'ancienne date |
---|
345 | var oldDate = this.calendarConverter.parse( $( "#iobservation_date_" + i ).val() ); |
---|
346 | AnyTime.noPicker( "iobservation_date_" + i ); |
---|
347 | this.createCalendar( $( "#tabObservation_" + z ), tapasTexts["label.datemesure"], "iobservation_date_" + z, oldDate, false ); |
---|
348 | $( "#iobservation_date_" + i ).attr( {id:"iobservation_date_" + z} ); |
---|
349 | |
---|
350 | // Idem pour les heures !!! |
---|
351 | // TODO : voir si besoin de parser les heures ou non |
---|
352 | // var oldTime = this.timeConverter.parse( $( "#ira_" + i ).val() ); |
---|
353 | var oldTime = $( "#ira_" + i ).val(); |
---|
354 | AnyTime.noPicker( "ira_" + i ); |
---|
355 | this.createTime( $( "#tabObservation_" + z ), tapasTexts["label.ira"], "ira_" + z, oldTime, false ); |
---|
356 | $( "#ira_" + i ).attr( {id:"ira_" + z} ); |
---|
357 | } |
---|
358 | } |
---|
359 | |
---|
360 | this.nbRequest--; |
---|
361 | |
---|
362 | // Mise à jour des boutons |
---|
363 | this.updateButtons(); |
---|
364 | |
---|
365 | //tabs |
---|
366 | $( ".tab_class" ).removeClass( "activated" ); |
---|
367 | $( "#tab_request1" ).addClass( "activated" ); |
---|
368 | |
---|
369 | //formulaires |
---|
370 | $( ".divAll" ).hide(); |
---|
371 | $( "#all_1" ).show(); |
---|
372 | } |
---|
373 | }, |
---|
374 | |
---|
375 | |
---|
376 | onClickTab: function( event ) |
---|
377 | { |
---|
378 | var realTabId = $( "#" + event.currentTarget.id ).attr( "name" ); |
---|
379 | var clickedDiv = event.data; |
---|
380 | |
---|
381 | //tabs |
---|
382 | $( ".tab_class" ).removeClass( "activated" ); |
---|
383 | clickedDiv.divContainer.addClass( "activated" ); |
---|
384 | |
---|
385 | //forms |
---|
386 | $( ".divAll" ).hide(); |
---|
387 | $( "#all_" + realTabId ).show(); |
---|
388 | |
---|
389 | this.numRequest = realTabId; |
---|
390 | this.tabActive.numTab = realTabId; |
---|
391 | |
---|
392 | this.updateButtons(); |
---|
393 | }, |
---|
394 | |
---|
395 | |
---|
396 | // OTHERS ******************************************************** |
---|
397 | displayFileFormats: function( container, id ) |
---|
398 | { |
---|
399 | var paramSelect = new Object(); |
---|
400 | paramSelect.id = "select_" + id; |
---|
401 | paramSelect.parent = container; |
---|
402 | this.selectFormats = new Select( paramSelect ); |
---|
403 | jQuery.each( this.jSonFileFormats, jQuery.proxy( function ( i, jsonFileFormat ) |
---|
404 | { |
---|
405 | this.selectFormats.add( jsonFileFormat.value, jsonFileFormat.text ); |
---|
406 | }, this ) ); |
---|
407 | this.selectFormats.selectFirst( false ); |
---|
408 | }, |
---|
409 | |
---|
410 | |
---|
411 | displayObservatories: function( container, id ) |
---|
412 | { |
---|
413 | var paramSelect = new Object(); |
---|
414 | paramSelect.id = "select_" + id; |
---|
415 | paramSelect.parent = container; |
---|
416 | this.selectObservatories = new Select( paramSelect ); |
---|
417 | //ajouter select vide avec add |
---|
418 | this.selectObservatories.add( "-1", "-- " + tapasTexts["text.select"] + " --" ); |
---|
419 | jQuery.each( this.jSonObservatories, jQuery.proxy( function ( i, jsonObservatory ) |
---|
420 | { |
---|
421 | this.selectObservatories.add( jsonObservatory.id, jsonObservatory.name ); |
---|
422 | }, this ) ); |
---|
423 | this.selectObservatories.selectFirst( true ); |
---|
424 | }, |
---|
425 | |
---|
426 | |
---|
427 | displaySpectralUnits: function( container, id ) |
---|
428 | { |
---|
429 | var paramSelect = new Object(); |
---|
430 | paramSelect.id = "select_" + id; |
---|
431 | paramSelect.parent = container; |
---|
432 | this.selectSpectralUnits = new Select( paramSelect ); |
---|
433 | //ajouter select vide avec add |
---|
434 | this.selectSpectralUnits.add( "-1", "-- " + tapasTexts["text.select"] + " --" ); |
---|
435 | jQuery.each( this.jSonSpectralUnits, jQuery.proxy( function ( i, jsonSpectralUnit ) |
---|
436 | { |
---|
437 | this.selectSpectralUnits.add( jsonSpectralUnit.value, tapasTexts[jsonSpectralUnit.value] ); |
---|
438 | //this.selectSpectralUnits.add( jsonSpectralUnit.value, jsonSpectralUnit.value ); |
---|
439 | }, this ) ); |
---|
440 | this.selectSpectralUnits.selectFirst( true ); |
---|
441 | }, |
---|
442 | |
---|
443 | displayInstrumentalFunctions: function( container, id ) |
---|
444 | { |
---|
445 | var paramSelect = new Object(); |
---|
446 | paramSelect.id = "select_" + id; |
---|
447 | paramSelect.parent = container; |
---|
448 | this.selectInstrumentalFunctions = new Select( paramSelect ); |
---|
449 | //ajouter select vide avec add |
---|
450 | jQuery.each( this.jSonInstrumentalFunctions, jQuery.proxy( function ( i, jsonInstrumentalFunction ) |
---|
451 | { |
---|
452 | this.selectInstrumentalFunctions.add( jsonInstrumentalFunction.value, tapasTexts[jsonInstrumentalFunction.text] ); |
---|
453 | }, this ) ); |
---|
454 | this.selectInstrumentalFunctions.selectFirst( true ); |
---|
455 | }, |
---|
456 | |
---|
457 | |
---|
458 | displayClimatoReferences: function( container, id ) |
---|
459 | { |
---|
460 | var paramSelect = new Object(); |
---|
461 | paramSelect.id = "select_" + id; |
---|
462 | paramSelect.parent = container; |
---|
463 | this.selectClimatoReferences = new Select( paramSelect ); |
---|
464 | //ajouter select vide avec add |
---|
465 | jQuery.each( this.jSonClimatoReferences, jQuery.proxy( function ( i, jsonClimatoReference ) |
---|
466 | { |
---|
467 | this.selectClimatoReferences.add( jsonClimatoReference.value, tapasTexts[jsonClimatoReference.text] ); |
---|
468 | }, this ) ); |
---|
469 | this.selectClimatoReferences.selectFirst( true ); |
---|
470 | }, |
---|
471 | |
---|
472 | |
---|
473 | showErrors: function( result ) |
---|
474 | { |
---|
475 | //this.containerErrors.show(); |
---|
476 | // this.containerErrors.html( tapasTexts[result.responseText] ); |
---|
477 | }, |
---|
478 | |
---|
479 | |
---|
480 | |
---|
481 | createForm: function() |
---|
482 | { |
---|
483 | this.divErreurs = $( document.createElement( "div" ) ); |
---|
484 | this.divErreurs.addClass( "errorsForm" ); |
---|
485 | this.divErreurs.hide(); |
---|
486 | |
---|
487 | var divAll = $( document.createElement( "div" ) ); |
---|
488 | divAll.attr( {id:"all_" + this.nbRequest, class:"divAll"} ); |
---|
489 | |
---|
490 | |
---|
491 | //Creation div |
---|
492 | var divPreference = $( document.createElement( "div" ) ); |
---|
493 | var tabPreference = $( document.createElement( "table" ) ); |
---|
494 | tabPreference.attr( {cellspacing:3} ); |
---|
495 | |
---|
496 | var divObservation = $( document.createElement( "div" ) ); |
---|
497 | var tabObservation = $( document.createElement( "table" ) ); |
---|
498 | //tabObservation.attr({border:1}); |
---|
499 | tabObservation.attr( {id:"tabObservation_" + this.nbRequest, cellspacing:3} ); |
---|
500 | |
---|
501 | |
---|
502 | var divAtmosphere = $( document.createElement( "div" ) ); |
---|
503 | var tabAtmosphere = $( document.createElement( "table" ) ); |
---|
504 | |
---|
505 | |
---|
506 | var fieldSetObservation = $( document.createElement( "fieldset" ) ); |
---|
507 | fieldSetObservation.addClass( "cfs1" ); |
---|
508 | divObservation.append( fieldSetObservation ); |
---|
509 | |
---|
510 | var legendObservation = $( document.createElement( "legend" ) ); |
---|
511 | legendObservation.html( "Observation" ); |
---|
512 | fieldSetObservation.append( legendObservation ); |
---|
513 | legendObservation.addClass( "containerField" ); |
---|
514 | |
---|
515 | var fieldSetPreference = $( document.createElement( "fieldset" ) ); |
---|
516 | fieldSetPreference.addClass( "cfs2" ); |
---|
517 | divPreference.append( fieldSetPreference ); |
---|
518 | |
---|
519 | var legendPreference = $( document.createElement( "legend" ) ); |
---|
520 | legendPreference.html( tapasTexts["label.preferences"] ); |
---|
521 | fieldSetPreference.append( legendPreference ); |
---|
522 | legendPreference.addClass( "containerField" ); |
---|
523 | |
---|
524 | fieldSetObservation.append( tabObservation ); |
---|
525 | divObservation.addClass( "divObservation" ); |
---|
526 | divAll.append( divObservation ); |
---|
527 | |
---|
528 | |
---|
529 | divAtmosphere.append( tabAtmosphere ); |
---|
530 | //divAtmosphere.addClass("divAtmosphere"); |
---|
531 | //this.containerForm.append( divAtmosphere ); |
---|
532 | fieldSetObservation.append( divAtmosphere ); |
---|
533 | |
---|
534 | fieldSetPreference.append( tabPreference ); |
---|
535 | divPreference.addClass( "divPreference" ); |
---|
536 | divAll.append( divPreference ); |
---|
537 | |
---|
538 | this.containerForm.append( divAll ); |
---|
539 | this.containerForm.append( this.divErreurs ); |
---|
540 | //this.tabInput = new Array(3); |
---|
541 | |
---|
542 | this.createTrList( tapasTexts["label.format"], "iformat_" + this.nbRequest, tabPreference, 'format' ); |
---|
543 | this.createTrList( tapasTexts["label.era"], "irextinction_" + this.nbRequest, tabPreference, 'yesno' ); |
---|
544 | this.createTrList( tapasTexts["label.eh2o"], "ih2oe_" + this.nbRequest, tabPreference, 'yesno' ); |
---|
545 | this.createTrList( tapasTexts["label.eo3"], "io3e_" + this.nbRequest, tabPreference, 'yesno' ); |
---|
546 | this.createTrList( tapasTexts["label.eo2"], "io2e_" + this.nbRequest, tabPreference, 'yesno' ); |
---|
547 | this.createTrList( tapasTexts["label.eco2"], "ico2e_" + this.nbRequest, tabPreference, 'yesno' ); |
---|
548 | |
---|
549 | this.createTrList( tapasTexts["label.observatory"], "iobservatory_" + this.nbRequest, tabObservation, 'observatories' ); |
---|
550 | this.createCalendar( tabObservation, tapasTexts["label.datemesure"], "iobservation_date_" + this.nbRequest, false, true ); |
---|
551 | |
---|
552 | //unite |
---|
553 | this.createTrList( tapasTexts["label.spectralUnit"], "ispectral_choice_" + this.nbRequest, tabObservation, 'spectralUnit' ); |
---|
554 | this.createTr2Input( tapasTexts["label.spectralRange"], tapasTexts["label.to"], "iminspectral_ranger_" + this.nbRequest, "imaxspectral_ranger_" + this.nbRequest, tabObservation, "[350,2500] nm" ); |
---|
555 | |
---|
556 | //fonction instrumentale |
---|
557 | this.createTrList( tapasTexts["label.ifunction"], "ifunction_" + this.nbRequest, tabObservation, "ilsf" ); |
---|
558 | //reference climato |
---|
559 | //this.createTrList( tapasTexts["label.climato"], "icr", tabAtmosphere, "climatoReference" ); |
---|
560 | this.createTrList( tapasTexts["label.climato"], "icr_" + this.nbRequest, tabObservation, "climatoReference" ); |
---|
561 | |
---|
562 | |
---|
563 | //this.createTr( tapasTexts["label.ira"], "ira", tabObservation ); |
---|
564 | this.createTime( tabObservation, tapasTexts["label.ira"], "ira_" + this.nbRequest, false, true ); |
---|
565 | this.createTr( tapasTexts["label.ide"], "ide_" + this.nbRequest, tabObservation, "hh:mm:ss.ms [-90,90] °" ); |
---|
566 | this.createTr( tapasTexts["label.iza"], "iza_" + this.nbRequest, tabObservation, "[0,90] °" ); |
---|
567 | |
---|
568 | this.createTr( tapasTexts["label.resolution"], "irp_" + this.nbRequest, tabObservation, "" ); |
---|
569 | this.createTr( tapasTexts["label.ratio"], "isr_" + this.nbRequest, tabObservation, "" ); |
---|
570 | |
---|
571 | |
---|
572 | //jQuery.proxy permet d'envoyer le contexte this courant |
---|
573 | |
---|
574 | }, |
---|
575 | |
---|
576 | |
---|
577 | |
---|
578 | createTapasObject: function() |
---|
579 | { |
---|
580 | |
---|
581 | var requests = new Array(); |
---|
582 | |
---|
583 | for( var i = 1; i <= this.nbRequest; i++ ) |
---|
584 | { |
---|
585 | // PREFERENCE |
---|
586 | var preference = new Object(); |
---|
587 | |
---|
588 | preference.format = new Object(); |
---|
589 | //toutes les valeurs possibles |
---|
590 | preference.format.firstValue = this.selectFormats.getValuesInString(); |
---|
591 | |
---|
592 | //la valeur selectionnee |
---|
593 | preference.format.secondValue = this.selectFormats.getValue(); |
---|
594 | |
---|
595 | preference.rayleighExtinction = new Object(); |
---|
596 | preference.rayleighExtinction.firstValue = this.select_ih2oe.getValuesInString(); |
---|
597 | preference.rayleighExtinction.secondValue = this.select_irextinction.getValue(); |
---|
598 | |
---|
599 | |
---|
600 | preference.h2oExtinction = new Object(); |
---|
601 | preference.h2oExtinction.firstValue = this.select_ih2oe.getValuesInString(); |
---|
602 | preference.h2oExtinction.secondValue = this.select_ih2oe.getValue(); |
---|
603 | |
---|
604 | |
---|
605 | preference.o3Extinction = new Object(); |
---|
606 | preference.o3Extinction.firstValue = this.select_io3e.getValuesInString(); |
---|
607 | preference.o3Extinction.secondValue = this.select_io3e.getValue(); |
---|
608 | |
---|
609 | preference.o2Extinction = new Object(); |
---|
610 | preference.o2Extinction.firstValue = this.select_io2e.getValuesInString(); |
---|
611 | preference.o2Extinction.secondValue = this.select_io2e.getValue(); |
---|
612 | |
---|
613 | preference.co2Extinction = new Object(); |
---|
614 | preference.co2Extinction.firstValue = this.select_ico2e.getValuesInString(); |
---|
615 | preference.co2Extinction.secondValue = this.select_ico2e.getValue(); |
---|
616 | |
---|
617 | |
---|
618 | // OBSERVATION |
---|
619 | var observatory = new Object(); |
---|
620 | |
---|
621 | //observatory.id = this.selectObservatories.getValue(); |
---|
622 | observatory.id = "3"; |
---|
623 | |
---|
624 | // Los |
---|
625 | var los = new Object(); |
---|
626 | |
---|
627 | |
---|
628 | los.raJ2000 = $( "#ira_" + i ).val(); |
---|
629 | los.decJ2000 = $( "#ide_" + i ).val(); |
---|
630 | |
---|
631 | |
---|
632 | los.zenithAngle = $( "#iza_" + i ).val(); |
---|
633 | |
---|
634 | |
---|
635 | // Instrument |
---|
636 | var instrument = new Object(); |
---|
637 | |
---|
638 | instrument.ilsfChoice = new Object(); |
---|
639 | instrument.ilsfChoice.firstValue = this.selectInstrumentalFunctions.getValuesInString(); |
---|
640 | instrument.ilsfChoice.secondValue = this.selectInstrumentalFunctions.getValue(); |
---|
641 | |
---|
642 | instrument.spectralChoice = new Object(); |
---|
643 | |
---|
644 | this.selectSpectralUnits.remove( "-1" ); |
---|
645 | instrument.spectralChoice.firstValue = this.selectSpectralUnits.getValuesInString(); |
---|
646 | instrument.spectralChoice.secondValue = this.selectSpectralUnits.getValue(); |
---|
647 | |
---|
648 | instrument.spectralRange = $( "#iminspectral_ranger_" + i ).val() + ' ' + $( "#imaxspectral_ranger_" + i ).val(); |
---|
649 | |
---|
650 | |
---|
651 | instrument.resolvingPower = new Object(); |
---|
652 | instrument.resolvingPower.firstValue = "0"; |
---|
653 | instrument.resolvingPower.secondValue = $( "#irp_" + i ).val(); |
---|
654 | |
---|
655 | instrument.samplingRatio = new Object(); |
---|
656 | instrument.samplingRatio.firstValue = "0"; |
---|
657 | instrument.samplingRatio.secondValue = $( "#isr_" + i ).val(); |
---|
658 | |
---|
659 | var observation = new Object(); |
---|
660 | observation.date = this.calendarConverter.parse( $( "#iobservation_date_" + i ).val() ); |
---|
661 | observation.observatory = observatory; |
---|
662 | |
---|
663 | observation.los = los; |
---|
664 | observation.instrument = instrument; |
---|
665 | |
---|
666 | |
---|
667 | // ATMOSPHERE |
---|
668 | var atmosphere = new Object(); |
---|
669 | |
---|
670 | atmosphere.reference = new Object(); |
---|
671 | atmosphere.reference.firstValue = this.selectClimatoReferences.getValuesInString(); |
---|
672 | atmosphere.reference.secondValue = this.selectClimatoReferences.getValue(); |
---|
673 | |
---|
674 | |
---|
675 | // REQUEST |
---|
676 | var request = new Object(); |
---|
677 | request.id = i; |
---|
678 | request.preference = preference; |
---|
679 | request.observation = observation; |
---|
680 | request.atmosphere = atmosphere; |
---|
681 | |
---|
682 | requests[i] = request; |
---|
683 | } |
---|
684 | |
---|
685 | // TAPAS |
---|
686 | var tapas = new Object(); |
---|
687 | tapas.requests = requests; |
---|
688 | return tapas; |
---|
689 | }, |
---|
690 | |
---|
691 | validFields: function() |
---|
692 | { |
---|
693 | var testOk = isSup( this.selectObservatories.getValue(), 0 ); |
---|
694 | if( !testOk ) |
---|
695 | { |
---|
696 | this.containerErrors.html( tapasTexts["label.observatory"] + " : " + tapasTexts["text.toselect"] ); |
---|
697 | this.containerErrors.show(); |
---|
698 | return false; |
---|
699 | } |
---|
700 | |
---|
701 | testOk = isDiff( this.selectSpectralUnits.getValue(), -1 ); |
---|
702 | if( !testOk ) |
---|
703 | { |
---|
704 | this.containerErrors.html( tapasTexts["label.spectralUnit"] + " : " + tapasTexts["text.toselect"] ); |
---|
705 | this.containerErrors.show(); |
---|
706 | return false; |
---|
707 | } |
---|
708 | |
---|
709 | testOk = isValidRange( $( "#iminspectral_ranger" ).val(), $( "#imaxspectral_ranger" ).val(), this.selectSpectralUnits.getValue() ); |
---|
710 | if( !testOk ) |
---|
711 | { |
---|
712 | this.containerErrors.html( tapasTexts["label.spectralRange"] + " : " + tapasTexts["text.badvalue"] ); |
---|
713 | this.containerErrors.show(); |
---|
714 | return false; |
---|
715 | } |
---|
716 | |
---|
717 | testOk = isDeg( $( "#ide" ).val() ); |
---|
718 | if( !testOk ) |
---|
719 | { |
---|
720 | this.containerErrors.html( tapasTexts["label.ide"] + " : " + tapasTexts["text.badvalue"] ); |
---|
721 | this.containerErrors.show(); |
---|
722 | return false; |
---|
723 | } |
---|
724 | |
---|
725 | testOk = isValidNum( $( "#iza" ).val() ); |
---|
726 | if( !testOk ) |
---|
727 | { |
---|
728 | this.containerErrors.html( tapasTexts["label.iza"] + " : " + tapasTexts["text.badvalue"] ); |
---|
729 | this.containerErrors.show(); |
---|
730 | return false; |
---|
731 | } |
---|
732 | |
---|
733 | testOk = isBetween( $( "#iza" ).val(), 0, 90 ); |
---|
734 | if( !testOk ) |
---|
735 | { |
---|
736 | this.containerErrors.html( tapasTexts["label.iza"] + " : " + tapasTexts["text.badvalue"] ); |
---|
737 | this.containerErrors.show(); |
---|
738 | return false; |
---|
739 | } |
---|
740 | |
---|
741 | testOk = isValidNum( $( "#irp" ).val() ); |
---|
742 | if( !testOk ) |
---|
743 | { |
---|
744 | this.containerErrors.html( tapasTexts["label.resolution"] + " : " + tapasTexts["text.badvalue"] ); |
---|
745 | this.containerErrors.show(); |
---|
746 | return false; |
---|
747 | } |
---|
748 | |
---|
749 | testOk = isSup( $( "#irp" ).val(), 1 ); |
---|
750 | if( !testOk ) |
---|
751 | { |
---|
752 | this.containerErrors.html( tapasTexts["label.resolution"] + " : " + tapasTexts["text.badvalue"] ); |
---|
753 | this.containerErrors.show(); |
---|
754 | return false; |
---|
755 | } |
---|
756 | |
---|
757 | testOk = isValidNum( $( "#isr" ).val() ); |
---|
758 | if( !testOk ) |
---|
759 | { |
---|
760 | this.containerErrors.html( tapasTexts["label.ratio"] + " : " + tapasTexts["text.badvalue"] ); |
---|
761 | this.containerErrors.show(); |
---|
762 | return false; |
---|
763 | } |
---|
764 | |
---|
765 | testOk = isSup( $( "#isr" ).val(), 1 ); |
---|
766 | if( !testOk ) |
---|
767 | { |
---|
768 | this.containerErrors.html( tapasTexts["label.ratio"] + " : " + tapasTexts["text.badvalue"] ); |
---|
769 | this.containerErrors.show(); |
---|
770 | return false; |
---|
771 | } |
---|
772 | }, |
---|
773 | |
---|
774 | updateButtons: function() |
---|
775 | { |
---|
776 | if( 1 < this.nbRequest ) |
---|
777 | this.delRequestButton.enable(); |
---|
778 | else |
---|
779 | this.delRequestButton.disable(); |
---|
780 | |
---|
781 | if( 9 <= this.nbRequest ) |
---|
782 | this.addRequestButton.disable(); |
---|
783 | else |
---|
784 | this.addRequestButton.enable(); |
---|
785 | } |
---|
786 | |
---|
787 | } ); |
---|
788 | |
---|
789 | </script> |
---|