| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/> |
| 5 |
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/> |
| 6 |
<meta name="apple-mobile-web-app-capable" content="yes"/> |
| 7 |
<title>MVC Repeat with Selectable RoundRectList - Single Select</title> |
| 8 |
|
| 9 |
<script type="text/javascript" src="../../../../dojox/mobile/deviceTheme.js" data-dojo-config="mblThemeFiles: ['base']"></script> |
| 10 |
|
| 11 |
|
| 12 |
<script type="text/javascript" src="../../../../dojo/dojo.js" |
| 13 |
data-dojo-config="isDebug: true, async: true, parseOnLoad: false, mvc: {debugBindings: true}"></script> |
| 14 |
|
| 15 |
<script type="text/javascript"> |
| 16 |
require([ |
| 17 |
"dojo/_base/lang", |
| 18 |
"dijit/registry", |
| 19 |
"dojox/mobile/parser", |
| 20 |
"dojo/store/Memory", |
| 21 |
"dojo/ready", |
| 22 |
"dojo/when", |
| 23 |
"dojox/mvc/getStateful", |
| 24 |
"dojox/mvc/at", |
| 25 |
"dojox/mvc/Group", |
| 26 |
"dojox/mvc/Repeat", |
| 27 |
"dojox/mvc/Output", |
| 28 |
"dojox/mobile", |
| 29 |
"dojox/mobile/Button", |
| 30 |
"dojox/mobile/TextBox", |
| 31 |
"dojox/mobile/CheckBox", |
| 32 |
"dojox/mobile/deviceTheme" |
| 33 |
], function(lang, registry, parser, MemoryStore, ready, when, getStateful, at){ |
| 34 |
window.at = at; |
| 35 |
|
| 36 |
var search_results_init1 = |
| 37 |
[{ |
| 38 |
"Query" : "Engineers1", |
| 39 |
"Results" : [ |
| 40 |
{ |
| 41 |
"First" : "Anne1", |
| 42 |
"Last" : "Ackerman1", |
| 43 |
"Checked" : true |
| 44 |
}, |
| 45 |
{ |
| 46 |
"First" : "Ben1", |
| 47 |
"Last" : "Beckham1", |
| 48 |
"Checked" : false |
| 49 |
}, |
| 50 |
{ |
| 51 |
"First" : "Chad1", |
| 52 |
"Last" : "Chapman1", |
| 53 |
"Checked" : false |
| 54 |
} |
| 55 |
] |
| 56 |
}]; |
| 57 |
|
| 58 |
var search_results_init2 = |
| 59 |
[{ |
| 60 |
"Query" : "Engineers1", |
| 61 |
"Results" : [ |
| 62 |
{ |
| 63 |
"First" : "Anne2", |
| 64 |
"Last" : "Ackerman2", |
| 65 |
"Checked" : false |
| 66 |
}, |
| 67 |
{ |
| 68 |
"First" : "Ben2", |
| 69 |
"Last" : "Beckham2", |
| 70 |
"Checked" : true |
| 71 |
}, |
| 72 |
{ |
| 73 |
"First" : "Chad2", |
| 74 |
"Last" : "Chapman2", |
| 75 |
"Checked" : false |
| 76 |
} |
| 77 |
] |
| 78 |
}]; |
| 79 |
var memStore1 = new MemoryStore({data : search_results_init1}); |
| 80 |
//model1 = mvc.newStatefulModel({ store : memStore1 })[0]; |
| 81 |
|
| 82 |
when(memStore1.query(), function(data){ |
| 83 |
model1 = getStateful(data)[0]; |
| 84 |
model1Orig = lang.clone(model1); |
| 85 |
//if(model1 && model2 && model3){ runTests(); } |
| 86 |
}); |
| 87 |
|
| 88 |
|
| 89 |
var memStore2 = new MemoryStore({data : search_results_init2}); |
| 90 |
//model2 = mvc.newStatefulModel({ store : memStore2 })[0]; |
| 91 |
when(memStore2.query(), function(data){ |
| 92 |
model2 = getStateful(data)[0]; |
| 93 |
model2Orig = lang.clone(model2); |
| 94 |
//if(model1 && model2 && model3){ runTests(); } |
| 95 |
}); |
| 96 |
|
| 97 |
// when "dojo/ready" is ready call parser.parse (if not doing parseOnLoad) |
| 98 |
ready(function(){ |
| 99 |
parser.parse(); |
| 100 |
}); |
| 101 |
|
| 102 |
|
| 103 |
// called to reset the model for each of the repeats |
| 104 |
swapToModel1 = function() { |
| 105 |
registry.byId('repeatId1').set('children',model1.Results); |
| 106 |
registry.byId('repeatId2').set('children',model1.Results); |
| 107 |
registry.byId('repeatid2arem').set('children',model1.Results); |
| 108 |
}; |
| 109 |
|
| 110 |
swapToModel2 = function() { |
| 111 |
registry.byId('repeatId1').set('children',model2.Results); |
| 112 |
registry.byId('repeatId2').set('children',model2.Results); |
| 113 |
registry.byId('repeatid2arem').set('children',model2.Results); |
| 114 |
}; |
| 115 |
|
| 116 |
resetAll = function() { |
| 117 |
model1 = lang.clone(model1Orig); |
| 118 |
model2 = lang.clone(model2Orig); |
| 119 |
registry.byId('repeatId1').set('children',model1.Results); |
| 120 |
registry.byId('repeatId2').set('children',model1.Results); |
| 121 |
registry.byId('repeatid2arem').set('children',model1.Results); |
| 122 |
}; |
| 123 |
|
| 124 |
|
| 125 |
}); |
| 126 |
|
| 127 |
</script> |
| 128 |
</head> |
| 129 |
<body style="visibility:hidden;"> |
| 130 |
<div id="wrapper"> |
| 131 |
<div id="header"> |
| 132 |
<div id="navigation"></div> |
| 133 |
<div id="headerInsert"> |
| 134 |
<h2>MVC Repeat with Selectable RoundRectDataList - Single Select</h2> |
| 135 |
</div> |
| 136 |
</div> |
| 137 |
<div id="main"> |
| 138 |
<div id="leftNav"></div> |
| 139 |
<div id="mainContent"> |
| 140 |
<h4>Here is one using dojox.mvc.Repeat as a mixin with no Group and dojo.parser instead of dojox.mobile.parser it is all good using mixin.</h4> |
| 141 |
<ul data-dojo-type="dojox.mobile.RoundRectList" id="repeatId1" select="single" |
| 142 |
data-dojo-mixins="dojox.mvc.Repeat" data-dojo-props="exprchar:'#', children: model1.Results"> |
| 143 |
<li id="configure_itemmix1#{this.index}" class="mblVariableHeight" data-dojo-type="dojox.mobile.ListItem" |
| 144 |
data-dojo-props="label: at('rel:#{this.index}', 'First'), |
| 145 |
checked: at('rel:#{this.index}', 'Checked')"> |
| 146 |
</li> |
| 147 |
</ul> |
| 148 |
|
| 149 |
<h4>Here is one using MVC using Repeat no Group, with removeRepeatNode set true it is all good if Repeat sets select and onCheckStateChanged.</h4> |
| 150 |
<ul data-dojo-type="dojox.mobile.RoundRectList" id="repeatparentidrem" select="single"> |
| 151 |
<div data-dojo-type="dojox.mvc.Repeat" id="repeatid2arem" |
| 152 |
data-dojo-props="exprchar:'#', children:model1.Results, removeRepeatNode:true"> |
| 153 |
<li id="configure_itemrem#{this.index}" class="mblVariableHeight" data-dojo-type="dojox.mobile.ListItem" |
| 154 |
data-dojo-props="label: at('rel:#{this.index}','First'), |
| 155 |
checked: at('rel:#{this.index}','Checked')"> |
| 156 |
</li> |
| 157 |
</div> |
| 158 |
</ul> |
| 159 |
<h4>You can update the label or checked from here to update the model.</h4> |
| 160 |
<div id="repeatparentid2"> |
| 161 |
<div id="repeatId2" data-dojo-type="dojox.mvc.Repeat" data-dojo-props="children:model1.Results"> |
| 162 |
<input class="cell" data-dojo-type="dojox.mobile.TextBox" id="nameInput2${this.index}" |
| 163 |
data-dojo-props="value: at('rel:${this.index}', 'First')"/> |
| 164 |
<label data-dojo-type="dojox.mvc.Output" for="CBInput${this.index}" |
| 165 |
data-dojo-props="value: at('rel:${this.index}','First')"/></label> |
| 166 |
<input class="cell" type="checkbox" data-dojo-type="dojox.mobile.CheckBox" id="CBInput${this.index}" |
| 167 |
data-dojo-props="checked: at('rel:${this.index}','Checked')"/> |
| 168 |
</div> |
| 169 |
</div> |
| 170 |
|
| 171 |
<br/>Model: |
| 172 |
<button type="button" data-dojo-type="dojox.mobile.Button" data-dojo-props="onClick: function(){swapToModel2();}">Swap Model2</button> |
| 173 |
<button type="button" data-dojo-type="dojox.mobile.Button" data-dojo-props="onClick: function(){swapToModel1();}">Swap Model1</button> |
| 174 |
<button id="reset" type="button" data-dojo-type="dojox.mobile.Button" data-dojo-props="onClick: function(){resetAll();}">Reset all</button> |
| 175 |
</div> |
| 176 |
</div> |
| 177 |
</div> |
| 178 |
</body> |
| 179 |
</html> |