aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/wire/demos/markup/demo_ConditionalActions.html
blob: ea0ca645661f22542acb31993b0ee0e5ecafff3a (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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!--
	This file demonstrates how the dojox.wire code can be used to do declarative
	wiring of events.  Specifically, it shows how you can wire actions to set values 
	across to other widgets, but only if certain conditions are met.
-->
<html>
<head>
	<title>Conditional Actions Demo</title>
	<style type="text/css">

		@import "../../../../dijit/themes/tundra/tundra.css";
		@import "../../../../dojo/resources/dojo.css";
		@import "../../../../dijit/tests/css/dijitTests.css";
		@import "../TableContainer.css";

		.splitView {
			width: 90%;
			height: 90%;
			border: 1px solid #bfbfbf;
			border-collapse: separate;
		}

		b {
			float: left;
		}

		.rJustified {
			float: right;
		}

	</style>

	<script type="text/javascript" src="../../../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
	<script type="text/javascript">
		dojo.require("dojo.parser");
		dojo.require("dojo.data.ItemFileReadStore");
		dojo.require("dojox.wire");
		dojo.require("dojox.wire.ml.Invocation");
		dojo.require("dojox.wire.ml.DataStore");
		dojo.require("dojox.wire.ml.Transfer");
		dojo.require("dojox.wire.ml.Data");
		dojo.require("dijit.form.TextBox");
		dojo.require("dijit.form.CheckBox");
		dojo.require("dijit.form.ComboBox");
	</script>
</head>

<body class="tundra">

	<!-- Layout -->
	<font size="3"><b>Demo of Conditional Actions:</b></font><br/><br/>
	This demo shows how you can use actions to read and set widget values, as well as have actions only occur if 
	if certain conditions are met, such as cloning values as they are typed from the billing address over to the
	shipping address if the 'Use Same Address' checkbox is checked true.
	<br/>
	<br/>
	<div dojoType="dojo.data.ItemFileReadStore" url="states.json" jsId="statesStore"></div>
	<table width="100%">
		<tr>
			<td colspan="2" align="center">
				Use Same Address: <div dojoType="dijit.form.CheckBox" id="useSameAddress" checked="true"></div>
			</td>
		</tr>
		<tr>
			<td>
				<b>Billing Address</b>
			</td>
			<td>
				<b>Shipping Address</b>
			</td>
		</tr>

		<tr>
			<td>
				<b>Name:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="BillingName" name="billingname" value=""  size="50"></div>
			</td>
			<td>
				<b>Name:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="ShippingName" name="shippingname" value="" disabled="true" size="50"></div>
			</td>
		</tr>
		<tr>
			<td>
				<b>Address 1:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="BillingAddress1" name="billingaddress1" value=""  size="50"></div>
			</td>
			<td>
				<b>Address 1:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="ShippingAddress1" name="shippingaddress1" value="" disabled="true" size="50"></div>
			</td>
		</tr>
		<tr>
			<td>
				<b>Address 2:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="BillingAddress2" name="billingaddress2" value=""  size="50"></div>
			</td>
			<td>
				<b>Address 2:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="ShippingAddress2" name="shippingaddress2" value="" disabled="true" size="50"></div>
			</td>
		</tr>
		<tr>
			<td>
				<b>City:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="BillingCity" name="billingcity" value=""  size="50"></div>
			</td>
			<td>
				<b>City:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="ShippingCity" name="shippingcity" value="" disabled="true" size="50"></div>
			</td>
		</tr>
		<tr>
			<td>
				<b>State:</b> <div class="rJustified" dojoType="dijit.form.ComboBox" searchAttr="name" id="BillingState" name="billingstate" value=""   store="statesStore" size="46"></div>
			</td>
			<td>
				<b>State:</b> <div class="rJustified" dojoType="dijit.form.ComboBox" searchAttr="name" id="ShippingState" name="shippingstate" value="" store="statesStore" disabled="true" size="46"></div>
			</td>
		</tr>
		<tr>
			<td>
				<b>Zip code:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="BillingZip" name="billingzip" value=""  size="50"></div>
			</td>
			<td>
				<b>Zip code:</b> <div class="rJustified" dojoType="dijit.form.TextBox" id="ShippingZip" name="shippingzip" value="" disabled="true" size="50"></div>
			</td>
		</tr>
	</table>


	<!-------------------------------- Using dojox.wire, declaratively wire up the widgets. --------------------------->

	<!--
		This is a simple data map so that the attributes we support modifying on ComboBox, TextField, etc, are lookupable.
		since steAttribute(attr, value), replaced the single attribute setDisabled
	-->
	<div dojoType="dojox.wire.ml.Data"
		id="attributesMap">
		<div dojoType="dojox.wire.ml.DataProperty"
			name="disabled"
			value="disabled"></div>
	</div>


	<!-- 
		Enable/disable the Right hand side of the shipping address view based on the checkbox events. 
	-->
	<div dojoType="dojox.wire.ml.Action"
		trigger="useSameAddress"
		triggerEvent="setChecked">
		<!--
			Trigger a setting of the Shipping fields' input state based on the state of the checkbox.
		-->
		<div dojoType="dojox.wire.ml.Invocation" object="ShippingName"    method="setAttribute" parameters="attributesMap.disabled, arguments[0]"></div>
		<div dojoType="dojox.wire.ml.Invocation" object="ShippingAddress1"    method="setAttribute" parameters="attributesMap.disabled, arguments[0]"></div>
		<div dojoType="dojox.wire.ml.Invocation" object="ShippingAddress2"    method="setAttribute" parameters="attributesMap.disabled, arguments[0]"></div>
		<div dojoType="dojox.wire.ml.Invocation" object="ShippingCity"    method="setAttribute" parameters="attributesMap.disabled, arguments[0]"></div>
		<div dojoType="dojox.wire.ml.Invocation" object="ShippingState"    method="setAttribute" parameters="attributesMap.disabled, arguments[0]"></div>
		<div dojoType="dojox.wire.ml.Invocation" object="ShippingZip"    method="setAttribute" parameters="attributesMap.disabled, arguments[0]"></div>
	</div>    

	<!-- 
		Clone the values of form fields while typing based on the setting of the checkbox.
	-->
	<div dojoType="dojox.wire.ml.Action"
		trigger="BillingName"
		triggerEvent="onkeyup">
		<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>        
		<div dojoType="dojox.wire.ml.Transfer" source="BillingName.value" target="ShippingName.value"></div>
	</div>    
	<div dojoType="dojox.wire.ml.Action"
		trigger="BillingAddress1"
		triggerEvent="onkeyup">
		<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>        
		<div dojoType="dojox.wire.ml.Transfer" source="BillingAddress1.value" target="ShippingAddress1.value"></div>
	</div>    
	<div dojoType="dojox.wire.ml.Action"
		trigger="BillingAddress2"
		triggerEvent="onkeyup">
		<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>        
		<div dojoType="dojox.wire.ml.Transfer" source="BillingAddress2.value" target="ShippingAddress2.value"></div>
	</div>
	<div dojoType="dojox.wire.ml.Action"
		trigger="BillingCity"
		triggerEvent="onkeyup">
		<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>        
		<div dojoType="dojox.wire.ml.Transfer" source="BillingCity.value" target="ShippingCity.value"></div>
	</div>    
	<div dojoType="dojox.wire.ml.Action"
		trigger="BillingState"
		triggerEvent="onChange">
		<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>        
		<div dojoType="dojox.wire.ml.Transfer" source="BillingState.value" target="ShippingState.value"></div>
	</div>    

	<div dojoType="dojox.wire.ml.Action"
		trigger="BillingZip"
		triggerEvent="onkeyup">
		<div dojoType="dojox.wire.ml.ActionFilter" required="useSameAddress.checked" requiredValue="true" type="boolean"></div>        
		<div dojoType="dojox.wire.ml.Transfer" source="BillingZip.value" target="ShippingZip.value"></div>
	</div>    


	<!-- 
		Clone the values of form fields from billing over to shipping  over if the 
		useSameAddress checkbox is set back to true.
	-->
	<div dojoType="dojox.wire.ml.Action"
		trigger="useSameAddress"
		triggerEvent="setChecked">
		<div dojoType="dojox.wire.ml.ActionFilter" required="arguments[0]" requiredValue="true" type="boolean"></div>        

		<!--
			Note that this uses the basic 'property' form of copying the property over and setting it.  The Wire
			code supports both getX and setX functions of setting a property as well as direct access.  It first looks
			for the getX/setX functions and if present, uses them.  If missing, it will just do direct access.  Because
			of the standard getValue/setValue API of dijit form widgets, transfers work well and are compact.   
		-->
		<div dojoType="dojox.wire.ml.Transfer" source="BillingName.value" target="ShippingName.value"></div>
		<div dojoType="dojox.wire.ml.Transfer" source="BillingAddress1.value" target="ShippingAddress1.value"></div>
		<div dojoType="dojox.wire.ml.Transfer" source="BillingAddress2.value" target="ShippingAddress2.value"></div>
		<div dojoType="dojox.wire.ml.Transfer" source="BillingCity.value" target="ShippingCity.value"></div>
		<div dojoType="dojox.wire.ml.Transfer" source="BillingState.value" target="ShippingState.value"></div>
		<div dojoType="dojox.wire.ml.Transfer" source="BillingZip.value" target="ShippingZip.value"></div>
	</div>

</body>
</html>