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