Debian Codegraph @

dojox/mvc/tests/controllers/step9_test_mvc.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5 <title>Step 9 of test for Controllers, uses an EditStoreRefListController with holdModelUntilCommit: true.</title>
6 <style type="text/css">
7 @import "../css/app-format.css";
8 @import "../../../../dijit/themes/claro/claro.css";
9 </style>
10 <script type="text/javascript" data-dojo-config="parseOnLoad:0,isDebug:1,async:1,mvc:{debugBindings:1}" src="../../../../dojo/dojo.js"></script>
11 <script type="text/javascript">
12 var ctrl;
13
14 require([
15 'dojo/parser',
16 'dojo/_base/declare',
17 'dojo/ready',
18 'dojo/when',
19 'dojo/store/Memory',
20 'dojox/mvc/at',
21 'dojox/mvc/getStateful',
22 'dojox/mvc/EditStoreRefListController',
23 'dojox/mvc/ListController',
24 'dojox/mvc/parserExtension',
25 'dijit/form/TextBox',
26 'dijit/form/Button',
27 'dijit/form/RadioButton',
28 'dojox/mvc/Group',
29 'dojox/mvc/WidgetList',
30 'dojox/mvc/_InlineTemplateMixin',
31 'dojox/mvc/Output'
32 ], function(parser, declare, ready, when, Memory, at, getStateful,
33 EditStoreRefListController, ListController){
34 // Initial data
35 var storeData = {
36 "identifier": "id",
37 "items": [
38 {
39 "id" : "360324",
40 "AddressName" : "Home",
41 "Checked" : true,
42 "FullName" : "Mr. John Doe",
43 "Email" : "[email protected]",
44 "AddressLine1" : "123 Valley Rd.",
45 "AddressLine2" : "",
46 "City" : "Cary",
47 "State" : "NC",
48 "Zip" : "27513"
49 },
50 {
51 "id" : "360325",
52 "AddressName" : "Work",
53 "Checked" : false,
54 "FullName" : "Mr. John Doe",
55 "Email" : "[email protected]",
56 "AddressLine1" : "4567 S Miami Blvd",
57 "AddressLine2" : "Bldg:502, Office:M120",
58 "City" : "Durham",
59 "State" : "NC",
60 "Zip" : "27703"
61 }
62 ]
63 };
64
65
66 // To move from EditStoreRefListController with holdModelUntilCommit: false to use holdModelUntilCommit: true
67 // I had to add the require for dojox/mvc/at and ListController
68 //
69 // This test uses holdModelUntilCommit: true on the WidgetList, so updates to the address will not show-up in
70 // the "Verify" section and in the "Select an address" section until "Save" is pressed.
71 // But using holdModelUntilCommit: true requires use of a second controller (ctrlSource) which is a ListController
72 // and is bound to the sourceModel and cursorIndex of the first controller (ctrl).
73 //
74 // The "Verify" section and the "Select an address" section are bound to at(ctrlSource,'cursor') and at(ctrlSource, 'model') respectively.
75 // To set the Radio buttons correctly, "Checked" has to be updated in ctrl.model inside the transformRadioChecked.
76 //
77
78 var ctrlclz = declare([EditStoreRefListController], {
79
80 transformRadioChecked : {
81 format: function(checked){
82 if(checked){
83 ctrl.set('cursorIndex', this.target.index);
84 console.log("in transformRadioChecked setting cursorIndex to "+this.target.index);
85 }
86 ctrl.model[this.target.index].set("Checked", checked); // had to do this here to update the ctrl.model too.
87 return checked;
88 },
89 parse: function(checked){
90 return checked;
91 }
92 },
93
94 transformAddress2Class : {
95 format: function(value){
96 if(value && value.trim().length > 0){
97 return "row" // if AddressLine2 is set return row for class
98 }
99 return "hiderow"; // if AddressLine2 is not set return hiderow for class
100 }
101 },
102
103 addEmpty : function(empty){
104 var idx = this.model.length;
105 var data = {
106 "id" : Math.random(),
107 "AddressName" : "New Address",
108 "Checked" : true,
109 "FullName" : "",
110 "Email" : "",
111 "AddressLine1" : "",
112 "AddressLine2" : "",
113 "City" : "",
114 "State" : "",
115 "Zip" : ""
116 };
117 if(!empty){
118 data = {
119 "id" : Math.random(),
120 "AddressName" : "Copy of "+this.cursor.AddressName,
121 "Checked" : true,
122 "FullName" : "" || this.cursor.Name,
123 "Email" : this.cursor.Email,
124 "AddressLine1" : this.cursor.AddressLine1,
125 "AddressLine2" : this.cursor.AddressLine2,
126 "City" : this.cursor.City,
127 "State" : this.cursor.State,
128 "Zip" : this.cursor.Zip
129 };
130 }
131 var statefulData = getStateful(data);
132 this.model.splice(idx, 0, statefulData);
133 ctrlSource.model.splice(idx, 0, statefulData);
134 }
135
136 });
137 ctrl = new ctrlclz({store: new Memory({data:storeData}), holdModelUntilCommit: true});
138 ctrlSource = new (declare([ListController], {}))({model: at(ctrl, "sourceModel"), cursorIndex: at(ctrl, "cursorIndex")});
139 when(ctrl.queryStore(), function(){
140 parser.parse();
141 });
142 });
143 </script>
144 </head>
145 <body class="claro">
146 <script type="dojo/require">at: "dojox/mvc/at"</script>
147 <div id="wrapper">
148 <div id="main">
149 <div>
150 <h2>Step 9 of test for Controllers, uses an EditStoreRefListController with holdModelUntilCommit: true</h2>
151 <h2>Select the Shipping Address to use.</h2>
152 </div>
153
154 <div data-dojo-type="dojox/mvc/WidgetList"
155 data-dojo-mixins="dojox/mvc/_InlineTemplateMixin"
156 data-dojo-props="children: at(ctrlSource, 'model'), partialRebuild:true">
157 <script type="dojox/mvc/InlineTemplate">
158 <div>
159 <input type="radio" data-dojo-type="dijit/form/RadioButton" name="AddressName" id="radio${indexAtStartup}"
160 data-dojo-props="index: ${indexAtStartup},
161 // value: at('rel:', 'AddressName'), // do not set value on the radio button or it will also set checked.
162 checked: at('rel:', 'Checked').transform(ctrl.transformRadioChecked)"/>
163 <label class="radioLabel" for="radio${indexAtStartup}" data-dojo-type="dojox/mvc/Output"
164 data-dojo-props="value: at('rel:', 'AddressName')"></label> <br />
165 </div>
166 </script>
167 </div>
168 <div class="fullrow">
169 <button class="buttoncell" id="add" type="button" data-dojo-type="dijit/form/Button"
170 data-dojo-props="onClick: function(){ ctrl.addEmpty(true); }">New Address</button>
171 <button class="buttoncell" id="addcopy" type="button" data-dojo-type="dijit/form/Button"
172 data-dojo-props="onClick: function(){ ctrl.addEmpty(false); }">New copy of selected.</button>
173 </div>
174
175 <div class="spacer"></div>
176 <h2>Enter the Shipping Address</h2>
177
178 <div class="fullrow" data-dojo-type="dojox/mvc/Group" data-dojo-props="target: at(ctrl,'cursor')">
179 <div class="fullrow">
180 <label class="cell" for="AddressNameInput">Address Name:</label>
181 <input class="cell" id="AddressNameInput" data-dojo-type="dijit/form/TextBox"
182 data-dojo-props="value: at('rel:', 'AddressName')">
183 </div>
184 <br/>
185 <div class="fullrow">
186 <label class="cell" for="nameInput">Full Name:</label>
187 <input class="cell" id="nameInput" data-dojo-type="dijit/form/TextBox"
188 data-dojo-props="value: at('rel:', 'FullName')">
189 </div>
190 <div class="fullrow">
191 <label class="cell" for="AddressLine1Input">Address Line1:</label>
192 <input class="cell" id="AddressLine1Input" data-dojo-type="dijit/form/TextBox"
193 data-dojo-props="value: at('rel:', 'AddressLine1')">
194 </div>
195 <div class="fullrow">
196 <label class="cell" for="AddressLine2Input">Address Line2:</label>
197 <input class="cell" id="AddressLine2Input" data-dojo-type="dijit/form/TextBox"
198 data-dojo-props="value: at('rel:', 'AddressLine2')">
199 </div>
200 <div class="fullrow">
201 <label class="cell" for="cityInput">City:</label>
202 <input class="cell" id="cityInput" data-dojo-type="dijit/form/TextBox"
203 data-dojo-props="value: at('rel:', 'City')">
204 </div>
205 <div class="fullrow">
206 <label class="cell" for="stateInput">State:</label>
207 <input class="cell" id="stateInput" data-dojo-type="dijit/form/TextBox"
208 data-dojo-props="value: at('rel:', 'State')">
209 </div>
210 <div class="fullrow">
211 <label class="cell" for="zipInput">Zipcode:</label>
212 <input class="cell" id="zipInput" data-dojo-type="dijit/form/TextBox"
213 data-dojo-props="value: at('rel:', 'Zip')">
214 </div>
215 </div>
216 <br/>
217
218 <div class="fullrow">
219 <button class="buttoncell" id="reset" type="button" data-dojo-type="dijit/form/Button" data-dojo-props="onClick: function(){ ctrl.reset(); }">Reset</button>
220 <button class="buttoncell" id="commit" type="button" data-dojo-type="dijit/form/Button" data-dojo-props="onClick: function(){ ctrl.commit(); }">Save</button>
221 </div>
222
223 <br/>
224
225 <div class="fullrow" data-dojo-type="dojox/mvc/Group" data-dojo-props="target: at(ctrlSource,'cursor')">
226 <div>
227 <h2>Verify the shipping address for:
228 <div class="namecell" id="AddressNameOutput" data-dojo-type="dojox/mvc/Output"
229 data-dojo-props="value: at('rel:', 'AddressName')"></div>
230
231 </h2>
232 </div>
233 <div class="fullrow">
234 <div class="boldnamecell" data-dojo-type="dojox/mvc/Output"
235 data-dojo-props="value: at('rel:', 'FullName')"></div>
236 </div>
237 <div class="fullrow">
238 <div class="namecell" data-dojo-type="dojox/mvc/Output"
239 data-dojo-props="value: at('rel:', 'AddressLine1')"></div>
240 </div>
241 <div class="hiderow" data-mvc-bindings="class: at('rel:', 'AddressLine2').direction(at.from).transform(ctrl.transformAddress2Class)">
242 <div class="namecell" data-dojo-type="dojox/mvc/Output"
243 data-dojo-props="value: at('rel:', 'AddressLine2')"></div>
244 </div>
245 <div class="fullrow">
246 <div class="namecell" data-dojo-type="dojox/mvc/Output"
247 data-dojo-props="exprchar:'%', value: at('rel:', 'City')">%{this.value},</div>
248 <div class="namecell" data-dojo-type="dojox/mvc/Output"
249 data-dojo-props="value: at('rel:', 'State')"></div>
250 <div class="namecell" data-dojo-type="dojox/mvc/Output"
251 data-dojo-props="value: at('rel:', 'Zip')"></div>
252 </div>
253 </div>
254 </div>
255 </div>
256 </body>
257 </html>