| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 |
<title>Data binding -- Ref kitchen sink example</title> |
| 6 |
|
| 7 |
<script src="../../../../dojo/dojo.js" |
| 8 |
type="text/javascript" |
| 9 |
djConfig="parseOnLoad: true, 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("dijit.form.TextBox"); |
| 19 |
dojo.require("dijit.form.Button"); |
| 20 |
dojo.require("dojo.parser"); |
| 21 |
|
| 22 |
// Initial data |
| 23 |
var order = { |
| 24 |
"Serial" : "360324", |
| 25 |
"First" : "John", |
| 26 |
"Last" : "Doe", |
| 27 |
"Email" : "[email protected]", |
| 28 |
"ShipTo" : { |
| 29 |
"Street" : "123 Valley Rd", |
| 30 |
"City" : "Katonah", |
| 31 |
"State" : "NY", |
| 32 |
"Zip" : "10536" |
| 33 |
}, |
| 34 |
"BillTo" : { |
| 35 |
"Street" : "17 Skyline Dr", |
| 36 |
"City" : "Hawthorne", |
| 37 |
"State" : "NY", |
| 38 |
"Zip" : "10532" |
| 39 |
} |
| 40 |
}; |
| 41 |
|
| 42 |
// This example is an odd mix of everything, being the kitchen sink example :-) |
| 43 |
|
| 44 |
// The dojox.mvc.StatefulModel class creates a data model instance, which will be |
| 45 |
// shared by widgets being instantiated programmatically as well as |
| 46 |
// declaratively |
| 47 |
var model = dojox.mvc.newStatefulModel({ data : order }); |
| 48 |
|
| 49 |
// Here is programmatic data bound widget instantiation |
| 50 |
function addBoundDijits(){ |
| 51 |
// Absolute ref, passed as object |
| 52 |
var serial = new dijit.form.TextBox({id: "serialInput", ref: model.Serial}); |
| 53 |
serial.placeAt(dojo.byId("serialDiv")); |
| 54 |
serial.startup(); |
| 55 |
|
| 56 |
// Relative refs, passed as strings |
| 57 |
var fn = new dijit.form.TextBox({id: "firstnameInput", ref: "First"}); |
| 58 |
fn.placeAt(dojo.byId("firstnameDiv")); |
| 59 |
fn.startup(); |
| 60 |
var ln = new dijit.form.TextBox({id: "lastnameInput", ref: "Last"}); |
| 61 |
ln.placeAt(dojo.byId("lastnameDiv")); |
| 62 |
ln.startup(); |
| 63 |
} |
| 64 |
|
| 65 |
dojo.addOnLoad(addBoundDijits); |
| 66 |
</script> |
| 67 |
</head> |
| 68 |
<body class="claro"> |
| 69 |
<div id="wrapper"> |
| 70 |
<div id="header"> |
| 71 |
<div id="navigation"> |
| 72 |
</div> |
| 73 |
<div id="headerInsert"> |
| 74 |
<h1>Data Binding</h1> |
| 75 |
<h2>Ref kitchen sink example - all ways to specify refs, mixed bag on purpose.</h2> |
| 76 |
</div> |
| 77 |
</div> |
| 78 |
<div id="main"> |
| 79 |
<div id="leftNav"> |
| 80 |
</div> |
| 81 |
<div id="mainContent"> |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
<div class="row" id="infoGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'model'"> |
| 89 |
|
| 90 |
<div class="row" id="serialDiv"> |
| 91 |
<label class="cell" for="serialInput">Order #:</label> |
| 92 |
</div> |
| 93 |
|
| 94 |
|
| 95 |
<div class="row" id="firstnameDiv"> |
| 96 |
<label class="cell" for="firstnameInput">First:</label> |
| 97 |
</div> |
| 98 |
<div class="row" id="lastnameDiv"> |
| 99 |
<label class="cell" for="lastnameInput">Last:</label> |
| 100 |
</div> |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
<div class="row" id="emailDiv"> |
| 106 |
<label class="cell" for="emailInput">Email:</label> |
| 107 |
<input class="cell" id="emailInput" data-dojo-type="dijit.form.TextBox" |
| 108 |
data-dojo-props="ref: 'expr:model.Email'"></input> |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
<br/> |
| 112 |
Choose: |
| 113 |
<button id="shipto" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){setRef('addrGroup', model.ShipTo);}">Ship To</button> |
| 114 |
<button id="billto" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){setRef('addrGroup', model.BillTo);}">Bill To</button> |
| 115 |
<br/> |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
<div class="row" id="addrGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'widget:infoGroup.ShipTo'"> |
| 124 |
|
| 125 |
<div class="row"> |
| 126 |
<label class="cell" for="streetInput">Street:</label> |
| 127 |
<input class="cell" id="streetInput" data-dojo-type="dijit.form.TextBox" |
| 128 |
data-dojo-props="ref: 'Street'"></input> |
| 129 |
</div> |
| 130 |
|
| 131 |
|
| 132 |
<div class="row"> |
| 133 |
<label class="cell" for="cityInput">City:</label> |
| 134 |
<input class="cell" id="cityInput" data-dojo-type="dijit.form.TextBox" |
| 135 |
data-dojo-props="ref: 'rel:City'"></input> |
| 136 |
</div> |
| 137 |
|
| 138 |
<div class="row"> |
| 139 |
<label class="cell" for="stateInput">State:</label> |
| 140 |
<input class="cell" id="stateInput" data-dojo-type="dijit.form.TextBox" |
| 141 |
data-dojo-props="ref: ' rel: State' "></input> |
| 142 |
</div> |
| 143 |
<div class="row"> |
| 144 |
<label class="cell" for="zipInput">Zipcode:</label> |
| 145 |
<input class="cell" id="zipInput" data-dojo-type="dijit.form.TextBox" |
| 146 |
data-dojo-props="ref: 'Zip' "></input> |
| 147 |
</div> |
| 148 |
</div> |
| 149 |
<br/> |
| 150 |
Model: |
| 151 |
<button id="reset" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){model.reset();}">Reset</button> |
| 152 |
</div></div></div> |
| 153 |
<script type="text/javascript"> |
| 154 |
function setRef(id, addrRef) { |
| 155 |
var widget = dijit.byId(id); |
| 156 |
widget.set("ref", addrRef); |
| 157 |
} |
| 158 |
</script> |
| 159 |
</body> |
| 160 |
</html> |