My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
xmlns:javascript="http://www.w3.org/2002/xforms#inline">
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
<meta name="AUTHOR" content="John M. Boyer" />
<title>Purchase Order Application XForm</title>
<script src="../../src/ubiquity-loader.js" type="text/javascript">/**/</script>
<script src="format.js" type="text/javascript">/**/</script>
<link href="style/gen_default.css" rel="stylesheet"></link>
</head>
<body class="yui-skin-sam">
<xforms:model id="model">
<!-- The real data instance. This will b changed to using a resource
attribute, rather than src. -->
<xforms:instance id="po" src="purchaseOrderInstance.xml"></xforms:instance>

<!-- The sales tax rate, which is obtained from the external source. -->
<xforms:instance id='taxrate' src="taxrate.xml"></xforms:instance>

<!-- This instance contains the product list, which is externally defined. -->
<xforms:instance id='products' src="productList/productList.xml"></xforms:instance>

<!-- The instance data and type needed to attach the logo -->
<xforms:instance id="logo">
<logo xmlns="" xsi:type="xsd:anyURI">KnowledgeTreeLogo.jpg</logo>
</xforms:instance>

<!-- The total is just the sum of the subtotal and the tax; any time
those change, the total is automatically updated -->
<xforms:bind nodeset="total" calculate="../subtotal + ../tax"></xforms:bind>

<!-- We have a maximum of 200 dollars on the purchase order -->
<xforms:bind nodeset="total" constraint="self::total &lt;= 200"></xforms:bind>

<!-- The tax is just the subtotal times the tax rate -->
<xforms:bind nodeset="tax" calculate="../subtotal * instance('taxrate')"></xforms:bind>

<!-- The subtotal is the sum of all the line totals. Any time a row is
inserted, deleted or changed, the subtotal is automatically updated.
The calculate uses the 'node set' feature of XPath to get however
many line total elements exist for the summation. -->
<xforms:bind nodeset="subtotal" calculate="sum(../order/item/itemtotal)"></xforms:bind>

<!-- The node set feature of XPath is used to get all the line total
elements and set a calculation for each one. A line total is
just the unit cost times the quantity. Any time a new row is
inserted, this declaration automatically creates a new line total
calculation for it. An update of unit cost or quantity on any row
automatically updates the line total of that row, which then causes
the subtotal, tax and total to be updated automatically. Even though
those calculations are declared before this one, XForms reorders the
calculations so that they run in the order that makes sense. -->
<xforms:bind nodeset="order/item/itemtotal" calculate="../unitcost * ../qty"></xforms:bind>

<!-- Once a purchase item is created, the user must specify a quantity. -->
<xforms:bind nodeset="order/item/qty" type="xsd:positiveInteger"></xforms:bind>

<!-- Once a purchase item is created, the user must choose a product name. -->
<xforms:bind nodeset="order/item/product" required="true()"></xforms:bind>

<!-- This submission submits the data to a server script that bounces the
data back to us. This submission will eventually use event context to
determine different types of submission failures. -->

<xforms:submission id="makePurchase"
method="post"
includenamespaceprefixes=""
action="http://xformstest.org/cgi-bin/echo.sh">
<xforms:message ev:event="xforms-submit-error" level="modal" if="event('error-type')!='validation-error'">Unable to submit. Please try again later.</xforms:message>
<xforms:message ev:event="xforms-submit-error" level="modal" if="event('error-type')='validation-error'">Some of the data on this form is invalid. Please correct errors and try again.</xforms:message>
</xforms:submission>
</xforms:model>

<xforms:output class="company_motto" ref="instance('logo')" mediatype="image/*"></xforms:output>


<xforms:output class="company_name">
<xforms:label>Superior School Supplies</xforms:label>
</xforms:output>

<hr class="rule"></hr>

<xforms:trigger>
<xforms:label>Add to Order</xforms:label>
<xforms:action ev:event="DOMActivate">

<!-- Insert a new item after the currently indexed item
(the last focused item before this trigger was activated) -->
<xforms:insert context="order" nodeset="item" at="index('orderTable')"
position="after" origin="../prototype/item"></xforms:insert>

