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