| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 |
<title>13899 mvc Stateful Dates</title> |
| 6 |
|
| 7 |
<style> |
| 8 |
@import "../../../../dijit/themes/claro/document.css"; |
| 9 |
@import "../../../util/doh/robot/robot.css"; |
| 10 |
@import "../../../../dijit/tests/css/dijitTests.css"; |
| 11 |
.cell { display:inline-block; } |
| 12 |
</style> |
| 13 |
|
| 14 |
|
| 15 |
<link id="themeStyles" rel="stylesheet" href="../../../../dijit/themes/claro/claro.css"/> |
| 16 |
|
| 17 |
|
| 18 |
<script type="text/javascript" src="../../../../dojo/dojo.js" |
| 19 |
data-dojo-config="isDebug: true, parseOnLoad: false"></script> |
| 20 |
|
| 21 |
|
| 22 |
<script type="text/javascript" src="../../../../dijit/tests/_testCommon.js"></script> |
| 23 |
|
| 24 |
<script type="text/javascript"> |
| 25 |
var model; |
| 26 |
|
| 27 |
require([ |
| 28 |
'dojo/parser', |
| 29 |
'dojox/mvc', |
| 30 |
'dojo/store/Memory', |
| 31 |
'dijit/form/DateTextBox', |
| 32 |
'dijit/CalendarLite', |
| 33 |
'dojox/mvc/StatefulModel', |
| 34 |
'dojox/mvc/Repeat', |
| 35 |
'dojox/mvc/Group', |
| 36 |
'dojox/mvc/at', |
| 37 |
'dijit/registry', |
| 38 |
'dijit/form/Button', |
| 39 |
'dojox/mvc/Output', |
| 40 |
'dijit/form/TextBox', |
| 41 |
'dojo/date/stamp', |
| 42 |
'dojo/dom', |
| 43 |
'dojo/dom-construct', |
| 44 |
'dojo/on', |
| 45 |
'dojo/domReady!' |
| 46 |
], function (parser, mvc, Memory, DateTextBox, Calendar, StatefulModel, Repeat, Group, |
| 47 |
at, registry, Button, Output, TextBox, dateStamp, dom, domconstruct) { |
| 48 |
window.at = at; |
| 49 |
|
| 50 |
// *** Test1 setup begin: *** |
| 51 |
var search_results_init1 = |
| 52 |
[{ |
| 53 |
"Query" : "Engineers1", |
| 54 |
"Results" : [ |
| 55 |
{ |
| 56 |
"First" : "Anne1", |
| 57 |
"Last" : "Ackerman1" |
| 58 |
}, |
| 59 |
{ |
| 60 |
"First" : "Ben1", |
| 61 |
"Last" : "Beckham1" |
| 62 |
}, |
| 63 |
{ |
| 64 |
"First" : "Chad1", |
| 65 |
"Last" : "Chapman1" |
| 66 |
} |
| 67 |
] |
| 68 |
}]; |
| 69 |
var search_results_init2 = |
| 70 |
[{ |
| 71 |
"Query" : "Engineers2", |
| 72 |
"Results" : [ |
| 73 |
{ |
| 74 |
"First" : "Anne2", |
| 75 |
"Last" : "Ackerman2" |
| 76 |
}, |
| 77 |
{ |
| 78 |
"First" : "Ben2", |
| 79 |
"Last" : "Beckham2" |
| 80 |
} |
| 81 |
] |
| 82 |
}]; |
| 83 |
var search_results_init3 = |
| 84 |
[{ |
| 85 |
"Query" : "Engineers3", |
| 86 |
"Results" : [ |
| 87 |
{ |
| 88 |
"First" : "Chad3", |
| 89 |
"Last" : "Chapman3" |
| 90 |
} |
| 91 |
] |
| 92 |
}]; |
| 93 |
|
| 94 |
var memStore1 = new Memory({data : search_results_init1}); |
| 95 |
model1 = mvc.newStatefulModel({ store : memStore1 })[0]; |
| 96 |
var memStore2 = new Memory({data : search_results_init2}); |
| 97 |
model2 = mvc.newStatefulModel({ store : memStore2 })[0]; |
| 98 |
var memStore3 = new Memory({data : search_results_init3}); |
| 99 |
model3 = mvc.newStatefulModel({ store : memStore3 })[0]; |
| 100 |
|
| 101 |
templateString = '<div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: \'${this.index}\'">' + |
| 102 |
'<label class="cell">Name:</label>' + |
| 103 |
'<input class="cell" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: \'First\'"></input>' + |
| 104 |
'<div class="cell" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: \'Last\'"></div>' + |
| 105 |
'</div>'; |
| 106 |
|
| 107 |
// I would like to be able to programmatically create the widgets |
| 108 |
// which would go into the repeat, but that is not possible now given the way the |
| 109 |
// repeat parses it's content when it is built |
| 110 |
|
| 111 |
// need to parse the declarative swap buttons |
| 112 |
parser.parse("swapbuttons2"); |
| 113 |
|
| 114 |
var swapb1 = new Button({ |
| 115 |
onClick: function(){swapToModel(model1);}, |
| 116 |
id: "swapbutton1", |
| 117 |
label: "Swap Model1" |
| 118 |
}, document.getElementById('swapbutton1')); |
| 119 |
swapb1.startup(); |
| 120 |
|
| 121 |
var swapb2 = new Button({ |
| 122 |
onClick: function(){swapToModel(model2);}, |
| 123 |
id: "swapbutton2", |
| 124 |
label: "Swap Model2" |
| 125 |
}, document.getElementById('swapbutton2')); |
| 126 |
swapb2.startup(); |
| 127 |
|
| 128 |
var swapb3 = new Button({ |
| 129 |
onClick: function(){swapToModel(model3);}, |
| 130 |
id: "swapbutton3", |
| 131 |
label: "Swap Model3" |
| 132 |
}, document.getElementById('swapbutton3')); |
| 133 |
swapb3.startup(); |
| 134 |
|
| 135 |
var test2_repeat = new Repeat({ |
| 136 |
ref: model1.Results |
| 137 |
}, document.getElementById('test2_repeat')); |
| 138 |
test2_repeat.startup(); |
| 139 |
|
| 140 |
var test3_repeat = new Repeat({ |
| 141 |
children: at(model1, 'Results') |
| 142 |
}, document.getElementById('test3_repeat')); |
| 143 |
test3_repeat.startup(); |
| 144 |
|
| 145 |
var test1_repeat = new Repeat({ |
| 146 |
templateString: templateString, // not needed with my.Repeat since it is set there. |
| 147 |
ref: model1.Results |
| 148 |
}, document.getElementById('test1_repeat')); |
| 149 |
test1_repeat.startup(); |
| 150 |
|
| 151 |
}); |
| 152 |
|
| 153 |
// called to reset the model for each of the repeats |
| 154 |
//function swapToModel(model) { |
| 155 |
// console.log("called with "+model); |
| 156 |
//} |
| 157 |
</script> |
| 158 |
</head> |
| 159 |
|
| 160 |
<body class="claro"> |
| 161 |
<h2>Test 1: A programmatic repeat using a Template with a textbox and an mvc output field.</h2> |
| 162 |
<div style="border-style: solid; border-width: 2px; width: 827px;"> |
| 163 |
<div id="test1_repeat"> |
| 164 |
</div> |
| 165 |
</div> |
| 166 |
|
| 167 |
<h2>Test 2: A programmatic repeat with the html inline with an mvc output field and a textbox.</h2> |
| 168 |
<div style="border-style: solid; border-width: 2px; width: 827px;"> |
| 169 |
<div id="test2_repeat"> |
| 170 |
<div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: '${this.index}'"> |
| 171 |
<label class="cell">Name:</label> |
| 172 |
<div class="cell" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: 'First'"></div> |
| 173 |
<input class="cell" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Last'"></input> |
| 174 |
</div> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
|
| 178 |
<h2>Test 3: A programmatic repeat with the html inline using mvc.at.</h2> |
| 179 |
<div style="border-style: solid; border-width: 2px; width: 827px;"> |
| 180 |
<div id="test3_repeat"> |
| 181 |
<div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at('rel:${this.index}')"> |
| 182 |
<label class="cell">Name:</label> |
| 183 |
<input class="cell" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:First', 'value')"></input> |
| 184 |
<input class="cell" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:Last', 'value')"></input> |
| 185 |
</div> |
| 186 |
</div> |
| 187 |
</div> |
| 188 |
|
| 189 |
<h2>Test 4: Programmatic Swap models, this one is done by swapping between different models, I would like to be able to update the model data without replacing the model.</h2> |
| 190 |
<div id="swapbuttons" class="row"> |
| 191 |
<div id="swapbutton1" ></div> |
| 192 |
<div id="swapbutton2" ></div> |
| 193 |
<div id="swapbutton3" ></div> |
| 194 |
</div> |
| 195 |
|
| 196 |
<h2>Test 5: Swap models, (these are declarative buttons) this one is done by swapping between different models, I would like to be able to update the model data without replacing the model.</h2> |
| 197 |
<div id="swapbuttons2" class="row"> |
| 198 |
<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){swapToModel(model1);}">Swap Model1</button> |
| 199 |
<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){swapToModel(model2);}">Swap Model2</button> |
| 200 |
<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){swapToModel(model3);}">Swap Model3</button> |
| 201 |
</div> |
| 202 |
|
| 203 |
|
| 204 |
<script type="text/javascript"> |
| 205 |
function swapToModel(model) { |
| 206 |
require([ |
| 207 |
"dijit/registry", |
| 208 |
"dojox/mvc/at" |
| 209 |
], function(registry, at){ |
| 210 |
var widget = registry.byId("test1_repeat"); |
| 211 |
widget.set("ref", model.Results); |
| 212 |
registry.byId("test2_repeat").set("ref", model.Results); |
| 213 |
registry.byId("test3_repeat").set("children", at(model, 'Results')); |
| 214 |
}); |
| 215 |
} |
| 216 |
</script> |
| 217 |
|
| 218 |
</body> |
| 219 |
</html> |