| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/> |
| 5 |
<meta name="apple-mobile-web-app-capable" content="yes" /> |
| 6 |
<title>Android Repeat Data Example</title> |
| 7 |
<link href="../../../../../dojox/mobile/themes/android/android.css" rel="stylesheet"/> |
| 8 |
<link href="../css/android-format.css" rel="stylesheet"/> |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
<script type="text/javascript" src="../../../../../dojo/dojo.js" djConfig="parseOnLoad: false, isDebug: true"></script> |
| 16 |
|
| 17 |
<script language="JavaScript" type="text/javascript"> |
| 18 |
//dojo.require("dojo.parser"); |
| 19 |
dojo.require("dojox.mobile.parser"); // dojox.mobile.parser did not work |
| 20 |
dojo.require("dojox.mobile"); |
| 21 |
dojo.require("dojox.mobile.TextBox"); |
| 22 |
dojo.require("dojox.mobile.Button"); |
| 23 |
dojo.require("dojox.mvc"); |
| 24 |
dojo.require("dojox.mvc.Group"); |
| 25 |
dojo.require("dojox.mvc.Repeat"); |
| 26 |
dojo.require("dojo.data.ItemFileWriteStore"); |
| 27 |
dojo.require("dojo.store.DataStore"); |
| 28 |
|
| 29 |
dojo.requireIf(!dojo.isWebKit, "dojox.mobile.compat"); |
| 30 |
|
| 31 |
var model, selectedIndex = 0, nextIndexToAdd, theModelPromise; |
| 32 |
|
| 33 |
function setup() { |
| 34 |
var writeStore = new dojo.data.ItemFileWriteStore({url: dojo.moduleUrl("dojox.mvc.tests._data", "mvcRepeatData.json")}); |
| 35 |
var modelPromise = dojox.mvc.newStatefulModel({store: new dojo.store.DataStore({store: writeStore}), query:{"Location" : "CA"}}); // example of using a query parm for Location |
| 36 |
modelPromise.then(function(results){ |
| 37 |
model = results; |
| 38 |
nextIndexToAdd = model.data.length; |
| 39 |
//dojo.parser.parse(); |
| 40 |
dojox.mobile.parser.parse(); |
| 41 |
}); |
| 42 |
}; |
| 43 |
|
| 44 |
dojo.ready(setup); |
| 45 |
</script> |
| 46 |
</head> |
| 47 |
<body> |
| 48 |
<h1 dojoType="dojox.mobile.Heading">Android Repeat Data Binding Example.</h1> |
| 49 |
<div >Search Results:</div> |
| 50 |
<div dojoType="dojox.mvc.Repeat" class="row" ref="model"> |
| 51 |
<div class="row" dojoType="dojox.mvc.Group" ref="'rel:${this.index}'"> |
| 52 |
<input dojoType="dojox.mobile.TextBox" |
| 53 |
id="nameInput${this.index}" ref="'rel:First'" placeHolder="First Name"/> |
| 54 |
<button id="details${this.index}" type="button" dojoType="dojox.mobile.Button" class="mblBlueButton" onclick="setDetailsContext('${this.index}')">Details</button> |
| 55 |
</div> |
| 56 |
</div> |
| 57 |
<div class="spacer"></div> |
| 58 |
<div dojoType="dojox.mvc.Group" ref="model"> |
| 59 |
<div id="detailsBanner">Details for selected index:</div> |
| 60 |
<div id="detailsGroup" dojoType="dojox.mvc.Group" ref="'rel:0'"> |
| 61 |
<div><label for="firstInput">First Name:</label></div> |
| 62 |
<div><input id="firstInput" dojoType="dojox.mobile.TextBox" ref="'rel:First'" placeHolder="First Name"/></div> |
| 63 |
<div><label for="lastInput">Last Name:</label></div> |
| 64 |
<div><input id="lastInput" dojoType="dojox.mobile.TextBox" ref="'rel:Last'" placeHolder="Last Name"/></div> |
| 65 |
<div><label for="emailInput">Email:</label></div> |
| 66 |
<div><input id="emailInput" dojoType="dojox.mobile.TextBox" ref="'rel:Email'" placeHolder="Email"/></div> |
| 67 |
<div><label for="telInput">Telephone:</label></div> |
| 68 |
<div><input id="telInput" dojoType="dojox.mobile.TextBox" ref="'rel:Tel'" placeHolder="Telephone"/></div> |
| 69 |
<div><label for="faxInput">Fax:</label></div> |
| 70 |
<div><input id="faxInput" dojoType="dojox.mobile.TextBox" ref="'rel:Fax'" placeHolder="Fax"/></div> |
| 71 |
</div> |
| 72 |
</div> |
| 73 |
<div class="spacer"></div> |
| 74 |
<button id="add" type="button" dojoType="dojox.mobile.Button" class="mblBlueButton" onclick="insertResult(nextIndexToAdd)">Add</button> |
| 75 |
<button id="save" type="button" dojoType="dojox.mobile.Button" class="mblBlueButton" onclick="console.log(model[selectedIndex].toPlainObject());model[selectedIndex].commit()">Save</button> |
| 76 |
<button id="reset" type="button" dojoType="dojox.mobile.Button" class="mblBlueButton" onclick="model.reset()">Reset</button> |
| 77 |
<script type="text/javascript"> |
| 78 |
function setDetailsContext(index){ |
| 79 |
selectedIndex = index; |
| 80 |
var groupRoot = dijit.byId("detailsGroup"); |
| 81 |
groupRoot.set("ref", index); |
| 82 |
} |
| 83 |
|
| 84 |
function insertResult(index){ |
| 85 |
if (model[index-1].First.value !== ""){ // TODO: figure out why we are getting called twice for each click |
| 86 |
var insert = dojox.mvc.newStatefulModel({ "data" : { |
| 87 |
"First" : "", |
| 88 |
"Last" : "", |
| 89 |
"Location": "CA", |
| 90 |
"Office" : "", |
| 91 |
"Email" : "", |
| 92 |
"Tel" : "", |
| 93 |
"Fax" : ""} |
| 94 |
}); |
| 95 |
model.add(index, insert); |
| 96 |
setDetailsContext(index); |
| 97 |
nextIndexToAdd++; |
| 98 |
}else{ |
| 99 |
setDetailsContext(index-1); |
| 100 |
} |
| 101 |
} |
| 102 |
</script> |
| 103 |
</body> |
| 104 |
</html> |