summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/ui-contribution/scatours.html
blob: 3ac053f0592cc80892aa8abb39f9eff08d3af0c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!--
    * Licensed to the Apache Software Foundation (ASF) under one
    * or more contributor license agreements.  See the NOTICE file
    * distributed with this work for additional information
    * regarding copyright ownership.  The ASF licenses this file
    * to you under the Apache License, Version 2.0 (the
    * "License"); you may not use this file except in compliance
    * with the License.  You may obtain a copy of the License at
    * 
    *   http://www.apache.org/licenses/LICENSE-2.0
    * 
    * Unless required by applicable law or agreed to in writing,
    * software distributed under the License is distributed on an
    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    * KIND, either express or implied.  See the License for the
    * specific language governing permissions and limitations
    * under the License.    
-->
<html>
<head>
<title>SCA Tours</title>

<link rel="stylesheet" type="text/css" href="style.css" />

<script type="text/javascript" src="scatours.js"></script>

<script language="JavaScript">

	//@Reference
	var hotel = new Reference("hotel");
    
    //@Reference
    var flight = new Reference("flight");
    
    //@Reference
    var car = new Reference("car");    
	
    //@Reference
    var travelSearch = new Reference("travelSearch");
    
    //@Reference
    var travelBooking = new Reference("travelBooking");
        
    //local state
    var currentTripId;
    var searchResponseItems;
     
    //the constructor for trip leg beans
    function TripLegType(id,
                         fromLocation,
                         toLocation,
                         fromDate,
                         toDate,
                         noOfPeople) {
          this.id           = id;
          this.fromLocation = fromLocation;
          this.toLocation   = toLocation;
          this.fromDate     = fromDate;
          this.toDate       = toDate;
          this.noOfPeople   = noOfPeople;
    }
    
    function getTripLeg(){
        return new TripLegType(currentTripId,
                               document.travelForm.fromLocation.value,
                               document.travelForm.toLocation.value,
                               document.travelForm.fromDate.value,
                               document.travelForm.toDate.value,
                               document.travelForm.noOfPeople.value);
    }
		
    function init() {
	   try {
           newTrip(); 
	   }
	   catch(e) {
	       alert(e);
	   }
    }
    
    function searchHotels() {       
        hotel.searchSynch(getTripLeg(), search_response);
    }
    
    function searchFlights() {       
        flight.searchSynch(getTripLeg(), search_response);
    }    
    
    function searchCars() {       
        car.searchSynch(getTripLeg(), search_response);
    } 
        
    function searchPackages() {        
        travelSearch.search(getTripLeg(), search_response);
    }
        
    function search_response(items, exception) {
        if(exception){
            alert(exception.javaStack);
            return;
        }
        var responseHTML = '<table border="0">';
        responseHTML    += '<tr>';
        responseHTML    += '<td>Select</td><td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>';
        responseHTML    += '</tr>';
        
        for (var i=0; i<items.length; i++) {
            responseHTML += '<tr>';
            responseHTML += '<td><input onClick="processSelection()" name="items" type="checkbox" value="' + items[i].id + '"></td>'
            responseHTML += '<td>' +  items[i].name + '</td>';
            responseHTML += '<td>' +  items[i].description + '</td>';
            responseHTML += '<td>' +  items[i].location + '</td>';
            responseHTML += '<td>' +  items[i].fromDate + ' - ' + items[i].toDate +'</td>';
            responseHTML += '<td>' +  items[i].price + ' ' + items[i].currency + '</td>';
            responseHTML += '</tr>';
        }
        
        responseHTML    += '</table>';
        
        document.getElementById('searchResponse').innerHTML = responseHTML;
        
        searchResponseItems = items;
    }  
    
    function processSelection() {        
        var items  = document.tripForm.items;
        var j = 0;
        for (var i=0; i<items.length; i++) {
            if (items[i].checked == true) {
                travelBooking.addTripItem(currentTripId, items[i].value);
            } else {
                travelBooking.removeTripItem(currentTripId, items[i].value);
            }
        }
        
        travelBooking.getTripItems(currentTripId,getTripItems_response);
    }
    
    function getTripItems_response(items, exception) {
        if(exception){
            alert(exception.javaStack);
            return;
        }
        var itemsHTML = '<table border="0">';
        itemsHTML    += '<tr>';
        itemsHTML    += '<td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>';
        itemsHTML    += '</tr>';
        
        for (var i=0; i<items.length; i++) {
            itemsHTML += '<tr>';
            itemsHTML += '<td>' +  items[i].name + '</td>';
            itemsHTML += '<td>' +  items[i].description + '</td>';
            itemsHTML += '<td>' +  items[i].location + '</td>';
            itemsHTML += '<td>' +  items[i].fromDate + ' - ' + items[i].toDate +'</td>';
            itemsHTML += '<td>' +  items[i].price + ' ' + items[i].currency + '</td>';
            itemsHTML += '</tr>';
        }
        
        itemsHTML    += '</table>';
        
        document.getElementById('tripItems').innerHTML = itemsHTML;  
          
        travelBooking.getTotalPrice(currentTripId, getTotalPrice_response);
    }    
    
    function getTotalPrice_response(totalPrice, exception) {
        if(exception){
            alert(exception.javaStack);
            return;
        }
        document.getElementById('totalPrice').innerHTML = totalPrice;
    }
    
    function newTrip() { 
        travelBooking.newTrip(newTrip_response);
        
        document.getElementById('searchResponse').innerHTML = "";
        document.getElementById('tripItems').innerHTML = "";
        document.getElementById('totalPrice').innerHTML = "";
    }
    
    function newTrip_response(tripId, exception) { 
        if(exception){
            alert(exception.javaStack);
            return;
        }
        currentTripId = tripId
        document.getElementById('tripId').innerHTML = "Trip: " + tripId;
    }    
    
    function purchaseTrip() {        
        travelBooking.purchaseTrip(currentTripId);
        
        document.getElementById('searchResponse').innerHTML = "";
        document.getElementById('tripItems').innerHTML = "Thank you for shopping with SCA Tours";
        document.getElementById('totalPrice').innerHTML = "";
        searchResponseItems = null;
        tripItems = null;
    }    
	
