| 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="parseOnLoad: false, 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.Group"); |
| 25 |
dojo.require("dojox.mvc.Repeat"); |
| 26 |
dojo.require("dijit.form.TextBox"); |
| 27 |
dojo.require("dijit.form.Button"); |
| 28 |
dojo.require("dojo.data.ItemFileWriteStore"); |
| 29 |
dojo.require("dojo.store.DataStore"); |
| 30 |
dojo.require("dojo.parser"); |
| 31 |
|
| 32 |
var results, selectedIndex = 0; |
| 33 |
// declared here for convenience |
| 34 |
templateString = '<div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: \'${this.index}\'">' + |
| 35 |
'<label class="cell">Name:</label>' + |
| 36 |
'<input class="cell" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: \'First\'"></input>' + |
| 37 |
'<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){setDetailsContext(\'${this.index}\');}">Details</button>' + |
| 38 |
'</div>'; |
| 39 |
|
| 40 |
function setup() { |
| 41 |
var writeStore = new dojo.data.ItemFileWriteStore({url: dojo.moduleUrl("dojox.mvc.tests._data", "mvcRepeatData.json")}); |
| 42 |
var modelPromise = dojox.mvc.newStatefulModel({store: new dojo.store.DataStore({store: writeStore})}); |
| 43 |
modelPromise.then(function(model){ |
| 44 |
results = model; |
| 45 |
dojo.parser.parse(); |
| 46 |
|
| 47 |
// Can test with either the dojox.mvc.Repeat or my.Repeat |
| 48 |
var repeat = new my.Repeat({ |
| 49 |
//var repeat = new dojox.mvc.Repeat({ |
| 50 |
// templateString: templateString, // not needed with my.Repeat since it is set there. |
| 51 |
ref: model |
| 52 |
}).placeAt('repeat2'); |
| 53 |
repeat.startup(); |
| 54 |
startTests(); |
| 55 |
}); |
| 56 |
}; |
| 57 |
|
| 58 |
dojo.declare('my.Repeat', [dojox.mvc.Repeat], { |
| 59 |
templateString : templateString |
| 60 |
}); |
| 61 |
dojo.addOnLoad(setup); |
| 62 |
</script> |
| 63 |
|
| 64 |
<script type="text/javascript"> |
| 65 |
dojo.require('doh.runner'); |
| 66 |
dojo.require("dijit.dijit"); // optimize: load dijit layer |
| 67 |
dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
| 68 |
function startTests(){ |
| 69 |
// should be able to verify all of the inputs |
| 70 |
doh.register("Check initial values and bindings", [ |
| 71 |
{ |
| 72 |
name: "initial", |
| 73 |
runTest: function(){ |
| 74 |
var name1, bind1, firstInput; |
| 75 |
name1 = dijit.byId("dijit_form_TextBox_10"); |
| 76 |
if (name1) { |
| 77 |
console.log("testing dijit_form_TextBox_10"); |
| 78 |
bind1 = name1.get("binding"); |
| 79 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 80 |
doh.is("Anne",bind1.data,"bind1.data should be set"); |
| 81 |
doh.is("Anne",bind1.value,"bind1.value should be set"); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
name1 = dijit.byId("dijit_form_TextBox_0"); |
| 86 |
if (name1) { |
| 87 |
console.log("testing dijit_form_TextBox_0"); |
| 88 |
bind1 = name1.get("binding"); |
| 89 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 90 |
doh.is("Anne",bind1.data,"bind1.data should be set"); |
| 91 |
doh.is("Anne",bind1.value,"bind1.value should be set"); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
firstInput = dijit.byId("firstInput"); |
| 96 |
if (firstInput) { |
| 97 |
bind1 = firstInput.get("binding"); |
| 98 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 99 |
doh.is("Anne",bind1.data,"bind1.data should be set"); |
| 100 |
doh.is("Anne",bind1.value,"bind1.value should be set"); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
]); |
| 106 |
|
| 107 |
doh.register("select Ben", [ |
| 108 |
{ |
| 109 |
name: "testBen", |
| 110 |
runTest: function(){ |
| 111 |
setDetailsContext(1); |
| 112 |
var name1, bind1, firstInput; |
| 113 |
name1 = dijit.byId("dijit_form_TextBox_11"); |
| 114 |
if (name1) { |
| 115 |
bind1 = name1.get("binding"); |
| 116 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 117 |
doh.is("Ben",bind1.data,"bind1.data is wrong"); |
| 118 |
doh.is("Ben",bind1.value,"bind1.value is wrong"); |
| 119 |
} |
| 120 |
} |
| 121 |
name1 = dijit.byId("dijit_form_TextBox_1"); |
| 122 |
if (name1) { |
| 123 |
bind1 = name1.get("binding"); |
| 124 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 125 |
doh.is("Ben",bind1.data,"bind1.data is wrong"); |
| 126 |
doh.is("Ben",bind1.value,"bind1.value is wrong"); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
firstInput = dijit.byId("firstInput"); |
| 131 |
if (firstInput) { |
| 132 |
bind1 = firstInput.get("binding"); |
| 133 |
if (bind1 && bind1.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 134 |
console.debug("firstInput.value="+firstInput.value); |
| 135 |
doh.is("Ben",bind1.data,"firstInput bind1.data is wrong"); |
| 136 |
doh.is("Ben",bind1.value,"firstInput bind1.value is wrong"); |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
]); |
| 142 |
|
| 143 |
|
| 144 |
doh.register("select John and update John to Johnny test valueOf and toString", [ |
| 145 |
{ |
| 146 |
name: "testJohn", |
| 147 |
runTest: function(){ |
| 148 |
setDetailsContext(9); //select John |
| 149 |
var name9, bind9, firstInput; |
| 150 |
name9 = dijit.byId("dijit_form_TextBox_19"); |
| 151 |
if (name9) { |
| 152 |
bind9 = name9.get("binding"); |
| 153 |
if (bind9 && bind9.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 154 |
doh.is("John",bind9.data,"bind9.data is wrong"); |
| 155 |
doh.is("John",bind9.value,"bind9.value is wrong"); |
| 156 |
doh.is("John",bind9.valueOf(),"bind9.valueOf() is wrong"); |
| 157 |
doh.is("John",bind9.toString(),"bind9.toString() is wrong"); |
| 158 |
} |
| 159 |
} |
| 160 |
name9 = dijit.byId("dijit_form_TextBox_9"); |
| 161 |
if (name9) { |
| 162 |
bind9 = name9.get("binding"); |
| 163 |
if (bind9 && bind9.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 164 |
doh.is("John",bind9.data,"bind9.data is wrong"); |
| 165 |
doh.is("John",bind9.value,"bind9.value is wrong"); |
| 166 |
doh.is("John",bind9.valueOf(),"bind9.valueOf() is wrong"); |
| 167 |
doh.is("John",bind9.toString(),"bind9.toString() is wrong"); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
firstInput = dijit.byId("firstInput"); |
| 172 |
dojo.byId("firstInput").focus(); |
| 173 |
firstInput.set('value',"Johnny"); |
| 174 |
dojo.byId("lastInput").focus(); |
| 175 |
|
| 176 |
if (firstInput) { |
| 177 |
bind9 = firstInput.get("binding"); |
| 178 |
if (bind9 && bind9.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 179 |
doh.is("Johnny",bind9.value,"firstInput bind9.value is wrong"); |
| 180 |
doh.is("Johnny",firstInput.value,"firstInput firstInput.value is wrong"); |
| 181 |
doh.is("Johnny",bind9.valueOf(),"firstInput bind9.valueOf() is wrong"); |
| 182 |
doh.is("Johnny",bind9.toString(),"firstInput bind9.toString() is wrong"); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
// Test the value of and toString |
| 187 |
valueOfTest = new dojox.mvc.StatefulModel({ data: 42 }); |
| 188 |
doh.is(42,valueOfTest.data,"valueOfTest.data is wrong"); |
| 189 |
doh.is(42,valueOfTest.value,"valueOfTest.value is wrong"); |
| 190 |
doh.is(42,+valueOfTest,"valueOfTest.valueOf() is wrong"); |
| 191 |
doh.is("42",'' + valueOfTest,"valueOfTest.toString() is wrong"); |
| 192 |
|
| 193 |
toStringTest = new dojox.mvc.StatefulModel({ data: 'abc' }); |
| 194 |
doh.is('abc',toStringTest.data,"toStringTest.data is wrong"); |
| 195 |
doh.is('abc',toStringTest.value,"toStringTest.value is wrong"); |
| 196 |
doh.is(NaN,+toStringTest,"toStringTest.valueOf() is wrong"); |
| 197 |
doh.is('abc','' + toStringTest,"toStringTest.toString() is wrong") |
| 198 |
|
| 199 |
|
| 200 |
} |
| 201 |
} |
| 202 |
]); |
| 203 |
|
| 204 |
doh.register("test Commit and Reset", [ |
| 205 |
{ |
| 206 |
name: "testC&R", |
| 207 |
runTest: function(){ |
| 208 |
setDetailsContext(8); //select Irene |
| 209 |
var name8, bind8, firstInput, lastInput; |
| 210 |
name8 = dijit.byId("dijit_form_TextBox_18"); |
| 211 |
if (name8) { |
| 212 |
bind8 = name8.get("binding"); |
| 213 |
if (bind8 && bind8.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 214 |
doh.is("Irene",bind8.data,"bind8.data is wrong"); |
| 215 |
doh.is("Irene",bind8.value,"bind8.value is wrong"); |
| 216 |
} |
| 217 |
} |
| 218 |
name8 = dijit.byId("dijit_form_TextBox_8"); |
| 219 |
if (name8) { |
| 220 |
bind8 = name8.get("binding"); |
| 221 |
if (bind8 && bind8.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 222 |
doh.is("Irene",bind8.data,"bind8.data is wrong"); |
| 223 |
doh.is("Irene",bind8.value,"bind8.value is wrong"); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
//update Irene to IreneThisUpdateShouldBeSaved and commit |
| 228 |
firstInput = dijit.byId("firstInput"); |
| 229 |
dojo.byId("firstInput").focus(); |
| 230 |
firstInput.set("value","IreneThisUpdateShouldBeSaved"); |
| 231 |
dojo.byId("lastInput").focus(); |
| 232 |
results.commit(); |
| 233 |
|
| 234 |
lastInput = dijit.byId("lastInput"); |
| 235 |
dojo.byId("lastInput").focus(); |
| 236 |
lastInput.set("value", "IraThisUpdateShouldBeReset"); |
| 237 |
dojo.byId("firstInput").focus(); |
| 238 |
results.reset(); |
| 239 |
|
| 240 |
if (firstInput) { |
| 241 |
bind8 = firstInput.get("binding"); |
| 242 |
if (bind8 && bind8.isInstanceOf(dojox.mvc.StatefulModel)) { |
| 243 |
doh.is("IreneThisUpdateShouldBeSaved",bind8.value,"firstInput bind8.value is wrong"); |
| 244 |
doh.is("IreneThisUpdateShouldBeSaved",firstInput.value,"firstInput firstInput.value is wrong"); |
| 245 |
doh.is("Ira",lastInput.value,"lastInput lastInput.value is wrong"); |
| 246 |
} |
| 247 |
} |
| 248 |
} |
| 249 |
} |
| 250 |
]); |
| 251 |
|
| 252 |
doh.run(); |
| 253 |
}; |
| 254 |
</script> |
| 255 |
</head> |
| 256 |
<body class="claro"> |
| 257 |
<h1 class="testTitle">doh_mvc_programmatic-repeat-store.html automated tests (non-robot)</h1> |
| 258 |
<div id="wrapper"> |
| 259 |
<div id="header"> |
| 260 |
<div id="navigation"> |
| 261 |
</div> |
| 262 |
<div id="headerInsert"> |
| 263 |
<h2>Master Detail Example - With repeat container, using a store, with save, commit and reset.</h2> |
| 264 |
</div> |
| 265 |
</div> |
| 266 |
<div id="main"> |
| 267 |
<div id="leftNav"> |
| 268 |
</div> |
| 269 |
<div id="mainContent"> |
| 270 |
<div id="searchBanner">Search Results for term: </div> |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
<table><tbody><tr> |
| 280 |
<td> |
| 281 |
<div> |
| 282 |
<div>Programatic Repeat using my.Repeat and its templateString: </div> |
| 283 |
<div id="repeat2"></div> |
| 284 |
</div> |
| 285 |
</td> |
| 286 |
<td> |
| 287 |
<div> |
| 288 |
<div>Declarative Repeat using my.Repeat does not pass templateString: </div> |
| 289 |
<div id="repeatId2" data-dojo-type="my.Repeat" data-dojo-props="ref: 'results'"></div> |
| 290 |
</div> |
| 291 |
</td> |
| 292 |
</tr></tbody></table> |
| 293 |
|
| 294 |
<div class="spacer"></div> |
| 295 |
|
| 296 |
<div data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'results'"> |
| 297 |
<div id="detailsBanner">Details for selected index:</div> |
| 298 |
|
| 299 |
<div id="detailsGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: '0'"> |
| 300 |
<div class="row"> |
| 301 |
<label class="cell" for="firstInput">First Name:</label> |
| 302 |
<input class="cell" id="firstInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'First'"></input> |
| 303 |
</div> |
| 304 |
<div class="row"> |
| 305 |
<label class="cell" for="lastInput">Last Name:</label> |
| 306 |
<input class="cell" id="lastInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Last'"></input> |
| 307 |
</div> |
| 308 |
<div class="row"> |
| 309 |
<label class="cell" for="locationInput">Location:</label> |
| 310 |
<input class="cell" id="locationInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Location'"></input> |
| 311 |
</div> |
| 312 |
<div class="row"> |
| 313 |
<label class="cell" for="officeInput">Office:</label> |
| 314 |
<input class="cell" id="officeInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Office'"></input> |
| 315 |
</div> |
| 316 |
<div class="row"> |
| 317 |
<label class="cell" for="emailInput">Email:</label> |
| 318 |
<input class="cell" id="emailInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Email'"></input> |
| 319 |
</div> |
| 320 |
<div class="row"> |
| 321 |
<label class="cell" for="telInput">Telephone:</label> |
| 322 |
<input class="cell" id="telInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Tel'"></input> |
| 323 |
</div> |
| 324 |
<div class="row"> |
| 325 |
<label class="cell" for="faxInput">Fax:</label> |
| 326 |
<input class="cell" id="faxInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Fax'"></input> |
| 327 |
</div> |
| 328 |
<div class="row"> |
| 329 |
<div class="spacer"></div> |
| 330 |
<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){console.log(results[selectedIndex].toPlainObject());results[selectedIndex].commit();}">Save Item</button> |
| 331 |
<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){console.log(results.toPlainObject());results.commit();;}">Commit All</button> |
| 332 |
<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){results.reset();}">Reset to last saved</button> |
| 333 |
</div> |
| 334 |
</div> |
| 335 |
</div> |
| 336 |
</div> |
| 337 |
</div> |
| 338 |
</div> |
| 339 |
<script type="text/javascript"> |
| 340 |
// called to change the selected item |
| 341 |
function setDetailsContext(index) { |
| 342 |
selectedIndex = index; |
| 343 |
var widget = dijit.byId("detailsGroup"); |
| 344 |
widget.set("ref", index); |
| 345 |
} |
| 346 |
</script> |
| 347 |
</body> |
| 348 |
</html> |