| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 |
<title>MVC DOH Test</title> |
| 6 |
<style> |
| 7 |
@import "../../../../../dojo/resources/dojo.css"; |
| 8 |
@import "../../../../../dijit/tests/css/dijitTests.css"; |
| 9 |
@import "../css/app-format.css"; |
| 10 |
</style> |
| 11 |
<link id="themeStyles" rel="stylesheet" href="../../../../../dijit/themes/claro/claro.css"/> |
| 12 |
<script src="../../../../../dojo/dojo.js" type="text/javascript" djConfig="isDebug: true"></script> |
| 13 |
<script type="text/javascript" src="../helpers.js"></script> |
| 14 |
<script type="text/javascript"> |
| 15 |
dojo.require("dojox.mvc"); |
| 16 |
dojo.require("dojox.mvc.Group"); |
| 17 |
dojo.require("dijit.form.TextBox"); |
| 18 |
dojo.require("dijit.form.Button"); |
| 19 |
dojo.require("dojo.parser"); |
| 20 |
|
| 21 |
// Initial data with a noticeable hierarchy |
| 22 |
var order = { |
| 23 |
"Serial" : "360324", |
| 24 |
"First" : "John", |
| 25 |
"Last" : "Doe", |
| 26 |
"Email" : "[email protected]", |
| 27 |
"ShipTo" : { |
| 28 |
"Type" : "Home", |
| 29 |
"Address" : { |
| 30 |
"Street" : "123 Valley Rd", |
| 31 |
"City" : "Katonah", |
| 32 |
"State" : "NY", |
| 33 |
"Zip" : "10536" |
| 34 |
}, |
| 35 |
"Telephone" : { |
| 36 |
"AreaCode" : "123", |
| 37 |
"Landline" : { |
| 38 |
"Number" : "456-7890", |
| 39 |
"Extension" : "42" |
| 40 |
}, |
| 41 |
"Cell" : { |
| 42 |
"Number" : "765-4321" |
| 43 |
} |
| 44 |
} |
| 45 |
}, |
| 46 |
"BillTo" : { |
| 47 |
"Type" : "Office", |
| 48 |
"Address" : { |
| 49 |
"Street" : "17 Skyline Dr", |
| 50 |
"City" : "Hawthorne", |
| 51 |
"State" : "NY", |
| 52 |
"Zip" : "10532" |
| 53 |
}, |
| 54 |
"Telephone" : { |
| 55 |
"AreaCode" : "098", |
| 56 |
"Landline" : { |
| 57 |
"Number" : "765-4321", |
| 58 |
"Extension" : "24" |
| 59 |
}, |
| 60 |
"Cell" : { |
| 61 |
"Number" : "123-4567" |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
}; |
| 66 |
|
| 67 |
// The dojox.mvc.StatefulModel class creates a data model instance |
| 68 |
// where each leaf within the data model is decorated with dojo.Stateful |
| 69 |
// properties that widgets can bind to and watch for their changes. |
| 70 |
var model = dojox.mvc.newStatefulModel({ data : order }); |
| 71 |
var selectedAddr = dojox.mvc.newStatefulModel({ data : "ShipTo" }); |
| 72 |
</script> |
| 73 |
|
| 74 |
<script type="text/javascript"> |
| 75 |
dojo.require('doh.runner'); |
| 76 |
dojo.require("dijit.dijit"); // optimize: load dijit layer |
| 77 |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
| 78 |
|
| 79 |
dojo.addOnLoad(function() { |
| 80 |
|
| 81 |
doh.register("parse", function() { |
| 82 |
dojo.parser.parse(); |
| 83 |
}); |
| 84 |
|
| 85 |
// should be able to verify all of the inputs |
| 86 |
doh.register("check initial values and bindings", [{ |
| 87 |
name : "initial", |
| 88 |
runTest : function() { |
| 89 |
var serial1, bind1, addr1; |
| 90 |
//test serialInput |
| 91 |
serial1 = dijit.byId("serialInput"); |
| 92 |
if (serial1) { |
| 93 |
bind1 = serial1.get("binding"); |
| 94 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 95 |
doh.is("360324", bind1.data,"bind1.data should be set"); |
| 96 |
doh.is("360324", bind1.value,"bind1.value should be set"); |
| 97 |
} |
| 98 |
} |
| 99 |
//test addrLabel |
| 100 |
addr1 = dijit.byId("addrLabel"); |
| 101 |
if (addr1) { |
| 102 |
bind1 = addr1.get("binding"); |
| 103 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 104 |
doh.is("ShipTo", bind1.data,"bind1.data should be set"); |
| 105 |
doh.is("ShipTo", bind1.value,"bind1.value should be set"); |
| 106 |
} |
| 107 |
} |
| 108 |
//test streetInput |
| 109 |
addr1 = dijit.byId("streetInput"); |
| 110 |
if (addr1) { |
| 111 |
bind1 = addr1.get("binding"); |
| 112 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 113 |
doh.is("123 Valley Rd", bind1.data,"bind1.data should be set"); |
| 114 |
doh.is("123 Valley Rd", bind1.value,"bind1.value should be set"); |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
}]); |
| 119 |
|
| 120 |
doh.register("check BillTo", [{ |
| 121 |
name : "testBillTo", |
| 122 |
runTest : function() { |
| 123 |
setRef('addrGroup', 'model.BillTo'); |
| 124 |
|
| 125 |
var serial1, bind1, addr1; |
| 126 |
//test serialInput |
| 127 |
serial1 = dijit.byId("serialInput"); |
| 128 |
if (serial1) { |
| 129 |
bind1 = serial1.get("binding"); |
| 130 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 131 |
doh.is("360324", bind1.data,"bind1.data should be set"); |
| 132 |
doh.is("360324", bind1.value,"bind1.value should be set"); |
| 133 |
} |
| 134 |
} |
| 135 |
//test addrLabel |
| 136 |
addr1 = dijit.byId("addrLabel"); |
| 137 |
|
| 138 |
if (addr1) { |
| 139 |
bind1 = addr1.get("binding"); |
| 140 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 141 |
doh.is("ShipTo", bind1.data,"bind1.data should be set"); |
| 142 |
doh.is("BillTo", bind1.value,"bind1.value should be set"); |
| 143 |
} |
| 144 |
} |
| 145 |
//test streetInput |
| 146 |
addr1 = dijit.byId("streetInput"); |
| 147 |
if (addr1) { |
| 148 |
bind1 = addr1.get("binding"); |
| 149 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 150 |
doh.is("17 Skyline Dr", bind1.data,"bind1.data should be set"); |
| 151 |
doh.is("17 Skyline Dr", bind1.value,"bind1.value should be set"); |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
}]); |
| 156 |
|
| 157 |
doh.register("check ShipTo", [{ |
| 158 |
name : "testShipTo", |
| 159 |
runTest : function() { |
| 160 |
setRef('addrGroup', 'model.ShipTo'); |
| 161 |
|
| 162 |
var serial1, bind1, addr1; |
| 163 |
//test serialInput |
| 164 |
serial1 = dijit.byId("serialInput"); |
| 165 |
if (serial1) { |
| 166 |
bind1 = serial1.get("binding"); |
| 167 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 168 |
doh.is("360324", bind1.data,"bind1.data should be set"); |
| 169 |
doh.is("360324", bind1.value,"bind1.value should be set"); |
| 170 |
} |
| 171 |
} |
| 172 |
//test addrLabel |
| 173 |
addr1 = dijit.byId("addrLabel"); |
| 174 |
if (addr1) { |
| 175 |
bind1 = addr1.get("binding"); |
| 176 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 177 |
doh.is("ShipTo", bind1.data,"bind1.data should be set"); |
| 178 |
doh.is("ShipTo", bind1.value,"bind1.value should be set"); |
| 179 |
} |
| 180 |
} |
| 181 |
//test streetInput |
| 182 |
addr1 = dijit.byId("streetInput"); |
| 183 |
if (addr1) { |
| 184 |
bind1 = addr1.get("binding"); |
| 185 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 186 |
doh.is("123 Valley Rd", bind1.data,"bind1.data should be set"); |
| 187 |
doh.is("123 Valley Rd", bind1.value,"bind1.value should be set"); |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
}]); |
| 192 |
|
| 193 |
doh.register("change ShipTo", [{ |
| 194 |
name : "testShipTo", |
| 195 |
runTest : function() { |
| 196 |
setRef('addrGroup', 'model.ShipTo'); |
| 197 |
//set streetInput |
| 198 |
addr1 = dijit.byId("streetInput"); |
| 199 |
if (addr1) { |
| 200 |
addr1.set("value","456 Mountain Rd"); |
| 201 |
} |
| 202 |
setRef('addrGroup', 'model.BillTo'); |
| 203 |
setRef('addrGroup', 'model.ShipTo'); |
| 204 |
|
| 205 |
var serial1, bind1, addr1; |
| 206 |
//test serialInput |
| 207 |
serial1 = dijit.byId("serialInput"); |
| 208 |
if (serial1) { |
| 209 |
bind1 = serial1.get("binding"); |
| 210 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 211 |
doh.is("360324", bind1.data,"bind1.data should be set"); |
| 212 |
doh.is("360324", bind1.value,"bind1.value should be set"); |
| 213 |
} |
| 214 |
} |
| 215 |
//test addrLabel |
| 216 |
addr1 = dijit.byId("addrLabel"); |
| 217 |
if (addr1) { |
| 218 |
bind1 = addr1.get("binding"); |
| 219 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 220 |
doh.is("ShipTo", bind1.data,"bind1.data should be set"); |
| 221 |
doh.is("ShipTo", bind1.value,"bind1.value should be set"); |
| 222 |
} |
| 223 |
} |
| 224 |
//test streetInput |
| 225 |
var addr1s = dijit.byId("streetInput"); |
| 226 |
if (addr1s) { |
| 227 |
bind1s = addr1s.get("binding"); |
| 228 |
if (bind1s && bind1s.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 229 |
doh.is("456 Mountain Rd", bind1s.value,"bind1s.value should be set"); |
| 230 |
bind1s.commit(); |
| 231 |
doh.is("456 Mountain Rd", bind1s.data,"bind1s.value should be set after commit"); |
| 232 |
} |
| 233 |
} |
| 234 |
//test streetInput |
| 235 |
var addr1c = dijit.byId("cityInput"); |
| 236 |
if (addr1c) { |
| 237 |
bind1c = addr1c.get("binding"); |
| 238 |
if (bind1c && bind1c.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 239 |
doh.is("Katonah", bind1c.value,"bind1c.value should be set"); |
| 240 |
doh.is("Katonah", bind1c.data,"bind1c.data should be set"); |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
}]); |
| 245 |
|
| 246 |
doh.run(); |
| 247 |
|
| 248 |
}); |
| 249 |
</script> |
| 250 |
</head> |
| 251 |
|
| 252 |
|
| 253 |
<body class="claro"> |
| 254 |
<div id="wrapper"> |
| 255 |
<div id="header"> |
| 256 |
<div id="navigation"> |
| 257 |
</div> |
| 258 |
<div id="headerInsert"> |
| 259 |
<h1>Order Shipping Details</h1> |
| 260 |
<h2>Data Binding Example - Hierarchical data.</h2> |
| 261 |
</div> |
| 262 |
</div> |
| 263 |
<div id="main"> |
| 264 |
<div id="leftNav"> |
| 265 |
</div> |
| 266 |
<div id="mainContent"> |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
<div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'model'"> |
| 274 |
<div class="row"> |
| 275 |
<label class="cell" for="serialInput">Order #:</label> |
| 276 |
<input class="cell" id="serialInput" data-dojo-type="dijit.form.TextBox" |
| 277 |
data-dojo-props="ref: 'Serial'"/> |
| 278 |
</div> |
| 279 |
<div class="row"> |
| 280 |
<label class="cell" for="lastnameInput">Last name:</label> |
| 281 |
<input class="cell" id="lastnameInput" data-dojo-type="dijit.form.TextBox" |
| 282 |
data-dojo-props="ref: 'Last'"/> |
| 283 |
</div> |
| 284 |
<div class="row"> |
| 285 |
<label class="cell" for="emailInput">Email:</label> |
| 286 |
<input class="cell" id="emailInput" data-dojo-type="dijit.form.TextBox" |
| 287 |
data-dojo-props="ref: 'Email'"/> |
| 288 |
</div> |
| 289 |
</div> |
| 290 |
<br/> |
| 291 |
Choose: |
| 292 |
<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){setRef('addrGroup', 'model.ShipTo');}">Ship To</button> |
| 293 |
<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){setRef('addrGroup', 'model.BillTo');}">Bill To</button> |
| 294 |
<br/> |
| 295 |
<div class="row"> |
| 296 |
<label class="cell" for="addrLabel">Selected Address:</label> |
| 297 |
<input class="cell" data-dojo-type="dijit.form.TextBox" id="addrLabel" |
| 298 |
data-dojo-props="ref: 'selectedAddr'"/> |
| 299 |
</div> |
| 300 |
<br/> |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
<div id="addrGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'model.ShipTo'"> |
| 310 |
<div class="row"> |
| 311 |
<label class="cell" for="typeInput">Type:</label> |
| 312 |
<input class="cell" id="typeInput" data-dojo-type="dijit.form.TextBox" |
| 313 |
data-dojo-props="ref: 'Type'"/> |
| 314 |
</div> |
| 315 |
<div id="postalGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'Address'"> |
| 316 |
<div class="row"> |
| 317 |
<label class="cell" for="streetInput">Street:</label> |
| 318 |
<input class="cell" id="streetInput" data-dojo-type="dijit.form.TextBox" |
| 319 |
data-dojo-props="ref: 'Street'"/> |
| 320 |
</div> |
| 321 |
<div class="row"> |
| 322 |
<label class="cell" for="cityInput">City:</label> |
| 323 |
<input class="cell" id="cityInput" data-dojo-type="dijit.form.TextBox" |
| 324 |
data-dojo-props="ref: 'City'"/> |
| 325 |
</div> |
| 326 |
<div class="row"> |
| 327 |
<label class="cell" for="stateInput">State:</label> |
| 328 |
<input class="cell" id="stateInput" data-dojo-type="dijit.form.TextBox" |
| 329 |
data-dojo-props="ref: 'State'"/> |
| 330 |
</div> |
| 331 |
<div class="row"> |
| 332 |
<label class="cell" for="zipInput">Zipcode:</label> |
| 333 |
<input class="cell" id="zipInput" data-dojo-type="dijit.form.TextBox" |
| 334 |
data-dojo-props="ref: 'Zip'"/> |
| 335 |
</div> |
| 336 |
</div> |
| 337 |
<div id="telGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'Telephone'"> |
| 338 |
<div class="row"> |
| 339 |
<label class="cell" for="areacodeInput">Area code:</label> |
| 340 |
<input class="cell" id="areacodeInput" data-dojo-type="dijit.form.TextBox" |
| 341 |
data-dojo-props="ref: 'AreaCode'"/> |
| 342 |
</div> |
| 343 |
<div id="llGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'Landline'"> |
| 344 |
<div class="row"> |
| 345 |
<label class="cell" for="numberInput">Landline Number:</label> |
| 346 |
<input class="cell" id="numberInput" data-dojo-type="dijit.form.TextBox" |
| 347 |
data-dojo-props="ref: 'Number'"/> |
| 348 |
</div> |
| 349 |
<div class="row"> |
| 350 |
<label class="cell" for="extInput">Extension:</label> |
| 351 |
<input class="cell" id="extInput" data-dojo-type="dijit.form.TextBox" |
| 352 |
data-dojo-props="ref: 'Extension'"/> |
| 353 |
</div> |
| 354 |
</div> |
| 355 |
<div class="row" id="cellGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'Cell'"> |
| 356 |
<label class="cell" for="cellInput">Cell Number:</label> |
| 357 |
<input class="cell" id="cellInput" data-dojo-type="dijit.form.TextBox" |
| 358 |
data-dojo-props="ref: 'Number'"/> |
| 359 |
</div> |
| 360 |
</div> |
| 361 |
<br/> |
| 362 |
Model: |
| 363 |
<button id="reset" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){model.reset();}">Reset</button> |
| 364 |
</div></div></div> |
| 365 |
<script type="text/javascript"> |
| 366 |
function setRef(id, addrRef) { |
| 367 |
var widget = dijit.byId(id); |
| 368 |
widget.set("ref", addrRef); |
| 369 |
if(addrRef == "model.ShipTo") |
| 370 |
selectedAddr.set("value", "ShipTo"); |
| 371 |
else |
| 372 |
selectedAddr.set("value", "BillTo"); |
| 373 |
} |
| 374 |
</script> |
| 375 |
</body> |
| 376 |
|
| 377 |
</html> |