</script>

</head>

<body onload="init()" background="">
	<img src="scatours.png" border="0" />
	<div id="scatours">
        <form name="travelForm"> 
            <h3><div id="tripId"></h3>
            <br/>
            <table border="0">
                <tr>
                    <td>From Location:</td>
                    <td><input type="text" name="fromLocation" value="LGW"></td>
                    <td>To Location:</td>
                    <td><input type="text" name="toLocation" value="ANU"></td>
                </tr>
                <tr>
                    <td>Start Date:</td>
                    <td><input type="text" name="fromDate" value="06/12/08"></td>
                    <td>End Date:</td>
                    <td><input type="text" name="toDate" value="13/12/08"></td>
                </tr>
                <tr>
                    <td>Number of people:</td>
                    <td><select name="noOfPeople">
                        <option>1
                        <option selected>2
                        <option>3
                        <option>4
                    </select></td>
                    <td/>
                    <td/>
                </tr>
            </table>
            <input type="button" onClick="searchPackages()" value="SearchPackages"> 
            <input type="button" onClick="searchHotels()" value="Search Hotels">
            <input type="button" onClick="searchFlights()" value="Search Flights">
            <input type="button" onClick="searchHotels()" value="Search Cars"> 
        </form>
        <form name="tripForm">
            <h3>Search Results</h3> 
            <div id="searchResponse"></div>
            <br> 
            <h3>You Trip</h3>
            <div id="tripItems"></div>
            <br>            
            <div id="totalPrice"></div>
            <br>
            <input type="button" onClick="newTrip()" value="Create New Trip"> 
            <input type="button" onClick="purchaseTrip()" value="Purchase Trip"> 
        </form> 
	</div>
  
</body>
</html>