summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/ui-contribution/scatours.html
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/travelsample/ui-contribution/scatours.html')
-rw-r--r--sandbox/travelsample/ui-contribution/scatours.html361
1 files changed, 235 insertions, 126 deletions
diff --git a/sandbox/travelsample/ui-contribution/scatours.html b/sandbox/travelsample/ui-contribution/scatours.html
index 294c350ae1..f4206548c0 100644
--- a/sandbox/travelsample/ui-contribution/scatours.html
+++ b/sandbox/travelsample/ui-contribution/scatours.html
@@ -27,17 +27,18 @@
<script language="JavaScript">
//@Reference
- var scaToursSearch = new Reference("scaToursSearch");
+ var scaToursCatalog = new Reference("scaToursCatalog");
//@Reference
var scaToursBooking = new Reference("scaToursBooking");
+
+ //@Reference
+ var scaToursCart = new Reference("scaToursCart");
//local state
- var currentCartId;
- var tripIds = [];
- var currentTripIdIndex = -1;
- var searchItems;
- var cartItems;
+ var packagedItems;
+ var bespokeItems;
+ var cartId;
//the constructor for trip leg beans
function TripLegType(id,
@@ -55,25 +56,83 @@
}
function getTripLeg(){
- return new TripLegType(tripIds[currentTripIdIndex],
- document.travelForm.fromLocation.value,
- document.travelForm.toLocation.value,
- document.travelForm.fromDate.value,
- document.travelForm.toDate.value,
- document.travelForm.noOfPeople.value);
+ 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 {
- addCart();
+ 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() {
- scaToursSearch.search(getTripLeg(), search_response);
+ scaToursCatalog.search(getTripLeg(), search_response);
}
function search_response(items, exception) {
@@ -81,138 +140,191 @@
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>';
+
+ 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++) {
- 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>';
+ 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]);
+ }
}
- responseHTML += '</table>';
+ packagedHTML += '</table>';
+ packagedHTML += '<input type="button" onClick="bookPackagedTrip()" value="Book Packaged Trip">';
- document.getElementById('searchResponse').innerHTML = responseHTML;
+ 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">';
- searchItems = items;
+ if (packagedItems.length > 0){
+ document.getElementById('packagedTripItems').innerHTML = packagedHTML;
+ }
+
+ if (bespokeItems.length > 0){
+ document.getElementById('bespokeTripItems').innerHTML = bespokeHTML;
+ }
}
- function processSelection() {
+ function processPackagedSelection() {
// do nothing at the moment
}
-
- function addItemsToCart() {
- var items = document.tripForm.items;
-
+
+ function processBespokeSelection() {
+ // calculate total price
+ var items = document.getElementsByName("bespokeTripItemSelection");
+ var totalPrice = 0.0;
for (var i=0; i<items.length; i++) {
- // notify the server of the change
+ // find the items that are checked
if (items[i].checked == true) {
- scaToursBooking.addTripItem(currentCartId, tripIds[currentTripIdIndex], items[i].value);
- } else {
- scaToursBooking.removeTripItem(currentCartId, tripIds[currentTripIdIndex], items[i].value);
- }
+ 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();
- scaToursBooking.getTripItems(currentCartId, getTripItems_response);
- }
+ // 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 getTripItems() {
- scaToursBooking.getTripItems(currentCartId, getTripItems_response);
+ function getCartTrips() {
+ scaToursCart.getTrips(cartId, getCartTrips_response);
}
- function getTripItems_response(items, exception) {
+ function getCartTrips_response(trips, exception) {
if(exception){
alert(exception.javaStack);
return;
}
var itemsHTML = '';
+ var totalPrice = 0.0;
- for (var x=0; x<=currentTripIdIndex; x++){
- var tripId = tripIds[x]
- itemsHTML += '<h3>Trip - ' + tripId + '</h3>';
+ for (var x=0; x<trips.length; x++){
+ itemsHTML += '<h3>Trip - ' + trips[x].id + '</h3>';
itemsHTML += '<table border="0">';
itemsHTML += '<tr>';
- itemsHTML += '<td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>';
+ itemsHTML += '<td>Booking Ref</td><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++) {
- if (items[i].tripId == tripId) {
+ 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>' + 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 += '<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('tripItems').innerHTML = itemsHTML;
-
- scaToursBooking.getTotalPrice(currentCartId, getTotalPrice_response);
- }
-
- function getTotalPrice_response(totalPrice, exception) {
- if(exception){
- alert(exception.javaStack);
- return;
- }
- document.getElementById('totalPrice').innerHTML = totalPrice;
- }
-
- function addCart() {
- scaToursBooking.addCart(addCart_response);
-
- document.getElementById('searchResponse').innerHTML = "";
- document.getElementById('tripItems').innerHTML = "";
- document.getElementById('totalPrice').innerHTML = "";
- currentTripIdIndex = -1;
- tripIds = [];
- }
-
- function addCart_response(cartId, exception) {
- if(exception){
- alert(exception.javaStack);
- return;
- }
- currentCartId = cartId
-
- if (currentTripIdIndex == -1){
- addTrip();
- }
- }
-
- function addTrip() {
- scaToursBooking.addTrip(currentCartId, addTrip_response);
- }
-
- function addTrip_response(tripId, exception) {
- if(exception){
- alert(exception.javaStack);
- return;
- }
- currentTripIdIndex++;
- tripIds[currentTripIdIndex] = tripId;
- getTripItems();
- }
+ document.getElementById('cartItems').innerHTML = itemsHTML;
+ document.getElementById('cartPrice').innerHTML = totalPrice + ' ' + trips[0].currency;
+ }
function checkout() {
- scaToursBooking.checkout(currentCartId);
+ scaToursCart.checkout(cartId);
document.getElementById('searchResponse').innerHTML = "";
- document.getElementById('tripItems').innerHTML = "Thank you for shopping with SCA Tours";
- document.getElementById('totalPrice').innerHTML = "";
+ document.getElementById('cartItems').innerHTML = "Thank you for shopping with SCA Tours";
+ document.getElementById('cartPrice').innerHTML = "";
searchResponseItems = null;
tripItems = null;
}
@@ -227,21 +339,21 @@
<body onload="init()" background="">
<img src="scatours.png" border="0" />
<div id="scatours">
- <form name="travelForm">
- <h3>Search for hotels, flights and cars</h3>
+ <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="ANU"></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/08"></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/08"></td>
+ <td><input type="text" name="toDate" value="13/12/09"></td>
</tr>
<tr>
<td>Number of people:</td>
@@ -258,23 +370,20 @@
<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/>
+ <form name="packagedTripForm">
+ <div id="packagedTripItems"></div>
+ </form>
+ <form name="bespokeTripForm">
+ <div id="bespokeTripItems"></div>
+ </form>
+ <form name="cartForm">
<h3>Shopping Cart</h3>
- <h3><div id="cartId"></h3>
- <div id="tripItems"></div>
- <br/>
- <h3>Cart Totals</h3>
- Total Price: <div id="totalPrice"></div>
- <br/>
- <input type="button" onClick="addCart()" value="Reset Cart">
- <input type="button" onClick="addTrip()" value="Create New Trip">
+ <div id="cartItems"></div>
+ <br/>
+ Total Price: <div id="cartPrice"></div>
+ <br/>
<input type="button" onClick="checkout()" value="Checkout">
- </form>
+ </form>
</div>
</body>