source: tapas/web/project/formTapas_script.jsp @ 439

Last change on this file since 439 was 439, checked in by vmipsl, 12 years ago

Select _ getValues()
ajout calendar

File size: 9.1 KB
Line 
1<script type="text/javascript">
2var InterfaceTapas = Class.create( {
3
4    initialize: function( jsonFileFormats, jsonYesNos )
5    {
6        /** *********** CONTAINERS *********** **/
7        this.containerForm = $( "#formulaire" );
8        this.containerErrors = $( "#errors" );
9
10        this.jsonFileFormats = jsonFileFormats || null;
11        this.jsonYesNos = jsonYesNos || null;
12
13        this.containerErrors.hide();
14
15        this.createForm();
16        this.createCalendar( this.containerForm );
17    },
18
19
20
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 );
29
30        // Calendar
31        this.calendarFormat = "%Y-%m-%d %H:%i:%s";
32        this.calendarConverter = new AnyTime.Converter( { format: this.calendarFormat } );
33
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        } );
38
39        var currentDate = new Date();
40        $( "#observationDate" ).val( this.calendarConverter.format( currentDate ) );
41    },
42
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" ) );
49
50
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    },
58
59
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" ) );
66
67
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 );
73
74        tr.append( td2 );
75        container.append( tr );
76    },
77
78
79    createForm: function()
80    {
81
82        //Creation div
83        var divPreference = $( document.createElement( "div" ) );
84        var tabPreference = $( document.createElement( "table" ) );
85
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' );
92
93        divPreference.append( tabPreference );
94        this.containerForm.append( divPreference );
95
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 )} );
98
99    },
100
101
102
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 );
109
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    },
117
118    // HANDLES ******************************************************** = retours ajax
119    handleCreateXML: function( result )
120    {
121        var bob = jQuery.parseJSON( result ).result;
122        alert( bob );
123    },
124
125
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 )
141        {
142            this.selectFormats.add( jsonFileFormat.value, jsonFileFormat.text );
143        }, this ) );
144        this.selectFormats.selectFirst( false );
145    },
146
147
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 )
155        {
156            this.selectYesNos.add( jsonYesNo.value, jsonYesNo.text );
157        }, this ) );
158        this.selectYesNos.selectFirst( false );
159    },
160
161
162    showErrors: function( result )
163    {
164        this.containerErrors.show();
165        this.containerErrors.html( tapasTexts[result.responseText] );
166    },
167
168    createTapasForm: function()
169    {
170        // PREFERENCE
171        var preference = new Object();
172
173        preference.format = new Object();
174        preference.format.firstValue = $( "#1" ).val();
175        preference.format.secondValue = $( "#2" ).val();
176
177        var pair = new Object();
178        pair.firstValue = "YES,NO";
179        pair.secondValue = "YES";
180
181        preference.rayleighExtinction = pair;
182        preference.h2oExtinction = pair;
183        preference.o3Extinction = pair;
184        preference.o2Extinction = pair;
185        preference.co2Extinction = pair;
186
187        // OBSERVATION
188        // Observatory
189        var observatory = new Object();
190        observatory.name = "SanFernandoObs.RSanFernando";
191
192        observatory.longitude = new Object();
193        observatory.longitude.min = "-180";
194        observatory.longitude.max = "180";
195        observatory.longitude.value = -118.491666666667;
196
197        observatory.latitude = new Object();
198        observatory.latitude.min = "-90";
199        observatory.latitude.max = "90";
200        observatory.latitude.value = 34.3083333333333;
201
202        observatory.altitude = new Object();
203        observatory.altitude.min = "0";
204        observatory.altitude.max = "10000";
205        observatory.altitude.value = 371;
206
207        // Los
208        var los = new Object();
209        los.raJ2000 = "04:32:43";
210        los.decJ2000 = "-43:12:10.22";
211
212        los.zenithAngle = new Object();
213        los.zenithAngle.min = "0";
214        los.zenithAngle.max = "90";
215        los.zenithAngle.value = 60;
216
217        // Instrument
218        var instrument = new Object();
219
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;
234
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;
240
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;
246
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";
250
251        atmosphere.ecmwfFile = new Array();
252        atmosphere.ecmwfFile[0] = "/home/ferron/tmp/tapas/ecmwf12.txt";
253
254        // REQUEST
255        var request = new Object();
256        request.id = 1;
257        request.preference = preference;
258        request.observation = observation;
259        request.atmosphere = atmosphere;
260
261        var requests = new Array();
262        requests[0] = request;
263
264        // TAPAS
265        var tapas = new Object();
266        tapas.id = "Ether_TAPAS_0000001";
267        tapas.requests = requests;
268
269        return tapas;
270    }
271
272} );
273
274
275</script>
Note: See TracBrowser for help on using the repository browser.