| 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 |
|
| 7 |
<style> |
| 8 |
@import "../../../../../dojo/resources/dojo.css"; |
| 9 |
@import "../../../../../dijit/tests/css/dijitTests.css"; |
| 10 |
@import "../css/app-format.css"; |
| 11 |
</style> |
| 12 |
|
| 13 |
|
| 14 |
<link id="themeStyles" rel="stylesheet" href="../../../../../dijit/themes/claro/claro.css"/> |
| 15 |
|
| 16 |
|
| 17 |
<script src="../../../../../dojo/dojo.js" type="text/javascript" |
| 18 |
djConfig="isDebug: true"> |
| 19 |
</script> |
| 20 |
<script type="text/javascript" src="../helpers.js"></script> |
| 21 |
|
| 22 |
<script type="text/javascript"> |
| 23 |
dojo.require("dojox.mvc"); |
| 24 |
dojo.require("dojox.mvc.Output"); |
| 25 |
dojo.require("dijit.form.TextBox"); |
| 26 |
dojo.require("dijit.form.NumberTextBox"); |
| 27 |
dojo.require("dijit.form.ValidationTextBox"); |
| 28 |
dojo.require("dijit.form.Button"); |
| 29 |
dojo.require("dojo.parser"); |
| 30 |
|
| 31 |
// The dojox.mvc.StatefulModel class creates a data model instance |
| 32 |
// where each leaf within the data model is decorated with dojo.Stateful |
| 33 |
// properties that widgets can bind to and watch for their changes. |
| 34 |
var model = dojox.mvc.newStatefulModel({ data : |
| 35 |
{ "First" : "John", |
| 36 |
"Last" : "Doe", |
| 37 |
"Email" : "[email protected]", |
| 38 |
"Num" : 3 |
| 39 |
} |
| 40 |
}); |
| 41 |
|
| 42 |
function testFirstRelevance(newValue) { |
| 43 |
//newValue = model.First.value; |
| 44 |
if ( newValue !== "0" ) return true; |
| 45 |
else return false; |
| 46 |
} |
| 47 |
|
| 48 |
function testFirstReadOnly(newValue) { |
| 49 |
if ( newValue !== "2" && newValue !== "3" ) return false; |
| 50 |
else return true; |
| 51 |
} |
| 52 |
|
| 53 |
function testNumValid(newValue) { |
| 54 |
if ( newValue !== 1 && newValue !== "1" && newValue !== "3") return true; |
| 55 |
else return false; |
| 56 |
} |
| 57 |
|
| 58 |
function testRequired(newValue) { |
| 59 |
if ( newValue !== 4 && newValue !== "4") return false; |
| 60 |
else return true; |
| 61 |
} |
| 62 |
|
| 63 |
function testLastRelevance(newValue) { |
| 64 |
//newValue = model.First.value; |
| 65 |
if ( newValue !== "0" ) return true; |
| 66 |
else return false; |
| 67 |
} |
| 68 |
|
| 69 |
function testLastValid(newValue) { |
| 70 |
if ( newValue !== "1" ) return true; |
| 71 |
else return false; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
function init(){ |
| 76 |
// bindSelfProperties tests |
| 77 |
//"readOnly" |
| 78 |
} |
| 79 |
|
| 80 |
</script> |
| 81 |
|
| 82 |
<script type="text/javascript"> |
| 83 |
dojo.require('doh.runner'); |
| 84 |
dojo.require("dijit.dijit"); // optimize: load dijit layer |
| 85 |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
| 86 |
|
| 87 |
dojo.addOnLoad(function() { |
| 88 |
|
| 89 |
doh.register("parse", function() { |
| 90 |
dojo.parser.parse(); |
| 91 |
}); |
| 92 |
|
| 93 |
// Setup Bindings |
| 94 |
dojox.mvc.bind(model.First, "value", model.First, "readOnly", testFirstReadOnly, true); |
| 95 |
dojox.mvc.bind(model.First, "value", model.First, "relevant", testFirstRelevance, true); |
| 96 |
dojox.mvc.bind(model.First, "value", model.First, "valid", testNumValid, true); |
| 97 |
dojox.mvc.bind(model.Num, "value", model.Num, "valid", testNumValid, true); |
| 98 |
|
| 99 |
// bind tests bind Last value to Email relevant and valid |
| 100 |
dojox.mvc.bind(model.Last, "value", model.Email, "relevant", testFirstRelevance, true); |
| 101 |
dojox.mvc.bind(model.Last, "value", model.Email, "valid", testNumValid, true); |
| 102 |
dojox.mvc.bind(model.Last, "value", model.Email, "readOnly", testFirstReadOnly, true); |
| 103 |
dojox.mvc.bind(model.Last, "value", model.Email, "required", testRequired, true); |
| 104 |
dojox.mvc.bind(model.Last, "value", model.Email, "value"); |
| 105 |
|
| 106 |
// should be able to verify all of the inputs |
| 107 |
doh.register("check initial values and bindings", [{ |
| 108 |
name : "initial", |
| 109 |
runTest : function() { |
| 110 |
// First test an empty array |
| 111 |
var m = new dojox.mvc.newStatefulModel({ data: {arr: []} }); |
| 112 |
doh.is([],m.arr.toPlainObject(),"m.arr.toPlainObject()should be []."); |
| 113 |
doh.is("object",typeof m.arr.toPlainObject(),"m.arr.toPlainObject() should be an object (array)"); |
| 114 |
doh.is(0,m.arr.toPlainObject().length,"m.arr.toPlainObject().length should be 0 for []."); |
| 115 |
|
| 116 |
var m2 = new dojox.mvc.newStatefulModel({ data: {str: ""} }); |
| 117 |
doh.is("",m2.str.toPlainObject(),"m2.str.toPlainObject()should be []."); |
| 118 |
doh.is("string",typeof m2.str.toPlainObject(),"m2.str.toPlainObject() should be a string."); |
| 119 |
doh.is(0,m2.str.toPlainObject().length,"m2.str.toPlainObject().length should be 0 for an empty string."); |
| 120 |
|
| 121 |
|
| 122 |
var first1, bind1, addr1; |
| 123 |
//test serialInput |
| 124 |
first1 = dijit.byId("firstnameInput"); |
| 125 |
if (first1) { |
| 126 |
bind1 = first1.get("binding"); |
| 127 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 128 |
doh.f(bind1.readOnly,"bind1.readOnly should be false"); |
| 129 |
//doh.t(bind1.relevant,"bind1.relevant should be true"); |
| 130 |
doh.f(bind1.required,"bind1.required should be false"); |
| 131 |
//doh.t(bind1.valid,"bind1.valid should be true"); |
| 132 |
} |
| 133 |
} |
| 134 |
//test emailInput |
| 135 |
addr1 = dijit.byId("emailInput"); |
| 136 |
if (addr1) { |
| 137 |
bind1 = addr1.get("binding"); |
| 138 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 139 |
doh.f(bind1.readOnly,"bind1.readOnly should be false"); |
| 140 |
//doh.t(bind1.relevant,"bind1.relevant should be true"); |
| 141 |
doh.f(bind1.required,"bind1.required should be false"); |
| 142 |
//doh.t(bind1.valid,"bind1.valid should be true"); |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
}]); |
| 147 |
|
| 148 |
doh.register("check FirstUpdate", [{ |
| 149 |
name : "testFirstUpdate", |
| 150 |
runTest : function() { |
| 151 |
//setRef("addrGroup", masterRecord.BillTo); |
| 152 |
var first1, bind1, addr1; |
| 153 |
//test first relevant false |
| 154 |
first1 = dijit.byId("firstnameInput"); |
| 155 |
first1.set("value","0"); |
| 156 |
if (first1) { |
| 157 |
bind1 = first1.get("binding"); |
| 158 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 159 |
doh.f(bind1.readOnly,"bind1.readOnly should be false"); |
| 160 |
doh.f(bind1.relevant,"bind1.relevant should be false"); |
| 161 |
doh.f(bind1.required,"bind1.required should be false"); |
| 162 |
doh.t(bind1.valid,"bind1.valid should be true"); |
| 163 |
} |
| 164 |
} |
| 165 |
//test first valid false |
| 166 |
first1.set("value","1"); |
| 167 |
if (first1) { |
| 168 |
bind1 = first1.get("binding"); |
| 169 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 170 |
doh.f(bind1.readOnly,"bind1.readOnly should be false for value = 1"); |
| 171 |
doh.t(bind1.relevant,"bind1.relevant should be true for value = 1"); |
| 172 |
doh.f(bind1.required,"bind1.required should be false for value = 1"); |
| 173 |
doh.f(bind1.valid,"bind1.valid should be false for value = 1"); |
| 174 |
} |
| 175 |
} |
| 176 |
//test first readOnly true |
| 177 |
first1.set("value","2"); |
| 178 |
if (first1) { |
| 179 |
bind1 = first1.get("binding"); |
| 180 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 181 |
doh.t(bind1.relevant,"bind1.relevant should be true for value = 2"); |
| 182 |
doh.f(bind1.required,"bind1.required should be false for value = 2"); |
| 183 |
doh.t(bind1.valid,"bind1.valid should be true for value = 2"); |
| 184 |
doh.t(bind1.readOnly,"bind1.readOnly should be true for value = 2"); |
| 185 |
} |
| 186 |
} |
| 187 |
//test first readOnly true and valid false |
| 188 |
first1.set("value","3"); |
| 189 |
if (first1) { |
| 190 |
bind1 = first1.get("binding"); |
| 191 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 192 |
doh.t(bind1.readOnly,"bind1.readOnly should be true for value = 3"); |
| 193 |
doh.t(bind1.relevant,"bind1.relevant should be true for value = 3"); |
| 194 |
doh.f(bind1.required,"bind1.required should be false for value = 3"); |
| 195 |
doh.f(bind1.valid,"bind1.valid should be false for value = 3"); |
| 196 |
} |
| 197 |
} |
| 198 |
//test first back to original |
| 199 |
first1.set("value","5"); |
| 200 |
if (first1) { |
| 201 |
bind1 = first1.get("binding"); |
| 202 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 203 |
doh.f(bind1.readOnly,"bind1.readOnly should be false for value = 5"); |
| 204 |
doh.t(bind1.relevant,"bind1.relevant should be true for value = 5"); |
| 205 |
doh.f(bind1.required,"bind1.required should be false for value = 5"); |
| 206 |
doh.t(bind1.valid,"bind1.valid should be ture for value = 5"); |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
}]); |
| 211 |
|
| 212 |
|
| 213 |
doh.register("check NumUpdate", [{ |
| 214 |
name : "testNumUpdate", |
| 215 |
runTest : function() { |
| 216 |
var first1, bind1, addr1; |
| 217 |
//test first valid false |
| 218 |
num1 = dijit.byId("numInput"); |
| 219 |
num1.set("value",1); |
| 220 |
if (num1) { |
| 221 |
bind1 = num1.get("binding"); |
| 222 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 223 |
doh.f(bind1.readOnly,"bind1.readOnly should be false for value = 1"); |
| 224 |
//doh.t(bind1.relevant,"bind1.relevant should be true for value = 1"); |
| 225 |
doh.f(bind1.required,"bind1.required should be false for value = 1"); |
| 226 |
doh.f(bind1.valid,"bind1.valid should be false for value = 1"); |
| 227 |
} |
| 228 |
} |
| 229 |
num1.set("value",5); |
| 230 |
if (num1) { |
| 231 |
bind1 = num1.get("binding"); |
| 232 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 233 |
doh.f(bind1.readOnly,"bind1.readOnly should be false for value = 5"); |
| 234 |
//doh.t(bind1.relevant,"bind1.relevant should be true for value = 5"); |
| 235 |
doh.f(bind1.required,"bind1.required should be false for value = 5"); |
| 236 |
doh.t(bind1.valid,"bind1.valid should be true for value = 5"); |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
}]); |
| 241 |
|
| 242 |
doh.register("check emailUpdate", [{ |
| 243 |
name : "testNumUpdate", |
| 244 |
runTest : function() { |
| 245 |
var last1, email1, bind1, addr1; |
| 246 |
//test first valid false |
| 247 |
last1 = dijit.byId("lastnameInput"); |
| 248 |
email1 = dijit.byId("emailInput"); |
| 249 |
|
| 250 |
//test last = 5 for original |
| 251 |
last1.set("value","5"); |
| 252 |
if (email1) { |
| 253 |
bind1 = email1.get("binding"); |
| 254 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 255 |
doh.f(bind1.readOnly,"bind1.readOnly should be false for email value = 5"); |
| 256 |
//doh.t(bind1.relevant,"bind1.relevant should be true for email value = 5"); |
| 257 |
doh.f(bind1.required,"bind1.required should be false for email value = 5"); |
| 258 |
doh.t(bind1.valid,"bind1.valid should be true for email value = 5"); |
| 259 |
} |
| 260 |
} |
| 261 |
//test last = 0 for email relevant = false |
| 262 |
last1.set("value","0"); |
| 263 |
if (email1) { |
| 264 |
bind1 = email1.get("binding"); |
| 265 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 266 |
doh.f(bind1.readOnly,"bind1.readOnly should be false for email value = 0"); |
| 267 |
doh.f(bind1.relevant,"bind1.relevant should be false for email value = 0"); |
| 268 |
doh.f(bind1.required,"bind1.required should be false for email value = 0"); |
| 269 |
doh.t(bind1.valid,"bind1.valid should be true for email value = 0"); |
| 270 |
} |
| 271 |
} |
| 272 |
//test last = 1 for email valid = false |
| 273 |
last1.set("value","1"); |
| 274 |
if (email1) { |
| 275 |
bind1 = email1.get("binding"); |
| 276 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 277 |
doh.f(bind1.readOnly,"bind1.readOnly should be false for email value = 1"); |
| 278 |
//doh.t(bind1.relevant,"bind1.relevant should be true for email value = 1"); |
| 279 |
doh.f(bind1.required,"bind1.required should be false for email value = 1"); |
| 280 |
doh.f(bind1.valid,"bind1.valid should be false for email value = 1"); |
| 281 |
} |
| 282 |
} |
| 283 |
//test last = 2 for email readOnly true |
| 284 |
last1.set("value","2"); |
| 285 |
if (email1) { |
| 286 |
bind1 = email1.get("binding"); |
| 287 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 288 |
doh.t(bind1.readOnly,"bind1.readOnly should be true for email value = 2"); |
| 289 |
//doh.t(bind1.relevant,"bind1.relevant should be true for email value = 2"); |
| 290 |
doh.f(bind1.required,"bind1.required should be false for email value = 2"); |
| 291 |
doh.t(bind1.valid,"bind1.valid should be true for email value = 2"); |
| 292 |
} |
| 293 |
} |
| 294 |
//test last = 3 for email readOnly true and email valid = false |
| 295 |
last1.set("value","3"); |
| 296 |
if (email1) { |
| 297 |
bind1 = email1.get("binding"); |
| 298 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 299 |
doh.t(bind1.readOnly,"bind1.readOnly should be true for email value = 3"); |
| 300 |
//doh.t(bind1.relevant,"bind1.relevant should be true for email value = 3"); |
| 301 |
doh.f(bind1.required,"bind1.required should be false for email value = 3"); |
| 302 |
doh.f(bind1.valid,"bind1.valid should be false for email value = 3"); |
| 303 |
} |
| 304 |
} |
| 305 |
//test last = 4 for email required true |
| 306 |
last1.set("value","4"); |
| 307 |
if (email1) { |
| 308 |
bind1 = email1.get("binding"); |
| 309 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 310 |
doh.f(bind1.readOnly,"bind1.readOnly should be false for email value = 4"); |
| 311 |
//doh.t(bind1.relevant,"bind1.relevant should be true for email value = 4"); |
| 312 |
doh.t(bind1.required,"bind1.required should be true for email value = 4"); |
| 313 |
doh.t(bind1.valid,"bind1.valid should be true for email value = 4"); |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
//test last = 5 for back to original |
| 318 |
last1.set("value","5"); |
| 319 |
if (email1) { |
| 320 |
bind1 = email1.get("binding"); |
| 321 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 322 |
doh.f(bind1.readOnly,"bind1.readOnly should be false for email value = 5"); |
| 323 |
//doh.t(bind1.relevant,"bind1.relevant should be true for email value = 5"); |
| 324 |
doh.f(bind1.required,"bind1.required should be false for email value = 5"); |
| 325 |
doh.t(bind1.valid,"bind1.valid should be true for email value = 5"); |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
} |
| 330 |
}]); |
| 331 |
|
| 332 |
doh.run(); |
| 333 |
|
| 334 |
}); |
| 335 |
</script> |
| 336 |
</head> |
| 337 |
|
| 338 |
<body class="claro"> |
| 339 |
<div id="wrapper"> |
| 340 |
<div id="header"> |
| 341 |
<div id="navigation"> |
| 342 |
</div> |
| 343 |
<div id="headerInsert"> |
| 344 |
<h1>Binding Tests</h1> |
| 345 |
</div> |
| 346 |
</div> |
| 347 |
<div id="main"> |
| 348 |
<div id="leftNav"> |
| 349 |
</div> |
| 350 |
<div id="mainContent"> |
| 351 |
<h2>Bind Self Tests</h2> |
| 352 |
<div class="row"> |
| 353 |
<label style="display:inline-block; width:100%; text-align:left;">First: Enter 0 to test for Relevant false (use Reset to re-enable)</label> |
| 354 |
<label style="display:inline-block; width:100%; text-align:left;">First: Enter 1 to test for Valid false.</label> |
| 355 |
<label style="display:inline-block; width:100%; text-align:left;">First: Enter 2 to test for ReadOnly false (use Reset to re-enable)</label> |
| 356 |
<label style="display:inline-block; width:100%; text-align:left;">First: Enter 3 to test for ReadOnly false and Valid false (use Reset to re-enable)</label> |
| 357 |
</div> |
| 358 |
<div class="row"> |
| 359 |
<label class="cell" for="firstnameInput">First:</label> |
| 360 |
<input class="cell" id="firstnameInput" data-dojo-type="dijit.form.ValidationTextBox" |
| 361 |
data-dojo-props="ref: model.First"/> |
| 362 |
|
| 363 |
<span id="tout" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.First"> |
| 364 |
(first name is: ${this.value}) |
| 365 |
</span> |
| 366 |
|
| 367 |
</div> |
| 368 |
<div class="row"> |
| 369 |
<label class="cell" for="firstnameInput"></label> |
| 370 |
<span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.First"> |
| 371 |
Relevant is: ${this.ref.relevant}, Valid is: ${this.ref.valid}, ReadOnly is: ${this.ref.readOnly}) |
| 372 |
</span> |
| 373 |
</div> |
| 374 |
<div class="row"> |
| 375 |
<label style="display:inline-block; width:100%; text-align:left;">Num: Enter 1 for Valid false</label> |
| 376 |
</div> |
| 377 |
<div class="row"> |
| 378 |
<label class="cell" for="numInput">Num:</label> |
| 379 |
<input class="cell" id="numInput" data-dojo-type="dijit.form.NumberTextBox" |
| 380 |
data-dojo-props="ref: model.Num"/> |
| 381 |
<span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Num"> |
| 382 |
(num is: ${this.value}) |
| 383 |
</span> |
| 384 |
</div> |
| 385 |
<h2>Bind Tests</h2> |
| 386 |
<div class="row"> |
| 387 |
<label style="display:inline-block; width:100%; text-align:left;">Last: Enter 0 to test for Relevant false for Email.</label> |
| 388 |
<label style="display:inline-block; width:100%; text-align:left;">Last: Enter 1 to test for Valid false for Email.</label> |
| 389 |
<label style="display:inline-block; width:100%; text-align:left;">Last: Enter 2 to test for ReadOnly true for Email.</label> |
| 390 |
<label style="display:inline-block; width:100%; text-align:left;">Last: Enter 3 to test for ReadOnly true and Valid false for Email.</label> |
| 391 |
<label style="display:inline-block; width:100%; text-align:left;">Last: Enter 4 to test for Required true for Email.</label> |
| 392 |
</div> |
| 393 |
|
| 394 |
<div class="row"> |
| 395 |
<label class="cell" for="lastnameInput">Last:</label> |
| 396 |
<input class="cell" id="lastnameInput" data-dojo-type="dijit.form.TextBox" |
| 397 |
data-dojo-props="ref: model.Last"/> |
| 398 |
<span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Last"> |
| 399 |
(last name is: ${this.value}) |
| 400 |
</span> |
| 401 |
</div> |
| 402 |
<div class="row"> |
| 403 |
<label class="cell" for="emailInput">Email:</label> |
| 404 |
<input class="cell" id="emailInput" data-dojo-type="dijit.form.ValidationTextBox" |
| 405 |
data-dojo-props="ref: model.Email"/> |
| 406 |
<span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Email"> |
| 407 |
(email is: ${this.value}) |
| 408 |
</span> |
| 409 |
</div> |
| 410 |
<div class="row"> |
| 411 |
<label class="cell" for="emailInput"></label> |
| 412 |
<span id="emailOut" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Email"> |
| 413 |
Relevant is: ${dijit.byId("emailInput").ref.relevant}, Valid is: ${this.ref.valid}, ReadOnly is: ${this.ref.readOnly}, Required is: ${this.ref.required}) |
| 414 |
</span> |
| 415 |
</div> |
| 416 |
|
| 417 |
<br/>Model: |
| 418 |
<button id="reset" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){doReset()}">Reset</button> |
| 419 |
</div> |
| 420 |
</div></div> |
| 421 |
<script type="text/javascript"> |
| 422 |
function doReset() { |
| 423 |
model.reset(); |
| 424 |
} |
| 425 |
</script> |
| 426 |
|
| 427 |
</body> |
| 428 |
|
| 429 |
</html> |