Debian Codegraph @

dojox/mvc/tests/test_mvc_new_label_and_totals.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>MVC Test for dynamic label and calculating totals</title>
6 <style type="text/css">
7 @import "css/app-format.css";
8 @import "../../../dijit/themes/claro/claro.css";
9 .cell { width: 30%; display:inline-block; }
10 </style>
11 <script type="text/javascript" data-dojo-config="parseOnLoad:0,isDebug:1,async:1,mvc:{debugBindings:1}" src="../../../dojo/dojo.js"></script>
12 <script type="text/javascript">
13 var model;
14
15 require([
16 'dojo/parser',
17 'dojo/ready',
18 "dojox/mvc/getStateful",
19 'dojox/mvc/at',
20 'dijit/form/TextBox',
21 'dijit/form/Button',
22 'dojox/mvc/Group',
23 'dojox/mvc/Repeat',
24 'dojox/mvc/Output'
25 ], function(parser, ready, getStateful, at){
26
27 // Order data
28 orderData = {
29 "Serial" : "111",
30 "First" : "",
31 "Lab" : "TEST",
32 "Last" : "last",
33 "Email" : "email",
34 "Age" : "33"
35 };
36
37 // Initial sum data
38 sumData = {
39 "one" : 1,
40 "two" : 2,
41 "three" : 3,
42 "four" : 4,
43 "total" : 10
44 };
45
46 // Initial repeat sum data
47 sumRepeatData = {
48 "list" : [
49 {"item" : 1},
50 {"item" : 2},
51 {"item" : 3},
52 {"item" : 4}
53 ],
54 "total" : 10
55 };
56
57 sumValuesConverter = {
58 format: function(value){
59 console.log("in sumValuesConverter format value ="+value);
60 value = value || 0;
61 return value;
62 },
63 parse: function(value){
64 console.log("in sumValuesConverter parse value ="+value);
65 recomputeTotal();
66 return value;
67 }
68 };
69
70 ageLabelConverter = {
71 format: function(value){
72 console.log("in ageLabelConverter format value ="+value);
73 if(!value){
74 return "Enter Age";
75 }else{
76 return "Enter "+value+"'s age";
77 }
78 },
79 parse: function(value){
80 console.log("in ageLabelConverter parse value ="+value);
81 return value;
82 }
83 };
84
85
86 sumRepeatValuesConverter = {
87 format: function(value){
88 console.log("in sumRepeatValuesConverter format value ="+value);
89 value = value || 0;
90 recomputeRepeatTotal();
91 return value;
92 },
93 parse: function(value){
94 console.log("in sumRepeatValuesConverter parse value ="+value);
95 return value;
96 }
97 };
98
99 ready(function(){
100 parser.parse();
101 recomputeTotal();
102 });
103
104 // Old api
105 //summodel = mvc.newStatefulModel({ data : sumData });
106 //sumrepeatmodel = mvc.newStatefulModel({ data : sumRepeatData });
107 //model = mvc.newStatefulModel({ data : order });
108 // new Api
109 summodel = getStateful(sumData );
110 sumrepeatmodel = getStateful(sumRepeatData);
111 model = getStateful(orderData);
112
113
114 });
115
116 function recomputeTotal() {
117 require([
118 "dijit/registry",
119 "dojox/mvc/at"
120 ], function(registry, at){
121 var total = 0;
122 var wone = parseInt(registry.byId("oneInput").get("value")) || 0;
123 var wtwo = parseInt(registry.byId("twoInput").get("value")) || 0;
124 var wthree = parseInt(registry.byId("threeInput").get("value")) || 0;
125 var wfour = parseInt(registry.byId("fourInput").get("value")) || 0;
126 total = wone + wtwo + wthree + wfour;
127 var wtotal = registry.byId("totalOutput");
128 wtotal.set("value", total);
129 });
130 };
131
132
133 function recomputeRepeatTotal() {
134 require([
135 "dijit/registry",
136 "dojox/mvc/at"
137 ], function(registry, at){
138 var total = 0;
139 for(var i=0;i<sumrepeatmodel.list.length;i++){
140 console.log("sumrepeatmodel.list[i].item = "+sumrepeatmodel.list[i].item);
141 var item = parseInt(sumrepeatmodel.list[i].item) || 0;
142 total = total + item;
143 }
144 var wtotal = registry.byId("totalrepeatOutput");
145 wtotal.set("value", total);
146 });
147 };
148
149
150 </script>
151
152 </head>
153 <body class="claro">
154 <script type="dojo/require">at: "dojox/mvc/at"</script>
155 <div id="wrapper">
156 <div id="header">
157 <div id="navigation">
158 </div>
159 <div id="headerInsert">
160 <h2>MVC Test for dynamic label and calculating totals</h2>
161 </div>
162 </div>
163 <div id="main">
164 <div id="leftNav"></div>
165 <div id="mainContent">
166 <h4>Update Age label with first name when it is set.</h4>
167 <div data-dojo-type="dojox.mvc.Group"
168 data-dojo-props="target: model">
169 <div class="row">
170 <label class="cell" for="firstInput">Enter first name:</label>
171 <input class="cell" id="firstInput" data-dojo-type="dijit.form.TextBox"
172 data-dojo-props="value: at('rel:', 'First')">
173 </div>
174 <div class="row">
175 <label class="cell" for="lastnameInput">Enter last name:</label>
176 <input class="cell" id="lastnameInput" data-dojo-type="dijit.form.TextBox"
177 data-dojo-props="value: at('rel:', 'Last')">
178 </div>
179 <div class="row">
180 <label class="cell" for="emailInput">Enter email:</label>
181 <input class="cell" id="emailInput" data-dojo-type="dijit.form.TextBox"
182 data-dojo-props="value: at('rel:', 'Email')">
183 </div>
184 <div class="row">
185 <label data-dojo-type="dojox.mvc.Output" class="cell" for="ageInput"
186 data-dojo-props="value: at('rel:', 'First').direction(at.from).transform(ageLabelConverter)"></label>
187 <input class="cell" id="ageInput" data-dojo-type="dijit.form.TextBox"
188 data-dojo-props="value: at('rel:', 'Age')">
189 </div>
190 </div>
191 <br/>
192 <h4>Update total when any of the fields are changed.</h4>
193 <div data-dojo-type="dojox.mvc.Group"
194 data-dojo-props="target: summodel">
195 <div class="row">
196 <label class="cell" for="oneInput">Item one:</label>
197 <input class="cell" id="oneInput" data-dojo-type="dijit.form.TextBox"
198 data-dojo-props="value: at('rel:', 'one').transform(sumValuesConverter)">
199 </div>
200 <div class="row">
201 <label class="cell" for="twoInput">Item two:</label>
202 <input class="cell" id="twoInput" data-dojo-type="dijit.form.TextBox"
203 data-dojo-props="value: at('rel:', 'two').transform(sumValuesConverter)">
204 </div>
205 <div class="row">
206 <label class="cell" for="threeInput">Item three:</label>
207 <input class="cell" id="threeInput" data-dojo-type="dijit.form.TextBox"
208 data-dojo-props="value: at('rel:', 'three').transform(sumValuesConverter)">
209 </div>
210 <div class="row">
211 <label class="cell" for="fourInput">Item four:</label>
212 <input class="cell" id="fourInput" data-dojo-type="dijit.form.TextBox"
213 data-dojo-props="value: at('rel:', 'four').transform(sumValuesConverter)">
214 </div>
215 <div class="row">
216 <label class="cell" for="totalOutput">Total:</label>
217 <div class="cell" id="totalOutput" data-dojo-type="dojox.mvc.Output"
218 data-dojo-props="value: at('rel:', 'total')"></div>
219 </div>
220 <br/>
221 <h4>Update total when any of the fields are changed - Using a Repeat.</h4>
222 <div id="outergroupId" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: sumrepeatmodel">
223 <div id="repeatId" data-dojo-type="dojox.mvc.Repeat"
224 data-dojo-props="children: at('rel:', 'list')">
225 <div data-dojo-type="dojox.mvc.Group"
226 data-dojo-props="target: at('rel:${this.index}')">
227 <div class="row">
228 <label class="cell" for="input${this.index}">Item ${this.index}:</label>
229 <input class="cell" id="input${this.index}" data-dojo-type="dijit.form.TextBox"
230 data-dojo-props="value: at('rel:', 'item').transform(sumRepeatValuesConverter)">
231 </div>
232 </div>
233 </div>
234 <div class="row">
235 <label class="cell" for="totalrepeatOutput">Total:</label>
236 <div class="cell" id="totalrepeatOutput" data-dojo-type="dojox.mvc.Output"
237 data-dojo-props="value: at('rel:', 'total')"></div>
238 </div>
239 </div>
240 <br/>
241 <br/>
242 Model:
243 <button id="reset" type="button" data-dojo-type="dijit.form.Button"
244 data-dojo-props="onClick: function(){model.set(orderData);summodel.set(sumData);sumrepeatmodel.set(sumRepeatData);}">Reset</button>
245 </div></div></div>
246 </body>
247 </html>