summaryrefslogtreecommitdiffstats
path: root/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-10-23 17:56:00 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-10-23 17:56:00 +0000
commita6e0a1a959b837f1441de68e070f53dee9e35a55 (patch)
treecc0a0d394b0df259c43c7b3001a48bd3ed4e67c1 /sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html
parentf60bcd37dc61721f97fd2f3f99c62c16e0125513 (diff)
Updating store with new vegetables catalog and adding basic support for shoppingCart services using JSON-RPC
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@829149 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html108
1 files changed, 105 insertions, 3 deletions
diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html b/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html
index cd9cff53a9..2fc5fcc434 100644
--- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html
+++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html
@@ -1,6 +1,25 @@
+<!--
+ * 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>Store</title>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<title>Online Store - Powered by Apache Tuscany</title>
<script type="text/javascript" src="dojo/dojo/dojo.js"></script>
@@ -11,6 +30,10 @@
<script language="JavaScript">
var catalog = new dojo.rpc.JsonService("/catalogAggregator?smd");
+
+ var shoppingCart = new dojo.rpc.JsonService("/shoppingCart/Cart?smd");
+
+ var shoppingTotal = new dojo.rpc.JsonService("/shoppingCart/Total?smd");
var catalogItems;
@@ -25,9 +48,76 @@
catalogItems = items;
}
+ // This handles the response from shoppingCart.getAll
+ // which is a collection of Entry<K,D>
+ function shoppingCart_getResponse(items) {
+ var list='';
+ for (var i=0; i<items.length; i++) {
+ //get the actual item, that is Entry.data
+ var item = items[i].data;
+ // process its attributes
+ var name = item.name;
+ var price = item.price
+ list += name + ' - ' + price + ' <br>';
+ }
+ document.getElementById("shoppingCart").innerHTML = list;
+
+ if (items.length != 0) {
+ try {
+ shoppingTotal.getTotal().addCallback(shoppingTotal_getTotalResponse);
+ }
+ catch(e){
+ alert(e);
+ }
+ }
+ }
+
+ function shoppingTotal_getTotalResponse(total,exception) {
+ if(exception) {
+ alert(exception.message);
+ return;
+ }
+ document.getElementById('total').innerHTML = total;
+ }
+
+ function shoppingCart_postResponse(entry) {
+ shoppingCart.getAll().addCallback(shoppingCart_getResponse);
+ }
+
+ function addToCart() {
+ var items = document.catalogForm.items;
+ var j = 0;
+ for (var i=0; i<items.length; i++)
+ if (items[i].checked) {
+ shoppingCart.post("", catalogItems[i]).addCallback(shoppingCart_postResponse);
+ items[i].checked = false;
+ }
+ }
+ function checkoutCart() {
+ document.getElementById('store').innerHTML='<h2>' +
+ 'Thanks for Shopping With Us!</h2>'+
+ '<h2>Your Order</h2>'+
+ '<form name="orderForm">'+
+ document.getElementById('shoppingCart').innerHTML+
+ '<br>'+
+ document.getElementById('total').innerHTML+
+ '<br>'+
+ '<br>'+
+ '<input type="submit" value="Continue Shopping">'+
+ '</form>';
+ shoppingCart.del("");
+ }
+ function deleteCart() {
+ shoppingCart.del("");
+ document.getElementById('shoppingCart').innerHTML = "";
+ document.getElementById('total').innerHTML = "";
+ }
+
+
function init() {
try {
catalog.get().addCallback(catalog_getResponse);
+ shoppingCart.get("").addCallback(shoppingCart_getResponse);
} catch (e) {
alert(e);
}
@@ -44,10 +134,22 @@
<h2>Catalog</h2>
<form name="catalogForm">
<div id="catalog" ></div>
- <br>
+ <br>
+ <input type="button" onClick="addToCart()" value="Add to Cart">
</form>
- <br>
+
+ <br>
+
+ <h2>Your Shopping Cart</h2>
+ <form name="shoppingCartForm">
+ <div id="shoppingCart"></div>
+ <br>
+ <div id="total"></div>
+ <br>
+ <input type="button" onClick="checkoutCart()" value="Checkout">
+ <input type="button" onClick="deleteCart()" value="Empty">
+ </form>
</div>
</body>
</html>