<!-- Send the focus to the new item in the order table -->
<xforms:setfocus control="orderTable"></xforms:setfocus>

</xforms:action>
</xforms:trigger>

<xforms:trigger>
<xforms:label>Delete from Order</xforms:label>
<xforms:action ev:event="DOMActivate">

<!-- Delete the currently indexed item -->
<xforms:delete nodeset="order/item" at="index('orderTable')"></xforms:delete>

<!-- Insert a blank item if the last one was just deleted -->
<xforms:insert context="order" origin="../prototype/item"
if="count(/po/order/item)=0"></xforms:insert>

<!-- Put the focus to the indexed item of the order table -->
<xforms:setfocus control="orderTable"></xforms:setfocus>

</xforms:action>
</xforms:trigger>

<xforms:submit submission="makePurchase">
<xforms:label>Submit Order</xforms:label>
</xforms:submit>

<hr class="rule"/>
<!--
<table summary="List of items to purchase">
<thead>
<tr>
<th>Product Name</th>
<th>Unit Cost</th>
<th>Quantity</th>
<th>Product Total</th>
</tr>
</thead>
<tbody>
-->
<xforms:repeat nodeset="order/item" id="orderTable" startindex="1">
<xforms:select1 ref="product" appearance="minimal">
<xforms:label>Choose product</xforms:label>
<xforms:itemset nodeset="instance('products')/product">
<xforms:label>
<xforms:output ref="@name"></xforms:output>
<xforms:output ref="." mediatype="image/*"></xforms:output>
</xforms:label>
<xforms:value ref="@code"></xforms:value>
</xforms:itemset>
<xforms:action ev:event="xforms-value-changed">
<xforms:setvalue ref="../unitcost"
value="instance('products')/product[@code=current()/../product]/@unitcost">
</xforms:setvalue>
</xforms:action>
</xforms:select1>

<xforms:input ref="unitcost">
<xforms:label>Unit Cost</xforms:label>
<xforms:hint>The unit cost of the selected product</xforms:hint>
</xforms:input>

<xforms:input ref="qty">
<xforms:label>Product Quantity</xforms:label>
<xforms:hint>Enter desired quantity of the product</xforms:hint>
<xforms:alert>This must be a positive whole number value.</xforms:alert>
</xforms:input>

<xforms:output ref="itemtotal" value="javascript:currency(number())">
<xforms:label>Product Total</xforms:label>
<xforms:hint>The cost for all units of this product</xforms:hint>
</xforms:output>
</xforms:repeat>

<hr size="6" class="rule"/>

<xforms:output ref="subtotal" class="table_summary regular" value="javascript:currency(number())">
<xforms:label>Subtotal: </xforms:label>
</xforms:output>

<xforms:output ref="tax" class="table_summary regular" value="javascript:currency(number())">
<xforms:label>Tax: </xforms:label>
</xforms:output>

<xforms:output ref="total" class="table_summary regular" value="javascript:currency(number())">
<xforms:label>Total: </xforms:label>
<xforms:alert>The maximum purchase order is 200 dollars.</xforms:alert>
</xforms:output>

<hr size="6" class="rule"></hr>

</body>
</html>

Change log

r2422 by boy...@ca.ibm.com on Mar 15, 2009   Diff
Committing r2421 validation-fixes-2 to
trunk after review.
Go to: 
Project members, sign in to write a code review

Older revisions

r2018 by wellsk0705 on Feb 27, 2009   Diff
In the spirit of just fixing a unit-
test, purchaseOrder.html had a messed
up script tag, and was missing the
yui-skin-sam on the body element.
Whilst the default.css needed the
...
r1597 by bryan.kyle on Dec 17, 2008   Diff
Phase 1 of the XPath/JS bridge.
r1583 by nkling on Dec 15, 2008   Diff
restore trunk
All revisions of this file

File info

Size: 9445 bytes, 189 lines

File properties

svn:mime-type
text/html
svn:eol-style
native
Powered by Google Project Hosting