summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-widget-runtime/src/test/resources/content/storeJS.html
blob: 6bbc285377ff975f26d39db4fed3d9d574162014 (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
<!--
    * 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>

<!-- one js include per sca component -->
<!-- For Atom, the Tuscany JavaScript client includes the model for Atom.  
	 Using this JavaScript model, users can use syntax such as:
	 item += "name=" + entry.getName() + ", price=" + entry.getContent() 
	 rather than
     item += entries[i].getElementsByTagName("content")[0].firstChild.nodeValue;
	-->
<script type="text/javascript" src="storeJS.js"></script>

<script language="JavaScript">

	//@Reference
	var catalog = new Reference("Catalog");
	
	//@Reference
	var shoppingCart = new Reference("ShoppingCart"); 
	
	//@Property
	var locale = Property("locale");

	function catalog_getResponse(items,exception) {
		if(exception){
			alert(exception.message);
			return;
		}
		var catalog = "";
		for (var i=0; i<items.length; i++)
			catalog += '<input name="items" type="checkbox" value="' + 
						items[i] + '">' + items[i]+ ' <br>';
		document.getElementById('catalog').innerHTML=catalog;
	}
	
	function shoppingCart_getResponse(feedDoc) {
	    // var xmlString = new XMLSerializer().serializeToString(feedDoc);
	    // alert("shoppingCart_getResponse feed xml=" + xmlString);
		var feed = new Feed( feedDoc );
		
		if (feed != null) {
			// var entries = feed.getElementsByTagName("entry");
			var entries = feed.getEntries();              
			var list = "";
			for (var i=0; i<entries.length; i++) {
				// var item = entries[i].getElementsByTagName("content")[0].firstChild.nodeValue;
				var item = entries[ i ].getContent().getText();
				list += item + ' <br>';
			}
			document.getElementById("shoppingCart").innerHTML = list;
			// document.getElementById('total').innerHTML = feed.getElementsByTagName("subtitle")[0].firstChild.nodeValue;
			var text =  feed.getSubtitle().getText();
			document.getElementById('total').innerHTML = text;
		}
	}
	
	function shoppingCart_postResponse(entry) {
		shoppingCart.get("", shoppingCart_getResponse);
	}				

	function addToCart() {
		var items  = document.catalogForm.items;
		var j = 0;
		for (var i=0; i<items.length; i++)
			if (items[i].checked) {
				var entry = new Entry( "cart-item" );
				entry.setContent( items[i].value );
				var entryXML = entry.toXML();
				var entry = '<entry xmlns="http://www.w3.org/2005/Atom"><title>cart-item</title><content type="text">'+items[i].value+'</content></entry>'
				shoppingCart.post(entry, 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" action="/ufs/store.html">'+
					document.getElementById('shoppingCart').innerHTML+
					'<br>'+
					document.getElementById('total').innerHTML+
					'<br>'+
					'<br>'+
					'<input type="submit" value="Continue Shopping">'+ 
				'</form>';
		shoppingCart.del("", null);
	}
	function deleteCart() {
		shoppingCart.del("", null);
		document.getElementById('shoppingCart').innerHTML = "";
		document.getElementById('total').innerHTML = "";	
	}	
	function testFeedtoXML() {
		if(exception){
			alert(exception.message);
			return;
		}
    	document.getElementById('results').innerHTML = text;
	}
	
    //alert(locale);
	catalog.get(catalog_getResponse);
	shoppingCart.get("", shoppingCart_getResponse);
</script>

</head>

<body>
<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">     
	   	<a href="../ShoppingCart/">(feed)</a>
	</form>    
  </div>
</body>
</html>