diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-04 22:02:45 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-04 22:02:45 +0000 |
commit | e8419233f758611b0b73057f685f1aff675b7e0e (patch) | |
tree | f6781463737e8eafa6df382eb131ec0743630545 /sandbox/sca-cloud-tutorial/store-merger-appengine-webapp/war/store.html | |
parent | f4a89e8eef219137bcfb625cbf770baa642312a8 (diff) |
Providing a store-merger application that explores adding new catalogs from different cloud environments to the store application
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@832884 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sandbox/sca-cloud-tutorial/store-merger-appengine-webapp/war/store.html | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/sandbox/sca-cloud-tutorial/store-merger-appengine-webapp/war/store.html b/sandbox/sca-cloud-tutorial/store-merger-appengine-webapp/war/store.html new file mode 100644 index 0000000000..aadb4ebd4f --- /dev/null +++ b/sandbox/sca-cloud-tutorial/store-merger-appengine-webapp/war/store.html @@ -0,0 +1,194 @@ +<!-- + * 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> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Online Store - Powered by Apache Tuscany</title> + +<link href="store.css" rel="stylesheet" type="text/css"> + +<script type="text/javascript" src="dojo/dojo/dojo.js"></script> + +<script type="text/javascript"> + dojo.require("dojo.rpc.JsonService"); +</script> + +<script language="JavaScript"> + + var userServices = new dojo.rpc.JsonService("/User?smd"); + + var catalog = new dojo.rpc.JsonService("/Catalog?smd"); + + var shoppingCart = new dojo.rpc.JsonService("/ShoppingCart?smd"); + + var userContext; + + var catalogItems; + + function showHeader() { + var userContextCallback = function(context) { + userContext = context; + //alert(userContext.userId + " --> " + userContext.loginUrl); + + var html=''; + if(! userContext.userId) { + html = "<a href='" + userContext.loginUrl +"'>Login</a>"; + } else { + html = userContext.email + " | <a href='" + userContext.logoutUrl +"'> Logout</a>"; + } + + document.getElementById('appHeader').innerHTML = html; + } + + userServices.getUserContext(document.URL, "").addCallback(userContextCallback); + } + + function showCatalogs() { + var catalogCallback = function(items) { + var catalog = ""; + for (var i=0; i<items.length; i++) { + var item = items[i].name + ' - ' + items[i].currencySymbol + items[i].price; + catalog += '<input name="items" type="checkbox" value="' + + item + '">' + item + ' <br>'; + } + document.getElementById('catalog').innerHTML=catalog; + catalogItems = items; + } + + catalog.get().addCallback(catalogCallback); + } + + + // 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 symbol = item.currencySymbol; + var price = item.price + list += name + ' - ' + symbol + price + ' <br>'; + } + document.getElementById("shoppingCart").innerHTML = list; + + if (items.length != 0) { + try { + shoppingCart.getTotal().addCallback(shoppingCart_getTotalResponse); + } + catch(e){ + alert(e); + } + } + } + + function shoppingCart_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.delete(""); + } + function deleteCart() { + shoppingCart.delete(""); + document.getElementById('shoppingCart').innerHTML = ""; + document.getElementById('total').innerHTML = ""; + } + + + + function init() { + try { + showHeader(); + + showCatalogs(); + + shoppingCart.getAll().addCallback(shoppingCart_getResponse); + } catch (e) { + alert(e); + } + } + + +</script> + +</head> + +<body onload="init()"> + <div id="appHeader" class="header"> + </div> + + <h1>Store</h1> + + + + <div id="store"> + <h2>Catalog</h2> + <form name="catalogForm"> + <div id="catalog" ></div> + <br> + <input type="button" onClick="addToCart()" value="Add to Cart"> + </form> + + + <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>
\ No newline at end of file |