| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 |
<title>DOH Async Simple Input - Output Group example</title> |
| 6 |
<style type="text/css"> |
| 7 |
@import "../../../../dojo/resources/dojo.css"; |
| 8 |
@import "../../../../dijit/tests/css/dijitTests.css"; |
| 9 |
@import "../css/app-format.css"; |
| 10 |
@import "../../../../dijit/themes/claro/claro.css"; |
| 11 |
</style> |
| 12 |
<script type="text/javascript" data-dojo-config="parseOnLoad:0,isDebug:1,async:1,mvc:{debugBindings:1}" src="../../../../dojo/dojo.js"></script> |
| 13 |
<script type="text/javascript"> |
| 14 |
var model; |
| 15 |
|
| 16 |
require([ |
| 17 |
'dojo/parser', |
| 18 |
'dojo/when', |
| 19 |
'dojox/mvc/EditModelRefController', |
| 20 |
'dojo/Stateful', |
| 21 |
'dojox/mvc/Group', |
| 22 |
'dojox/mvc/Output', |
| 23 |
'dojo/parser', |
| 24 |
'dijit/form/TextBox', |
| 25 |
'dijit/form/Button'], function(parser, when, EditModelRefController, Stateful){ |
| 26 |
|
| 27 |
// The dojox.mvc.StatefulModel class creates a data model instance |
| 28 |
// where each leaf within the data model is decorated with dojo.Stateful |
| 29 |
// properties that widgets can bind to and watch for their changes. |
| 30 |
//model = dojox.mvc.newStatefulModel({ data : { "First" : "John", "Last" : "Doe", "Email" : "[email protected]" }}); |
| 31 |
model = new EditModelRefController({sourceModel: new Stateful({ "First" : "John", "Last" : "Doe", "Email" : "[email protected]" })}); |
| 32 |
|
| 33 |
require([ |
| 34 |
'doh/runner', 'dijit/dijit' |
| 35 |
], function(){ |
| 36 |
require([ |
| 37 |
'dojo/domReady!' |
| 38 |
], function(){ |
| 39 |
doh.register("parse", function() { |
| 40 |
var dfd = new doh.Deferred(); |
| 41 |
when(dojo.parser.parse(), function(){ |
| 42 |
var detailsGroup = dijit.byId('detailsGroup'); |
| 43 |
detailsGroup.set('target', model); |
| 44 |
dfd.callback(true); |
| 45 |
}); |
| 46 |
return dfd; |
| 47 |
}); |
| 48 |
// should be able to verify all of the inputs |
| 49 |
doh.register("check initial values and bindings", [{ |
| 50 |
name : "initial", |
| 51 |
runTest : function() { |
| 52 |
doh.is("John", dijit.byId("First").get('value'),"First should be John"); |
| 53 |
doh.is("John", dijit.byId("dojox_mvc_Output_0").get('value'),"dojox_mvc_Output_0 should be John"); |
| 54 |
|
| 55 |
doh.is("Doe", dijit.byId("lastnameInput").get('value'),"lastnameInput should be Doe"); |
| 56 |
doh.is("Doe", dijit.byId("dojox_mvc_Output_1").get('value'),"dojox_mvc_Output_1 should be Doe"); |
| 57 |
|
| 58 |
doh.is("[email protected]", dijit.byId("emailInput").get('value'),"emailInput should be [email protected]"); |
| 59 |
doh.is("[email protected]", dijit.byId("dojox_mvc_Output_2").get('value'),"dojox_mvc_Output_2 should be [email protected]"); |
| 60 |
} |
| 61 |
}]); |
| 62 |
|
| 63 |
doh.register("update first name", [{ |
| 64 |
name : "Update-First-Name", |
| 65 |
runTest : function() { |
| 66 |
var first1, bind1, addr1; |
| 67 |
//test first relevant false |
| 68 |
first1 = dijit.byId("First"); |
| 69 |
first1.set("value","John-update"); |
| 70 |
if (first1) { |
| 71 |
doh.is("John-update", dijit.byId("First").get('value'),"First should be John"); |
| 72 |
doh.is("John-update", dijit.byId("dojox_mvc_Output_0").get('value'),"dojox_mvc_Output_0 should be John"); |
| 73 |
} |
| 74 |
} |
| 75 |
}]); |
| 76 |
doh.register("update last name", [{ |
| 77 |
name : "Update-Last-Name", |
| 78 |
runTest : function() { |
| 79 |
var last; |
| 80 |
//test first relevant false |
| 81 |
last = dijit.byId("lastnameInput"); |
| 82 |
last.set("value","Doe-update"); |
| 83 |
if (last) { |
| 84 |
doh.is("Doe-update", dijit.byId("lastnameInput").get('value'),"lastnameInput should be Doe-update"); |
| 85 |
doh.is("Doe-update", dijit.byId("dojox_mvc_Output_1").get('value'),"dojox_mvc_Output_1 should be Doe-update"); |
| 86 |
} |
| 87 |
} |
| 88 |
}]); |
| 89 |
doh.register("update last name", [{ |
| 90 |
name : "Update-Last-Name", |
| 91 |
runTest : function() { |
| 92 |
var last; |
| 93 |
//test first relevant false |
| 94 |
email = dijit.byId("emailInput"); |
| 95 |
email.set("value","[email protected]"); |
| 96 |
if (email) { |
| 97 |
doh.is("[email protected]", dijit.byId("emailInput").get('value'),"emailInput should be [email protected]"); |
| 98 |
doh.is("[email protected]", dijit.byId("dojox_mvc_Output_2").get('value'),"dojox_mvc_Output_2 should be [email protected]"); |
| 99 |
} |
| 100 |
} |
| 101 |
}]); |
| 102 |
doh.register("reset back to initial values and bindings", [{ |
| 103 |
name : "reset_test", |
| 104 |
runTest : function() { |
| 105 |
model.reset(); |
| 106 |
doh.is("John", dijit.byId("First").get('value'),"First should be John"); |
| 107 |
doh.is("John", dijit.byId("dojox_mvc_Output_0").get('value'),"dojox_mvc_Output_0 should be John"); |
| 108 |
|
| 109 |
doh.is("Doe", dijit.byId("lastnameInput").get('value'),"lastnameInput should be Doe"); |
| 110 |
doh.is("Doe", dijit.byId("dojox_mvc_Output_1").get('value'),"dojox_mvc_Output_1 should be Doe"); |
| 111 |
|
| 112 |
doh.is("[email protected]", dijit.byId("emailInput").get('value'),"emailInput should be [email protected]"); |
| 113 |
doh.is("[email protected]", dijit.byId("dojox_mvc_Output_2").get('value'),"dojox_mvc_Output_2 should be [email protected]"); |
| 114 |
} |
| 115 |
}]); |
| 116 |
|
| 117 |
doh.run(); |
| 118 |
|
| 119 |
}); |
| 120 |
}); |
| 121 |
}); |
| 122 |
</script> |
| 123 |
</head> |
| 124 |
<body class="claro"> |
| 125 |
<script type="dojo/require">at: "dojox/mvc/at"</script> |
| 126 |
<div id="wrapper"> |
| 127 |
<div id="header"> |
| 128 |
<div id="navigation"></div> |
| 129 |
<div id="headerInsert"> |
| 130 |
<h1>Async Input Output Test</h1> |
| 131 |
<h2>Data Binding Example</h2> |
| 132 |
</div> |
| 133 |
</div> |
| 134 |
<div id="main"> |
| 135 |
<div id="leftNav"></div> |
| 136 |
<div id="detailsGroup" dojoType="dojox.mvc.Group"> |
| 137 |
<div class="row"> |
| 138 |
<label class="cell" for="First">First:</label> |
| 139 |
<input class="cell" id="First" data-dojo-type="dijit.form.TextBox" |
| 140 |
data-dojo-props="value: at('rel:', 'First')"></input> |
| 141 |
|
| 142 |
<span data-dojo-type="dojox.mvc.Output" |
| 143 |
data-dojo-props="value: at('rel:', 'First')"> |
| 144 |
(first name is: ${this.value}) |
| 145 |
</span> |
| 146 |
</div> |
| 147 |
<div class="row"> |
| 148 |
<label class="cell" for="lastnameInput">Last:</label> |
| 149 |
<input class="cell" id="lastnameInput" data-dojo-type="dijit.form.TextBox" |
| 150 |
data-dojo-props="value: at('rel:', 'Last')"></input> |
| 151 |
<span data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at('rel:', 'Last')"> |
| 152 |
(last name is: ${this.value}) |
| 153 |
</span> |
| 154 |
</div> |
| 155 |
<div class="row"> |
| 156 |
<label class="cell" for="emailInput">Email:</label> |
| 157 |
<input class="cell" id="emailInput" data-dojo-type="dijit.form.TextBox" |
| 158 |
data-dojo-props="value: at('rel:', 'Email')"></input> |
| 159 |
<span data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at('rel:', 'Email')"> |
| 160 |
(email is: ${this.value}) |
| 161 |
</span> |
| 162 |
</div> |
| 163 |
<br/>Model: |
| 164 |
<button id="reset" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){model.reset();}">Reset</button> |
| 165 |
</div> |
| 166 |
</div> |
| 167 |
</div> |
| 168 |
</body> |
| 169 |
|
| 170 |
</html> |