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
|
<!--
* 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 scaToursSearch = new Reference("scaToursSearch");
//@Reference
var scaToursBooking = new Reference("scaToursBooking");
//local state
var currentTripId;
var searchItems;
var cartItems;
//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 searchTravelCatalog() {
scaToursSearch.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;
searchItems = items;
}
function processSelection() {
// do nothing at the moment
}
function addItemsToCart() {
var items = document.tripForm.items;
for (var i=0; i<items.length; i++) {
// notify the server of the change
if (items[i].checked == true) {
scaToursBooking.addTripItem(currentTripId, items[i].value);
} else {
scaToursBooking.removeTripItem(currentTripId, items[i].value);
}
}
scaToursBooking.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;
scaToursBooking.getTotalPrice(currentTripId, getTotalPrice_response);
}
function getTotalPrice_response(totalPrice, exception) {
if(exception){
alert(exception.javaStack);
return;
}
document.getElementById('totalPrice').innerHTML = totalPrice;
}
function newTrip() {
scaToursBooking.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 Reference: " + tripId;
}
function bookTrip() {
travelBooking.bookTrip(currentTripId);
document.getElementById('searchResponse').innerHTML = "";
document.getElementById('tripItems').innerHTML = "Thank you for shopping with SCA Tours";
document.getElementById('totalPrice').innerHTML = "";
searchResponseItems = null;
tripItems = null;
}
function purchase() {
}
</script>
</head>
<body onload="init()" background="">
<img src="scatours.png" border="0" />
<div id="scatours">
<form name="travelForm">
<h3>Search for hotels, flights and cars</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>
<br/>
<input type="button" onClick="searchTravelCatalog()" value="Search">
</form>
<form name="tripForm">
<h3>Search Results</h3>
<div id="searchResponse"></div>
<br/>
<input type="button" onClick="addItemsToCart()" value="Add Items">
<br/>
<h3>Shopping Cart</h3>
<h3><div id="tripId"></h3>
<div id="tripItems"></div>
<br/>
<div id="totalPrice"></div>
<br/>
<input type="button" onClick="bookTrip()" value="Book">
<input type="button" onClick="newTrip()" value="Create New Trip">
</form>
</div>
</body>
</html>
|