| 1 |
<!DOCTYPE html> |
| 2 |
<html style="width:100%;height:100%;overflow:hidden;"> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 |
<title>Dojo Repeat Selection Test</title> |
| 6 |
|
| 7 |
<style type="text/css"> |
| 8 |
@import "../../../../dijit/themes/dijit.css"; |
| 9 |
@import "../../../../dijit/themes/claro/document.css"; |
| 10 |
@import "../../../../dijit/tests/css/dijitTests.css"; |
| 11 |
</style> |
| 12 |
|
| 13 |
|
| 14 |
<link id="themeStyles" rel="stylesheet" href="../../../../dijit/themes/claro/claro.css"/> |
| 15 |
|
| 16 |
<style> |
| 17 |
.bordercontainer-nopadding .dijitContentPane, .bordercontainer-nopadding .dijitSplitContainer-dijitContentPane, .bordercontainer-nopadding .dijitBorderContainer-dijitContentPane { |
| 18 |
padding: 0; |
| 19 |
} |
| 20 |
|
| 21 |
.bordercontainer-nopadding .dijitMenuBar { |
| 22 |
border-width: 0 0 1px 0; |
| 23 |
} |
| 24 |
|
| 25 |
.view .dijitMenu { |
| 26 |
border-width: 0; |
| 27 |
} |
| 28 |
|
| 29 |
.view .dijitMenuItemHover { |
| 30 |
background-color: inherit; |
| 31 |
background-image: none; |
| 32 |
} |
| 33 |
|
| 34 |
.view .dijitMenuItemSelected { |
| 35 |
background-color: #abd6ff; |
| 36 |
background-image: url("images/standardGradient.png"); |
| 37 |
background-repeat: repeat-x; |
| 38 |
background-image: -moz-linear-gradient(rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0) 100%); |
| 39 |
background-image: -webkit-linear-gradient(rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0) 100%); |
| 40 |
background-image: -o-linear-gradient(rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0) 100%); |
| 41 |
background-image: -ms-linear-gradient(rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0) 100%); |
| 42 |
_background-image: none; |
| 43 |
} |
| 44 |
|
| 45 |
.view td.dijitMenuItemLabel { |
| 46 |
width: 100%; |
| 47 |
padding: 6px; |
| 48 |
} |
| 49 |
|
| 50 |
.view td.dijitMenuItemIconCell { |
| 51 |
padding: 6px; |
| 52 |
} |
| 53 |
|
| 54 |
.dijitBorderContainerNoGutter > .form { |
| 55 |
padding: 6px; |
| 56 |
} |
| 57 |
|
| 58 |
.row { |
| 59 |
width: 100%; |
| 60 |
display: inline-block; |
| 61 |
padding: 6px; |
| 62 |
-box-sizing: border-box; |
| 63 |
-moz-box-sizing: border-box; |
| 64 |
-webkit-box-sizing: border-box; |
| 65 |
} |
| 66 |
|
| 67 |
.cell { |
| 68 |
width: 100%; |
| 69 |
display:inline-block; |
| 70 |
-box-sizing: border-box; |
| 71 |
-moz-box-sizing: border-box; |
| 72 |
-webkit-box-sizing: border-box; |
| 73 |
} |
| 74 |
|
| 75 |
.complete { |
| 76 |
text-decoration: line-through; |
| 77 |
} |
| 78 |
</style> |
| 79 |
|
| 80 |
<script type="text/javascript"> |
| 81 |
dojoConfig = {async: 1, isDebug: 1, mvc: {debugBindings: 1}}; |
| 82 |
</script> |
| 83 |
<script type="text/javascript" src="../../../../dojo/dojo.js"></script> |
| 84 |
|
| 85 |
<script type="text/javascript"> |
| 86 |
var ViewMenuBarData, DetailMenuBarData, initialRows; |
| 87 |
var selectionStatusConverter = { |
| 88 |
format: function(value){ |
| 89 |
return this.target.uniqueId == (value || {}).uniqueId; |
| 90 |
}, |
| 91 |
parse: function(value){ |
| 92 |
if(!value){ throw new Error(); } // Stop copying the new value for unchecked case |
| 93 |
for(var a = this.source.inModel, i = 0; i < a.length; i++){ |
| 94 |
if(a[i].uniqueId == this.target.uniqueId){ |
| 95 |
return a[i]; |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
}, priorityConverter = { |
| 100 |
format: function(value){ |
| 101 |
return "dijitIcon dijitMenuItemIconCell " + (value <= 1 ? "dijitIconError" : ""); |
| 102 |
} |
| 103 |
}, completeConverter = { |
| 104 |
format: function(value){ |
| 105 |
return "dijitMenuItemLabel" + (value ? " complete" : ""); |
| 106 |
} |
| 107 |
},subjectConverter = { |
| 108 |
format: function(value){ |
| 109 |
return value || "(No subject)"; |
| 110 |
} |
| 111 |
}; |
| 112 |
|
| 113 |
require([ |
| 114 |
"doh/runner", |
| 115 |
"dojox", |
| 116 |
"dojo/_base/declare", |
| 117 |
"dojo/_base/lang", |
| 118 |
"dojo/dom", |
| 119 |
"dojo/dom-class", |
| 120 |
"dojo/query", |
| 121 |
"dojo/parser", |
| 122 |
"dojo/Stateful", |
| 123 |
"dijit/registry", |
| 124 |
"dijit/Menu", |
| 125 |
"dojox/mvc/at", |
| 126 |
"dojox/mvc/getStateful", |
| 127 |
"dijit/form/CheckBox", |
| 128 |
"dijit/form/DateTextBox", |
| 129 |
"dijit/form/Select", |
| 130 |
"dijit/form/TextBox", |
| 131 |
"dijit/layout/BorderContainer", |
| 132 |
"dijit/layout/ContentPane", |
| 133 |
"dijit/Editor", |
| 134 |
"dijit/MenuBar", |
| 135 |
"dijit/MenuBarItem", |
| 136 |
"dijit/MenuItem", |
| 137 |
"dojox/mvc/_atBindingExtension", |
| 138 |
"dojox/mvc/EditModelRefController", |
| 139 |
"dojox/mvc/ListController", |
| 140 |
"dojox/mvc/StatefulArray", |
| 141 |
"dojox/mvc/Group", |
| 142 |
"dojox/mvc/Repeat" |
| 143 |
], function(doh, dojox, declare, lang, ddom, domClass, query, parser, Stateful, registry, Menu, at, getStateful){ |
| 144 |
|
| 145 |
var uniqueIdSeq = 3; |
| 146 |
|
| 147 |
initialRows = getStateful([ |
| 148 |
{ |
| 149 |
uniqueId: 0, |
| 150 |
Completed: false, |
| 151 |
Subject: "Pick up my kids", |
| 152 |
Due: new Date((new Date()).getTime() + 48 * 3600000), |
| 153 |
Priority: 1, |
| 154 |
Description: "At the kindergarden" |
| 155 |
}, |
| 156 |
{ |
| 157 |
uniqueId: 1, |
| 158 |
Completed: true, |
| 159 |
Subject: "Take dojox.mvc learning course", |
| 160 |
Due: new Date((new Date()).getTime() + 72 * 3600000), |
| 161 |
Priority: 2, |
| 162 |
Description: "Need to find course material at http://dojotoolkit.org/" |
| 163 |
}, |
| 164 |
{ |
| 165 |
uniqueId: 2, |
| 166 |
Completed: false, |
| 167 |
Subject: "Wash my car", |
| 168 |
Due: new Date((new Date()).getTime() + 120 * 3600000), |
| 169 |
Priority: 3, |
| 170 |
Description: "Need to buy a cleaner before that" |
| 171 |
} |
| 172 |
]); |
| 173 |
|
| 174 |
ViewMenuBarData = getStateful([ |
| 175 |
{ |
| 176 |
label: "New", |
| 177 |
onClick: function(){ |
| 178 |
var ctl = registry.byId("listCtl"); |
| 179 |
var payload = getStateful({ |
| 180 |
uniqueId: uniqueIdSeq++, |
| 181 |
Completed: false, |
| 182 |
Subject: "", |
| 183 |
Due: new Date(""), |
| 184 |
Priority: 2, |
| 185 |
Description: "" |
| 186 |
}); |
| 187 |
ctl.inModel.unshift(payload); |
| 188 |
ctl.set("cursor", payload); |
| 189 |
} |
| 190 |
}, |
| 191 |
{ |
| 192 |
label: "Delete", |
| 193 |
onClick: function(){ |
| 194 |
var ctl = registry.byId("listCtl"); |
| 195 |
var idx = ctl.get("cursorIndex"); |
| 196 |
if(idx >= 0){ |
| 197 |
ctl.inModel.splice(idx, 1); |
| 198 |
} |
| 199 |
if(idx < ctl.inModel.get("length")){ |
| 200 |
ctl.set("cursorIndex", idx); |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
]); |
| 205 |
|
| 206 |
DetailMenuBarData = getStateful([ |
| 207 |
{ |
| 208 |
label: "Save", |
| 209 |
onClick: function(){ |
| 210 |
registry.byId("listCtl").commit(); |
| 211 |
} |
| 212 |
}, |
| 213 |
{ |
| 214 |
label: "Cancel", |
| 215 |
onClick: function(){ |
| 216 |
var ctl = registry.byId("listCtl"); |
| 217 |
ctl.reset(); |
| 218 |
} |
| 219 |
} |
| 220 |
]); |
| 221 |
|
| 222 |
domClass.add(ddom.byId("loading"), "dijitDisplayNone"); |
| 223 |
domClass.remove(ddom.byId("main"), "dijitDisplayNone"); |
| 224 |
parser.parse(); |
| 225 |
|
| 226 |
doh.register("Test values and bindings", [ |
| 227 |
{ |
| 228 |
name: "Initial", |
| 229 |
runTest: function(){ |
| 230 |
doh.t(ddom.byId("viewcheckbox0").checked, "First view row should be checked"); |
| 231 |
doh.t(domClass.contains(ddom.byId("viewiconimg0"), "dijitIconError"), "First view row should contain explanation mark"); |
| 232 |
doh.t(domClass.contains(ddom.byId("viewtext1"), "complete"), "Second view row should be marked as complete"); |
| 233 |
doh.is("Wash my car", ddom.byId("viewtext2").innerHTML, "Third view row should exist"); |
| 234 |
doh.f(ddom.byId("viewtext3"), "Fourth row shouldn't exist"); |
| 235 |
doh.is("Pick up my kids", ddom.byId("subject").value, "The subject field should be of the first row"); |
| 236 |
} |
| 237 |
}, |
| 238 |
{ |
| 239 |
name: "Navigate", |
| 240 |
runTest: function(){ |
| 241 |
ddom.byId("viewcheckbox1").click(); |
| 242 |
doh.is("Take dojox.mvc learning course", ddom.byId("subject").value, "The subject field should be of the second row"); |
| 243 |
ddom.byId("viewcheckbox2").click(); |
| 244 |
doh.is("3", ((query("#priority input[data-dojo-attach-point='valueNode']") || [])[0] || {}).value, "The priority field should be of the third row"); |
| 245 |
} |
| 246 |
}, |
| 247 |
{ |
| 248 |
name: "EditToCancel", |
| 249 |
runTest: function(){ |
| 250 |
ddom.byId("viewcheckbox0").click(); |
| 251 |
var completed = ddom.byId("completed"); |
| 252 |
completed.click(); |
| 253 |
var subject = registry.byId("subject"); |
| 254 |
subject.set("displayedValue", "Pick up my wife"); |
| 255 |
doh.f(domClass.contains(ddom.byId("viewtext0"), "complete"), "First view row shouldn't be marked as complete yet"); |
| 256 |
doh.is("Pick up my kids", ddom.byId("viewtext0").innerHTML, "First view row's subject shouldn't be updated yet"); |
| 257 |
registry.byId("menubaritem1_1").onClick(); |
| 258 |
doh.is("Pick up my kids", subject.get("displayedValue"), "Subject should be set back to the original one"); |
| 259 |
doh.f(completed.checked, "Completed checkbox should be set back to unchecked"); |
| 260 |
} |
| 261 |
}, |
| 262 |
{ |
| 263 |
name: "EditToSave", |
| 264 |
runTest: function(){ |
| 265 |
ddom.byId("viewcheckbox0").click(); |
| 266 |
var completed = ddom.byId("completed"); |
| 267 |
completed.click(); |
| 268 |
var subject = registry.byId("subject"); |
| 269 |
subject.set("displayedValue", "Pick up my wife"); |
| 270 |
doh.f(domClass.contains(ddom.byId("viewtext0"), "complete"), "First view row shouldn't be marked as complete yet"); |
| 271 |
doh.is("Pick up my kids", ddom.byId("viewtext0").innerHTML, "First view row's subject shouldn't be updated yet"); |
| 272 |
registry.byId("menubaritem1_0").onClick(); |
| 273 |
doh.t(domClass.contains(ddom.byId("viewtext0"), "complete"), "First view row should be marked as complete"); |
| 274 |
doh.is("Pick up my wife", ddom.byId("viewtext0").innerHTML, "First view row's subject should be updated"); |
| 275 |
} |
| 276 |
}, |
| 277 |
{ |
| 278 |
name: "Delete", |
| 279 |
runTest: function(){ |
| 280 |
registry.byId("menubaritem0_1").onClick(); |
| 281 |
doh.is("Take dojox.mvc learning course", ddom.byId("subject").value, "The subject field should be of the (formerly) second row"); |
| 282 |
doh.f(ddom.byId("viewtext2"), "Third row shouldn't exist"); |
| 283 |
} |
| 284 |
}, |
| 285 |
{ |
| 286 |
name: "Create", |
| 287 |
runTest: function(){ |
| 288 |
registry.byId("menubaritem0_0").onClick(); |
| 289 |
var viewtext = ddom.byId("viewtext0"); |
| 290 |
doh.is("(No subject)", viewtext.innerHTML, "First row's subject shouldn't be set yet"); |
| 291 |
var subject = registry.byId("subject"); |
| 292 |
subject.set("displayedValue", "Complete dojox.mvc test case"); |
| 293 |
doh.is("(No subject)", viewtext.innerHTML, "First row's subject shouldn't be updated yet"); |
| 294 |
registry.byId("menubaritem1_0").onClick(); |
| 295 |
doh.is("Complete dojox.mvc test case", viewtext.innerHTML, "Subject should be updated"); |
| 296 |
} |
| 297 |
} |
| 298 |
]); |
| 299 |
|
| 300 |
doh.run(); |
| 301 |
}); |
| 302 |
</script> |
| 303 |
</head> |
| 304 |
<body class="claro" style="width:100%;height:100%;margin:0;padding:0;overflow:hidden;"> |
| 305 |
<script type="dojo/require">at: "dojox/mvc/at"</script> |
| 306 |
<table id="loading" style="width:100%;height:100%;" border="0" cellpadding="0" cellspacing="0"> |
| 307 |
<tbody> |
| 308 |
<tr> |
| 309 |
<td align="center">Loading...</td> |
| 310 |
</tr> |
| 311 |
</tbody> |
| 312 |
</table> |
| 313 |
<div id="main" class="dijitDisplayNone" style="width:100%;height:100%;"> |
| 314 |
<span id="listCtl" data-dojo-type="dojox.mvc.ListController" data-dojo-mixins="dojox.mvc.EditModelRefController" |
| 315 |
data-dojo-props="_refInModelProp: 'inModel', _refSourceModelProp: 'cursor', _refModelProp: 'model', inModel: initialRows, cursorIndex: 0, holdModelUntilCommit: true"></span> |
| 316 |
<div class="bordercontainer-nopadding" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="persist: false, gutters: true, style: 'height: 100%; width: 100%;'"> |
| 317 |
<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'left', style: 'background-color: white; width: 48ex', splitter: true"> |
| 318 |
<div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="persist: false, gutters: false"> |
| 319 |
<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'top'"> |
| 320 |
<div data-dojo-type="dojox.mvc.Repeat" data-dojo-mixins="dijit.MenuBar" data-dojo-props="children: ViewMenuBarData"> |
| 321 |
<div id="menubaritem0_${index}" data-dojo-type="dijit.MenuBarItem" data-dojo-props="'*': at('rel:${index}', '*')"></div> |
| 322 |
</div> |
| 323 |
</div> |
| 324 |
<div class="view" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'center'"> |
| 325 |
<table border="0" cellspacing="0" cellpadding="0"> |
| 326 |
<tbody data-dojo-type="dojox.mvc.Repeat" data-dojo-props="children: at('widget:listCtl', 'inModel')"> |
| 327 |
<tr data-dojo-type="dijit._WidgetBase" data-dojo-props="target: at('rel:', '${index}')"> |
| 328 |
<td class="dijitMenuItemIconCell"> |
| 329 |
<input id="viewcheckbox${index}" data-dojo-type="dijit.form.CheckBox" |
| 330 |
data-dojo-props="uniqueId: at('rel:', 'uniqueId'), |
| 331 |
checked: at('widget:listCtl', 'cursor').transform(selectionStatusConverter)"> |
| 332 |
</td> |
| 333 |
<td class="dijitMenuItemIconCell"> |
| 334 |
<img id="viewiconimg${index}" src="../../../../dojo/resources/blank.gif" data-dojo-type="dijit._WidgetBase" |
| 335 |
data-dojo-props="_setDomClassAttr: {node: 'domNode', type: 'class'}, domClass: at('rel:', 'Priority').direction(at.from).transform(priorityConverter)"> |
| 336 |
</td> |
| 337 |
<td id="viewtext${index}" data-dojo-type="dijit._WidgetBase" |
| 338 |
data-dojo-props="Subject: at('rel:', 'Subject').direction(at.from).transform(subjectConverter), |
| 339 |
_setDomClassAttr: {node: 'domNode', type: 'class'}, domClass: at('rel:', 'Completed').direction(at.from).transform(completeConverter), |
| 340 |
_setSubjectAttr: {node: 'domNode', type: 'innerText'}"> |
| 341 |
</td> |
| 342 |
</tr> |
| 343 |
</tbody> |
| 344 |
</table> |
| 345 |
</div> |
| 346 |
</div> |
| 347 |
</div> |
| 348 |
<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'center', style: 'background-color: white;'"> |
| 349 |
<div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="persist: false, gutters: false"> |
| 350 |
<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'top'"> |
| 351 |
<div data-dojo-type="dojox.mvc.Repeat" data-dojo-mixins="dijit.MenuBar" data-dojo-props="children: DetailMenuBarData"> |
| 352 |
<div id="menubaritem1_${index}" data-dojo-type="dijit.MenuBarItem" data-dojo-props="'*': at('rel:${index}', '*')"></div> |
| 353 |
</div> |
| 354 |
</div> |
| 355 |
<div class="form" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region: 'center', target: at('widget:listCtl', 'model')"> |
| 356 |
<div class="row"> |
| 357 |
<span class="cell"> |
| 358 |
<label for="completed">Completed:</label> |
| 359 |
<input id="completed" data-dojo-type="dijit.form.CheckBox" data-dojo-props="checked: at('rel:', 'Completed')"> |
| 360 |
</span> |
| 361 |
</div> |
| 362 |
<div class="row"> |
| 363 |
<label class="cell" for="subject">Subject:</label> |
| 364 |
<input class="cell" id="subject" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Subject')"> |
| 365 |
</div> |
| 366 |
<div class="row"> |
| 367 |
<label class="cell" for="priority">Priority:</label> |
| 368 |
<span class="cell"> |
| 369 |
<select id="priority" data-dojo-type="dijit.form.Select" data-dojo-props="value: at('rel:', 'Priority')"> |
| 370 |
<option value="1">1</option> |
| 371 |
<option value="2">2</option> |
| 372 |
<option value="3">3</option> |
| 373 |
</select> |
| 374 |
</span> |
| 375 |
</div> |
| 376 |
<div class="row"> |
| 377 |
<label class="cell" for="due">Due:</label> |
| 378 |
<span class="cell"> |
| 379 |
<input id="due" data-dojo-type="dijit.form.DateTextBox" |
| 380 |
data-dojo-props="required: false, constraints: {datePattern: 'MMMM dd yyyy'}, value: at('rel:', 'Due')"> |
| 381 |
</span> |
| 382 |
</div> |
| 383 |
<div class="row"> |
| 384 |
<span class="cell">Description:</span> |
| 385 |
<div class="cell" data-dojo-type="dijit.Editor" |
| 386 |
data-dojo-props="plugins: ['bold', 'italic', 'underline'], height: '200', value: at('rel:', 'Description')"></div> |
| 387 |
</div> |
| 388 |
</div> |
| 389 |
</div> |
| 390 |
</div> |
| 391 |
</div> |
| 392 |
</div> |
| 393 |
</body> |
| 394 |
</html> |