[382] | 1 | <script type="text/javascript"> |
---|
[439] | 2 | var InterfaceTapas = Class.create( { |
---|
[382] | 3 | |
---|
[439] | 4 | initialize: function( jsonFileFormats, jsonYesNos ) |
---|
| 5 | { |
---|
| 6 | /** *********** CONTAINERS *********** **/ |
---|
| 7 | this.containerForm = $( "#formulaire" ); |
---|
| 8 | this.containerErrors = $( "#errors" ); |
---|
[382] | 9 | |
---|
[439] | 10 | this.jsonFileFormats = jsonFileFormats || null; |
---|
| 11 | this.jsonYesNos = jsonYesNos || null; |
---|
[419] | 12 | |
---|
[439] | 13 | this.containerErrors.hide(); |
---|
[419] | 14 | |
---|
[439] | 15 | this.createForm(); |
---|
| 16 | this.createCalendar( this.containerForm ); |
---|
| 17 | }, |
---|
[382] | 18 | |
---|
[419] | 19 | |
---|
| 20 | |
---|
[439] | 21 | // CREATES ******************************************************** |
---|
| 22 | createCalendar: function( containerCalendar ) |
---|
| 23 | { |
---|
| 24 | // Create input for date text |
---|
| 25 | var inputDateId = "observationDate"; |
---|
| 26 | var inputDate = $( document.createElement( "input" ) ); |
---|
| 27 | inputDate.attr( {id:inputDateId, size:"17"} ); |
---|
| 28 | containerCalendar.append( inputDate ); |
---|
[419] | 29 | |
---|
[439] | 30 | // Calendar |
---|
| 31 | this.calendarFormat = "%Y-%m-%d %H:%i:%s"; |
---|
| 32 | this.calendarConverter = new AnyTime.Converter( { format: this.calendarFormat } ); |
---|
[419] | 33 | |
---|
[439] | 34 | AnyTime.picker( inputDateId, { format: this.calendarFormat, firstDOW: 1, |
---|
| 35 | labelTitle: "Select Date", labelYear: "Year", labelMonth: "Month", labelDayOfMonth: "Day", |
---|
| 36 | labelHour: "Hour", labelMinute: "Minute", labelSecond: "Second" |
---|
| 37 | } ); |
---|
[419] | 38 | |
---|
[439] | 39 | var currentDate = new Date(); |
---|
| 40 | $( "#observationDate" ).val( this.calendarConverter.format( currentDate ) ); |
---|
| 41 | }, |
---|
[419] | 42 | |
---|
[439] | 43 | createTr: function( texte, inputId, container ) |
---|
| 44 | { |
---|
| 45 | var tr = $( document.createElement( "tr" ) ); |
---|
| 46 | var td1 = $( document.createElement( "td" ) ); |
---|
| 47 | var td2 = $( document.createElement( "td" ) ); |
---|
| 48 | var input = $( document.createElement( "input" ) ); |
---|
[419] | 49 | |
---|
| 50 | |
---|
[439] | 51 | input.attr( {id: inputId} ); |
---|
| 52 | td1.html( texte ); |
---|
| 53 | tr.append( td1 ); |
---|
| 54 | td2.append( input ); |
---|
| 55 | tr.append( td2 ); |
---|
| 56 | container.append( tr ); |
---|
| 57 | }, |
---|
[419] | 58 | |
---|
| 59 | |
---|
[439] | 60 | createTrList: function( texte, inputId, container, type ) |
---|
| 61 | { |
---|
| 62 | var tr = $( document.createElement( "tr" ) ); |
---|
| 63 | var td1 = $( document.createElement( "td" ) ); |
---|
| 64 | var td2 = $( document.createElement( "td" ) ); |
---|
| 65 | var input = $( document.createElement( "input" ) ); |
---|
[419] | 66 | |
---|
[382] | 67 | |
---|
[439] | 68 | input.attr( {id: inputId} ); |
---|
| 69 | td1.html( texte ); |
---|
| 70 | tr.append( td1 ); |
---|
| 71 | if( type == 'format' ) this.displayFileFormats( td2 ); |
---|
| 72 | else if( type == 'yesno' ) this.displayYesNo( td2 ); |
---|
[382] | 73 | |
---|
[439] | 74 | tr.append( td2 ); |
---|
| 75 | container.append( tr ); |
---|
| 76 | }, |
---|
[382] | 77 | |
---|
[419] | 78 | |
---|
[439] | 79 | createForm: function() |
---|
| 80 | { |
---|
[382] | 81 | |
---|
[439] | 82 | //Creation div |
---|
| 83 | var divPreference = $( document.createElement( "div" ) ); |
---|
| 84 | var tabPreference = $( document.createElement( "table" ) ); |
---|
[382] | 85 | |
---|
[439] | 86 | this.createTrList( "File format", "p1", tabPreference, 'format' ); |
---|
| 87 | this.createTr( "Rayleigh extinction", "p2", tabPreference ); |
---|
| 88 | this.createTrList( "H20 extinction", "p3", tabPreference, 'yesno' ); |
---|
| 89 | this.createTrList( "O3 extinction", "p4", tabPreference, 'yesno' ); |
---|
| 90 | this.createTrList( "O2 extinction", "p5", tabPreference, 'yesno' ); |
---|
| 91 | this.createTrList( "CO2 extinction", "p6", tabPreference, 'yesno' ); |
---|
[419] | 92 | |
---|
[439] | 93 | divPreference.append( tabPreference ); |
---|
| 94 | this.containerForm.append( divPreference ); |
---|
[419] | 95 | |
---|
[439] | 96 | //jQuery.proxy permet d'envoyer le contexte this courant |
---|
| 97 | 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 )} ); |
---|
[399] | 98 | |
---|
[439] | 99 | }, |
---|
[382] | 100 | |
---|
| 101 | |
---|
| 102 | |
---|
[439] | 103 | // REQUESTS ******************************************************** |
---|
| 104 | requestCreateXML: function() |
---|
| 105 | { |
---|
| 106 | var tapasForm = this.createTapasForm(); |
---|
| 107 | //passage de javascript a json grace au jquery |
---|
| 108 | var jsonTapasForm = $.toJSON( tapasForm ); |
---|
[396] | 109 | |
---|
[439] | 110 | if( jsonTapasForm ) |
---|
| 111 | $.ajax( { |
---|
| 112 | url: "data?methodName=createUserRequest&jsonTapas=" + jsonTapasForm, |
---|
| 113 | success:jQuery.proxy( this.handleCreateXML, this ), |
---|
| 114 | error: jQuery.proxy( this.showErrors, this ) |
---|
| 115 | } ); |
---|
| 116 | }, |
---|
[419] | 117 | |
---|
[439] | 118 | // HANDLES ******************************************************** = retours ajax |
---|
| 119 | handleCreateXML: function( result ) |
---|
| 120 | { |
---|
| 121 | var bob = jQuery.parseJSON( result ).result; |
---|
| 122 | alert( bob ); |
---|
| 123 | }, |
---|
[419] | 124 | |
---|
| 125 | |
---|
[439] | 126 | // EVENTS ******************************************************** |
---|
| 127 | onClickSubmit: function() |
---|
| 128 | { |
---|
| 129 | this.containerErrors.hide(); |
---|
| 130 | this.requestCreateXML(); |
---|
| 131 | }, |
---|
| 132 | |
---|
| 133 | // OTHERS ******************************************************** |
---|
| 134 | displayFileFormats: function( container ) |
---|
| 135 | { |
---|
| 136 | var paramSelect = new Object(); |
---|
| 137 | paramSelect.id = "select_formats"; |
---|
| 138 | paramSelect.parent = container; |
---|
| 139 | this.selectFormats = new Select( paramSelect ); |
---|
| 140 | jQuery.each( this.jsonFileFormats, jQuery.proxy( function ( i, jsonFileFormat ) |
---|
[419] | 141 | { |
---|
[439] | 142 | this.selectFormats.add( jsonFileFormat.value, jsonFileFormat.text ); |
---|
| 143 | }, this ) ); |
---|
| 144 | this.selectFormats.selectFirst( false ); |
---|
| 145 | }, |
---|
[419] | 146 | |
---|
| 147 | |
---|
[439] | 148 | displayYesNo: function( container, name ) |
---|
| 149 | { |
---|
| 150 | var paramSelect = new Object(); |
---|
| 151 | paramSelect.id = "select_" + name; |
---|
| 152 | paramSelect.parent = container; |
---|
| 153 | this.selectYesNos = new Select( paramSelect ); |
---|
| 154 | jQuery.each( this.jsonYesNos, jQuery.proxy( function ( i, jsonYesNo ) |
---|
[402] | 155 | { |
---|
[439] | 156 | this.selectYesNos.add( jsonYesNo.value, jsonYesNo.text ); |
---|
| 157 | }, this ) ); |
---|
| 158 | this.selectYesNos.selectFirst( false ); |
---|
| 159 | }, |
---|
[402] | 160 | |
---|
[399] | 161 | |
---|
[439] | 162 | showErrors: function( result ) |
---|
| 163 | { |
---|
| 164 | this.containerErrors.show(); |
---|
| 165 | this.containerErrors.html( tapasTexts[result.responseText] ); |
---|
| 166 | }, |
---|
[400] | 167 | |
---|
[439] | 168 | createTapasForm: function() |
---|
| 169 | { |
---|
| 170 | // PREFERENCE |
---|
| 171 | var preference = new Object(); |
---|
[400] | 172 | |
---|
[439] | 173 | preference.format = new Object(); |
---|
| 174 | preference.format.firstValue = $( "#1" ).val(); |
---|
| 175 | preference.format.secondValue = $( "#2" ).val(); |
---|
[400] | 176 | |
---|
[439] | 177 | var pair = new Object(); |
---|
| 178 | pair.firstValue = "YES,NO"; |
---|
| 179 | pair.secondValue = "YES"; |
---|
[400] | 180 | |
---|
[439] | 181 | preference.rayleighExtinction = pair; |
---|
| 182 | preference.h2oExtinction = pair; |
---|
| 183 | preference.o3Extinction = pair; |
---|
| 184 | preference.o2Extinction = pair; |
---|
| 185 | preference.co2Extinction = pair; |
---|
[400] | 186 | |
---|
[439] | 187 | // OBSERVATION |
---|
| 188 | // Observatory |
---|
| 189 | var observatory = new Object(); |
---|
| 190 | observatory.name = "SanFernandoObs.RSanFernando"; |
---|
[400] | 191 | |
---|
[439] | 192 | observatory.longitude = new Object(); |
---|
| 193 | observatory.longitude.min = "-180"; |
---|
| 194 | observatory.longitude.max = "180"; |
---|
| 195 | observatory.longitude.value = -118.491666666667; |
---|
[400] | 196 | |
---|
[439] | 197 | observatory.latitude = new Object(); |
---|
| 198 | observatory.latitude.min = "-90"; |
---|
| 199 | observatory.latitude.max = "90"; |
---|
| 200 | observatory.latitude.value = 34.3083333333333; |
---|
[400] | 201 | |
---|
[439] | 202 | observatory.altitude = new Object(); |
---|
| 203 | observatory.altitude.min = "0"; |
---|
| 204 | observatory.altitude.max = "10000"; |
---|
| 205 | observatory.altitude.value = 371; |
---|
[400] | 206 | |
---|
[439] | 207 | // Los |
---|
| 208 | var los = new Object(); |
---|
| 209 | los.raJ2000 = "04:32:43"; |
---|
| 210 | los.decJ2000 = "-43:12:10.22"; |
---|
[400] | 211 | |
---|
[439] | 212 | los.zenithAngle = new Object(); |
---|
| 213 | los.zenithAngle.min = "0"; |
---|
| 214 | los.zenithAngle.max = "90"; |
---|
| 215 | los.zenithAngle.value = 60; |
---|
[400] | 216 | |
---|
[439] | 217 | // Instrument |
---|
| 218 | var instrument = new Object(); |
---|
[399] | 219 | |
---|
[439] | 220 | instrument.spectralChoice = new Object(); |
---|
| 221 | instrument.spectralChoice.firstValue = "Vacuum Wavelength (nm),Standard Wavelength (nm),Wavenumber (cm-1)"; |
---|
| 222 | instrument.spectralChoice.secondValue = "Standard Wavelength (nm)"; |
---|
| 223 | instrument.spectralRange = "1180 1200"; |
---|
| 224 | instrument.ilsfChoice = new Object(); |
---|
| 225 | instrument.ilsfChoice.firstValue = "-1,0,1"; |
---|
| 226 | instrument.ilsfChoice.secondValue = 0; |
---|
| 227 | instrument.ilsfPath = "/home/ferron/tmp/tapas/ilsf.txt"; |
---|
| 228 | instrument.resolvingPower = new Object(); |
---|
| 229 | instrument.resolvingPower.firstValue = "0"; |
---|
| 230 | instrument.resolvingPower.secondValue = 1000000; |
---|
| 231 | instrument.samplingRatio = new Object(); |
---|
| 232 | instrument.samplingRatio.firstValue = "0"; |
---|
| 233 | instrument.samplingRatio.secondValue = 3; |
---|
[399] | 234 | |
---|
[439] | 235 | var observation = new Object(); |
---|
| 236 | observation.date = this.calendarConverter.parse( $( "#observationDate" ).val() ).getTime(); |
---|
| 237 | observation.observatory = observatory; |
---|
| 238 | observation.los = los; |
---|
| 239 | observation.instrument = instrument; |
---|
[399] | 240 | |
---|
[439] | 241 | // ATMOSPHERE |
---|
| 242 | var atmosphere = new Object(); |
---|
| 243 | atmosphere.reference = new Object(); |
---|
| 244 | atmosphere.reference.firstValue = "0,1,2,3,4,5,6"; |
---|
| 245 | atmosphere.reference.secondValue = 6; |
---|
[400] | 246 | |
---|
[439] | 247 | atmosphere.arlettyFile = new Array(); |
---|
| 248 | atmosphere.arlettyFile[0] = "/home/ferron/tmp/tapas/Reims_070402.ARL.txt"; |
---|
| 249 | atmosphere.arlettyFile[1] = "/home/ferron/tmp/tapas/Reims_070402.ARL.txt22"; |
---|
[400] | 250 | |
---|
[439] | 251 | atmosphere.ecmwfFile = new Array(); |
---|
| 252 | atmosphere.ecmwfFile[0] = "/home/ferron/tmp/tapas/ecmwf12.txt"; |
---|
[400] | 253 | |
---|
[439] | 254 | // REQUEST |
---|
| 255 | var request = new Object(); |
---|
| 256 | request.id = 1; |
---|
| 257 | request.preference = preference; |
---|
| 258 | request.observation = observation; |
---|
| 259 | request.atmosphere = atmosphere; |
---|
[400] | 260 | |
---|
[439] | 261 | var requests = new Array(); |
---|
| 262 | requests[0] = request; |
---|
[382] | 263 | |
---|
[439] | 264 | // TAPAS |
---|
| 265 | var tapas = new Object(); |
---|
| 266 | tapas.id = "Ether_TAPAS_0000001"; |
---|
| 267 | tapas.requests = requests; |
---|
[384] | 268 | |
---|
[439] | 269 | return tapas; |
---|
| 270 | } |
---|
[384] | 271 | |
---|
[439] | 272 | } ); |
---|
| 273 | |
---|
| 274 | |
---|
[384] | 275 | </script> |
---|