| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 |
<title>Programmatic Repeat example, using a store with save, commit and reset</title> |
| 6 |
|
| 7 |
<script src="../../../../dojo/dojo.js" |
| 8 |
type="text/javascript" |
| 9 |
djConfig="parseOnLoad: false, isDebug: true"> |
| 10 |
</script> |
| 11 |
<style type="text/css"> |
| 12 |
@import "css/app-format.css"; |
| 13 |
@import "../../../../dijit/themes/claro/claro.css"; |
| 14 |
</style> |
| 15 |
<script type="text/javascript" > |
| 16 |
dojo.require("dojox.mvc"); |
| 17 |
dojo.require("dojox.mvc.Group"); |
| 18 |
dojo.require("dojox.mvc.Repeat"); |
| 19 |
dojo.require("dijit.form.TextBox"); |
| 20 |
dojo.require("dijit.form.Button"); |
| 21 |
dojo.require("dojo.data.ItemFileWriteStore"); |
| 22 |
dojo.require("dojo.store.DataStore"); |
| 23 |
dojo.require("dojo.parser"); |
| 24 |
|
| 25 |
var results, selectedIndex = 0; |
| 26 |
// declared here for convenience |
| 27 |
templateString = '<div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: \'${this.index}\'">' + |
| 28 |
'<label class="cell">Name:</label>' + |
| 29 |
'<input class="cell" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: \'First\'"></input>' + |
| 30 |
'<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){setDetailsContext(\'${this.index}\');}">Details</button>' + |
| 31 |
'</div>'; |
| 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})}); |
| 36 |
modelPromise.then(function(model){ |
| 37 |
results = model; |
| 38 |
dojo.parser.parse(); |
| 39 |
|
| 40 |
// Can test with either the dojox.mvc.Repeat or my.Repeat |
| 41 |
var repeat = new my.Repeat({ |
| 42 |
//var repeat = new dojox.mvc.Repeat({ |
| 43 |
// templateString: templateString, // not needed with my.Repeat since it is set there. |
| 44 |
ref: model |
| 45 |
}).placeAt('repeat2'); |
| 46 |
repeat.startup(); |
| 47 |
}); |
| 48 |
}; |
| 49 |
|
| 50 |
dojo.declare('my.Repeat', [dojox.mvc.Repeat], { |
| 51 |
templateString : templateString |
| 52 |
}); |
| 53 |
dojo.addOnLoad(setup); |
| 54 |
</script> |
| 55 |
</head> |
| 56 |
<body class="claro" style="background-image: url(images/master_detail.png)"> |
| 57 |
<div id="wrapper"> |
| 58 |
<div id="header"> |
| 59 |
<div id="navigation"> |
| 60 |
</div> |
| 61 |
<div id="headerInsert"> |
| 62 |
<h2>Master Detail Example - With repeat container, using a store, with save, commit and reset.</h2> |
| 63 |
</div> |
| 64 |
</div> |
| 65 |
<div id="main"> |
| 66 |
<div id="leftNav"> |
| 67 |
</div> |
| 68 |
<div id="mainContent"> |
| 69 |
<div id="searchBanner">Search Results for term: </div> |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
<table><tbody><tr> |
| 79 |
<td> |
| 80 |
<div> |
| 81 |
<div>Programatic Repeat using my.Repeat and its templateString: </div> |
| 82 |
<div id="repeat2"></div> |
| 83 |
</div> |
| 84 |
</td> |
| 85 |
<td> |
| 86 |
<div> |
| 87 |
<div>Declarative Repeat using my.Repeat does not pass templateString: </div> |
| 88 |
<div id="repeatId2" data-dojo-type="my.Repeat" data-dojo-props="ref: 'results'"></div> |
| 89 |
</div> |
| 90 |
</td> |
| 91 |
</tr></tbody></table> |
| 92 |
|
| 93 |
<div class="spacer"></div> |
| 94 |
|
| 95 |
<div data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'results'"> |
| 96 |
<div id="detailsBanner">Details for selected index:</div> |
| 97 |
|
| 98 |
<div id="detailsGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: '0'"> |
| 99 |
<div class="row"> |
| 100 |
<label class="cell" for="firstInput">First Name:</label> |
| 101 |
<input class="cell" id="firstInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'First'"></input> |
| 102 |
</div> |
| 103 |
<div class="row"> |
| 104 |
<label class="cell" for="lastInput">Last Name:</label> |
| 105 |
<input class="cell" id="lastInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Last'"></input> |
| 106 |
</div> |
| 107 |
<div class="row"> |
| 108 |
<label class="cell" for="locationInput">Location:</label> |
| 109 |
<input class="cell" id="locationInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Location'"></input> |
| 110 |
</div> |
| 111 |
<div class="row"> |
| 112 |
<label class="cell" for="officeInput">Office:</label> |
| 113 |
<input class="cell" id="officeInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Office'"></input> |
| 114 |
</div> |
| 115 |
<div class="row"> |
| 116 |
<label class="cell" for="emailInput">Email:</label> |
| 117 |
<input class="cell" id="emailInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Email'"></input> |
| 118 |
</div> |
| 119 |
<div class="row"> |
| 120 |
<label class="cell" for="telInput">Telephone:</label> |
| 121 |
<input class="cell" id="telInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Tel'"></input> |
| 122 |
</div> |
| 123 |
<div class="row"> |
| 124 |
<label class="cell" for="faxInput">Fax:</label> |
| 125 |
<input class="cell" id="faxInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="ref: 'Fax'"></input> |
| 126 |
</div> |
| 127 |
<div class="row"> |
| 128 |
<div class="spacer"></div> |
| 129 |
<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> |
| 130 |
<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){console.log(results.toPlainObject());results.commit();;}">Commit All</button> |
| 131 |
<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){results.reset();}">Reset to last saved</button> |
| 132 |
</div> |
| 133 |
</div> |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
</div> |
| 137 |
</div> |
| 138 |
<script type="text/javascript"> |
| 139 |
// called to change the selected item |
| 140 |
function setDetailsContext(index) { |
| 141 |
selectedIndex = index; |
| 142 |
var widget = dijit.byId("detailsGroup"); |
| 143 |
widget.set("ref", index); |
| 144 |
}; |
| 145 |
</script> |
| 146 |
</body> |
| 147 |
</html> |