summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/contributions/interaction-ui-contribution/src/main/resources/scatours.html
blob: 067c1c2761ff590a3a29af20532a044b823a7b96 (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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!--
    * 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 scaToursCatalog = new Reference("scaToursCatalog");
    
    //@Reference
    var scaToursBooking = new Reference("scaToursBooking");
    
    //@Reference
    var scaToursCart = new Reference("scaToursCart");    
        
    //local state
    var packagedItems;
    var bespokeItems;
    var cartId;
         
    //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(cartId,
                               document.searchForm.fromLocation.value,
                               document.searchForm.toLocation.value,
                               document.searchForm.fromDate.value,
                               document.searchForm.toDate.value,
                               document.searchForm.noOfPeople.value);
    }
    
    //the constructor for bespoke trip beans
    function TripType() {
          this.id           = cartId;
          this.type         = "Bespoke";
          this.tripItems    = new Array();
          // json databinding can't tolerate having a class hint set as the 
          // databinding transformer is not in the right classloader to load 
          // the class pointed to by the hint
          //this.javaClass    = "scatours.common.TripItem";
    }
    
    function getTrip(){
        return new TripType();
    }    
    
    // remove class hint from the trip object
    // can also be used to limit the amount of 
    // data returned to the server
    function copyTrip(trip){
        var tripCopy = new TripType();
        
        tripCopy.id = trip.id;
        tripCopy.tripId = trip.tripId;
        tripCopy.type = trip.type;
        tripCopy.name = trip.name;
        tripCopy.description = trip.description;
        tripCopy.location = trip.location;
        tripCopy.fromDate = trip.fromDate;
        tripCopy.toDate = trip.toDate;
        tripCopy.price = trip.price;
        tripCopy.currency = trip.currency;
        tripCopy.link = trip.link;
        
        return tripCopy;
    }   
		
    function init() {
	   try {
           newCart(); 
	   }
	   catch(e) {
	       alert(e);
	   }
    }
    
    function reset() { 
        document.getElementById('packagedTripItems').innerHTML = "";
        document.getElementById('bespokeTripItems').innerHTML = "";
        document.getElementById('cartItems').innerHTML = "";
        document.getElementById('cartPrice').innerHTML = "";
        packagedItems = new Array();
        bespokeItems = new Array();
    }
       
    function newCart() { 
        scaToursCart.newCart(newCart_response);
        reset();
    }
    
    function newCart_response(newCartId, exception) { 
        if(exception){
            alert(exception.javaStack);
            return;
        }
        cartId = newCartId
    }        
            
    function searchTravelCatalog() {        
        scaToursCatalog.search(getTripLeg(), search_response);
    }
        
    function search_response(items, exception) {
        if(exception){
            alert(exception.javaStack);
            return;
        }
        
        var packagedHTML = '<h3>Packaged Trip Items</h3>';
        packagedHTML    += '<table border="0">';
        packagedHTML    += '<tr>';
        packagedHTML    += '<td>Select</td><td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>';
        packagedHTML    += '</tr>'; 
             
        var bespokeHTML = '<h3>Bespoke Trip Items</h3>'; 
        bespokeHTML    += '<table border="0">';
        bespokeHTML    += '<tr>';
        bespokeHTML    += '<td>Select</td><td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>';
        bespokeHTML    += '</tr>';       
        
        for (var i=0; i<items.length; i++) {
            if (items[i].type == "Trip") {
                packagedHTML += '<tr>';
                packagedHTML += '<td><input onClick="processPackagedSelection()" name="packagedTripItemSelection" type="checkbox" value="' + items[i].id + '"></td>'
                packagedHTML += '<td>' +  items[i].name + '</td>';
                packagedHTML += '<td>' +  items[i].description + '</td>';
                packagedHTML += '<td>' +  items[i].location + '</td>';
                packagedHTML += '<td>' +  items[i].fromDate + ' - ' + items[i].toDate +'</td>';
                packagedHTML += '<td>' +  items[i].price + ' ' + items[i].currency + '</td>';
                packagedHTML += '</tr>';
                packagedItems.push(items[i]);
            } else {
                bespokeHTML += '<tr>';
                bespokeHTML += '<td><input onClick="processBespokeSelection()" name="bespokeTripItemSelection" type="checkbox" value="' + items[i].id + '"></td>'
                bespokeHTML += '<td>' +  items[i].name + '</td>';
                bespokeHTML += '<td>' +  items[i].description + '</td>';
                bespokeHTML += '<td>' +  items[i].location + '</td>';
                bespokeHTML += '<td>' +  items[i].fromDate + ' - ' + items[i].toDate +'</td>';
                bespokeHTML += '<td>' +  items[i].price + ' ' + items[i].currency + '</td>';
                bespokeHTML += '</tr>';  
                bespokeItems.push(items[i]);          
            }
        }
        
        packagedHTML    += '</table>'; 
        packagedHTML    += '<input type="button" onClick="bookPackagedTrip()" value="Book Packaged Trip">'; 
        
        bespokeHTML    += '<tr><td/><td/><td>Total Price</td><td/><td/><td><div id="bespokeTripPrice"></div> </td></tr>';
        bespokeHTML    += '</table>';
        bespokeHTML    += '<input type="button" onClick="bookBespokeTrip()" value="Book Bespoke Trip">';       
        
        if (packagedItems.length > 0){
            document.getElementById('packagedTripItems').innerHTML = packagedHTML;
        }
        
        if (bespokeItems.length > 0){
            document.getElementById('bespokeTripItems').innerHTML = bespokeHTML;
        }
    }  
    
    function processPackagedSelection() {
        // do nothing at the moment
    }
    
    function processBespokeSelection() {
        // calculate total price
        var items  = document.getElementsByName("bespokeTripItemSelection");
        var totalPrice = 0.0;
        for (var i=0; i<items.length; i++) {
            
            // find the items that are checked
            if (items[i].checked == true) {
                totalPrice = totalPrice + bespokeItems[i].price;
            } 
        }
        document.getElementById('bespokeTripPrice').innerHTML = totalPrice + ' ' + bespokeItems[0]. currency;
    }        
    
    function bookPackagedTrip() {   
        // find first selected trip item
        var trip = null;
        var items  = document.getElementsByName("packagedTripItemSelection");
        for (var i=0; i<items.length; i++) {
            
            // find the items that are checked
            if (items[i].checked == true) {
                trip = copyTrip(packagedItems[i]);
                break;
            } 
        }
            
        if (trip != null) { 
            // book trip        
            scaToursBooking.bookTrip(cartId, trip);
            
            // reset the display
            reset();
            
            // re-populate the cart with all entries
            getCartTrips();
        } else {
            alert ("Please select a trip")
        }
    }   
    
    function bookBespokeTrip() {
        // create a trip object
        var trip = getTrip();    
        
        // add selected trip items to trip
        var items  = document.getElementsByName("bespokeTripItemSelection");
        for (var i=0; i<items.length; i++) {
            
            // find the items that are checked
            if (items[i].checked == true) {
                trip.tripItems.push(copyTrip(bespokeItems[i]));
            } 
        }
            
        if (trip.tripItems.length > 0) { 
            // book trip        
            scaToursBooking.bookTrip(cartId, trip);
            
            // reset the display
            reset();
            
            // re-populate the cart with all entries
            getCartTrips();
        } else {
            alert ("Please select some trip items!")
        }
    } 
    
    function getCartTrips() {
        scaToursCart.getTrips(cartId, getCartTrips_response);
    }
    
    function getCartTrips_response(trips, exception) {
        if(exception){
            alert(exception.javaStack);
            return;
        }
        var itemsHTML = '';
        var totalPrice  = 0.0;
        
        for (var x=0; x<trips.length; x++){
            itemsHTML += '<h3>Trip - ' + trips[x].id + '</h3>';
            itemsHTML += '<table border="0">';
            itemsHTML += '<tr>';
            itemsHTML += '<td>Booking Ref</td><td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>';
            itemsHTML += '</tr>';
            
            if (trips[x].type == "Trip") {
                itemsHTML += '<tr>';
                itemsHTML += '<td>' +  trips[x].bookingCode + '</td>';
                itemsHTML += '<td>' +  trips[x].name + '</td>';
                itemsHTML += '<td>' +  trips[x].description + '</td>';
                itemsHTML += '<td>' +  trips[x].location + '</td>';
                itemsHTML += '<td>' +  trips[x].fromDate + ' - ' + trips[x].toDate +'</td>';
                itemsHTML += '<td>' +  trips[x].price + ' ' + trips[x].currency + '</td>';
                itemsHTML += '</tr>';
                totalPrice = totalPrice + trips[x].price;
            
            } else {
                var tripItems = trips[x].tripItems;
            
                for (var i=0; i<tripItems.length; i++) {
                    itemsHTML += '<tr>';
                    itemsHTML += '<td>' +  tripItems[i].bookingCode + '</td>';
                    itemsHTML += '<td>' +  tripItems[i].name + '</td>';
                    itemsHTML += '<td>' +  tripItems[i].description + '</td>';
                    itemsHTML += '<td>' +  tripItems[i].location + '</td>';
                    itemsHTML += '<td>' +  tripItems[i].fromDate + ' - ' + tripItems[i].toDate +'</td>';
                    itemsHTML += '<td>' +  tripItems[i].price + ' ' + tripItems[i].currency + '</td>';
                    itemsHTML += '</tr>';
                    totalPrice = totalPrice + tripItems[i].price;
                }
            }
            
            itemsHTML    += '</table>';
        }
        
        document.getElementById('cartItems').innerHTML = itemsHTML;  
        document.getElementById('cartPrice').innerHTML = totalPrice + ' ' + trips[0].currency; 
    }     
    
    function checkout() {        
        scaToursCart.checkout(cartId);
        
        document.getElementById('packagedTripItems').innerHTML = "";
        document.getElementById('bespokeTripItems').innerHTML = "";
        document.getElementById('cartItems').innerHTML = "Thank you for shopping with SCA Tours";
        document.getElementById('cartPrice').innerHTML = "";
        searchResponseItems = null;
        tripItems = null;
    }   
    
    function purchase() { 
    }
	
</script>

</head>

<body onload="init()" background="">
	<img src="scatours.png" border="0" />
	<div id="scatours">
        <form name="searchForm"> 
            <h3>Search for trips, 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="FLR"></td>
                </tr>
                <tr>
                    <td>Start Date:</td>
                    <td><input type="text" name="fromDate" value="06/12/09"></td>
                    <td>End Date:</td>
                    <td><input type="text" name="toDate" value="13/12/09"></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="packagedTripForm">
            <div id="packagedTripItems"></div>    
        </form>         
        <form name="bespokeTripForm">
            <div id="bespokeTripItems"></div>    
        </form> 
        <form name="cartForm">
            <h3>Shopping Cart</h3>
            <div id="cartItems"></div>
            <br/>  
            Total Price: <div id="cartPrice"></div>
            <br/>          
            <input type="button" onClick="checkout()" value="Checkout"> 
        </form>         
	</div>
  
</body>
</html>