Debian Codegraph @

dojox/mvc/tests/doh/doh_mvc_sync-test.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5 <title>MVC DOH Test</title>
6
7 <style>
8 @import "../../../../dojo/resources/dojo.css";
9 @import "../../../../dijit/tests/css/dijitTests.css";
10 @import "../css/app-format.css";
11 </style>
12
13 <!-- required: the default dijit theme: -->
14 <link id="themeStyles" rel="stylesheet" href="../../../../dijit/themes/claro/claro.css">
15
16 <!-- required: dojo.js -->
17 <script src="../../../../dojo/dojo.js" type="text/javascript" data-dojo-config="isDebug: 1, parseOnLoad: 0, async: 1"></script>
18 <script type="text/javascript" src="./helpers.js"></script>
19
20 <script type="text/javascript">
21 require([
22 "doh/runner",
23 "dojo/parser",
24 "dojo/when",
25 "dojo/Stateful",
26 "dijit/registry",
27 "dojox/mvc/sync",
28 "dijit/form/TextBox",
29 "dijit/form/NumberTextBox",
30 "dijit/form/ValidationTextBox",
31 "dijit/form/Button",
32 "dojox/mvc/Output"
33 ], function(doh, parser, when, Stateful, registry, sync){
34 model = new Stateful({
35 First: "John",
36 Last: "Doe",
37 Email: "[email protected]",
38 Num: 3
39 });
40 model2 = new Stateful({
41 First: "John2",
42 Last: "Doe2",
43 Email: "[email protected]",
44 Num: 2
45 });
46 model3 = new Stateful({
47 First: "",
48 Last: "",
49 Email: "",
50 Num: 3
51 });
52 model4 = new Stateful({
53 First: "John4",
54 Last: "Doe4",
55 Email: "[email protected]",
56 Num: 4
57 });
58 model5 = new Stateful({
59 First: "",
60 Last: "",
61 Email: "",
62 Num: 5
63 });
64
65 function noParse(){
66 throw new Error();
67 }
68
69 readOnlyConverter = {
70 format: function(value){
71 return value === "2" || value === "3";
72 },
73 parse: noParse
74 };
75
76 relevanceConverter = {
77 format: function(value){
78 return value !== "0";
79 },
80 parse: noParse
81 };
82
83 numValidConverter = {
84 format: function(value){
85 return value !== "3" && !(value - 0 === 1);
86 },
87 parse: noParse
88 };
89
90 emailConverter = {
91 format: function(value){
92 return value + "formatted";
93 },
94 parse: noParse
95 };
96
97 requiredConverter = {
98 format: function(value){
99 return value - 0 === 4;
100 },
101 parse: noParse
102 };
103
104 lastValidConverter = {
105 format: function(value){
106 return value !== "1";
107 },
108 parse: noParse
109 };
110
111 when(parser.parse(), function(){
112 doh.register("Check sync values from 2 to 3", [{
113 name: "Initial",
114 runTest: function(){
115 // sync test
116 var firstx2 = "";
117 sync(model2, "First", model3, "First");
118 doh.is("John2", model3.get("First"), "model3.First should be John2");
119 // set model3.First should update model2.First
120 model3.set("First", "Billy3");
121 doh.is("Billy3", model2.get("First"), "model2.First should now be Billy3");
122
123 sync(model2, "Last", model3, "Last", {bindDirection:sync.from});
124 // sync(model2, "Last", model3, "Last", {bindDirection:sync.to});
125 doh.is("Doe2", model3.get("Last"), "model3.Last should be Doe2");
126 // set model3.Last should NOT update model2.Last
127 model3.set("Last", "Billy3");
128 doh.is("Doe2", model2.get("Last"), "model2.Last should still be Doe2");
129
130 sync(model2, "Num", model3, "Num", {bindDirection:sync.to});
131 doh.is(3, model2.get("Num"), "model2.Num should be 3");
132 doh.is(3, model3.get("Num"), "model3.Num should be 3");
133 }
134 }, {
135 name: "TestSyncWildCard",
136 runTest: function(){
137 sync(model4, "*", model5, "*");
138 doh.is("John4", model5.get("First"), "model5.First should be John4");
139 doh.is("Doe4", model5.get("Last"), "model5.Last should now be Doe4");
140 // set model5.Last should update model4.Last
141 model5.set("Last", "Upate5");
142 doh.is("Upate5", model4.get("Last"), "model4.Last should be Upate5");
143 }
144 }, {
145 name: "TestSyncConverter",
146 runTest: function(){
147 sync(model2, "Email", model3, "Email", {converter : emailConverter});
148 doh.is("[email protected]", model3.get("Email"), "model3.Email should be [email protected]");
149 model2.set("Email", "Em2");
150 doh.is("Em2formatted", model3.get("Email"), "model3.Email should be Em2formatted");
151 // doh.is("Doe4", model5.get("Last"), "model5.Last should now be Doe4");
152 }
153 }]);
154
155 doh.run();
156 });
157 });
158 </script>
159 </head>
160 <body class="claro">
161 <script type="dojo/require">at: "dojox/mvc/at"</script>
162 <div id="wrapper">
163 <div id="header">
164 <div id="navigation"></div>
165 <div id="headerInsert">
166 <h1>Binding Tests</h1>
167 </div>
168 </div>
169 <div id="main">
170 <div id="leftNav">
171 </div>
172 <div id="mainContent">
173 <h2>Bind Self Tests</h2>
174 <div class="row">
175 <label class="cell" for="firstnameInput">Model2 First:</label>
176 <input class="cell" id="firstnameInput" data-dojo-type="dijit.form.ValidationTextBox"
177 data-dojo-props="value: at(model2, 'First')">
178 <!-- Content in output below will always be in sync with value of textbox above -->
179 First name is: <span id="tout" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(model2, 'First')"></span>
180 </div>
181 <div class="row">
182 <label class="cell" for="firstnameInput3">Model3 First:</label>
183 <input class="cell" id="firstnameInput3" data-dojo-type="dijit.form.ValidationTextBox"
184 data-dojo-props="value: at(model3, 'First')">
185 <!-- Content in output below will always be in sync with value of textbox above -->
186 First name is: <span id="tout3" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(model3, 'First')"></span>
187 </div>
188 <div class="row">
189 <label class="cell" for="lastnameInput">Model2 Last:</label>
190 <input class="cell" id="lastnameInput" data-dojo-type="dijit.form.ValidationTextBox"
191 data-dojo-props="value: at(model2, 'Last')">
192 <!-- Content in output below will always be in sync with value of textbox above -->
193 Last name is: <span id="lasttout" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(model2, 'Last')"></span>
194 </div>
195 <div class="row">
196 <label class="cell" for="lastnameInput3">Model3 Last:</label>
197 <input class="cell" id="lastnameInput3" data-dojo-type="dijit.form.ValidationTextBox"
198 data-dojo-props="value: at(model3, 'Last')">
199 <!-- Content in output below will always be in sync with value of textbox above -->
200 Last name is: <span id="lasttout3" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(model3, 'Last')"></span>
201 </div>
202 <div class="row">
203 <label class="cell" for="emailInput2">Email:</label>
204 <input class="cell" id="emailInput2" data-dojo-type="dijit.form.ValidationTextBox"
205 data-dojo-props="value: at(model2, 'Email')">
206 Model2 Email is: <span data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(model2, 'Email')"></span>
207 </div>
208 <div class="row">
209 <label class="cell" for="emailInput3">Email:</label>
210 <input class="cell" id="emailInput3" data-dojo-type="dijit.form.ValidationTextBox"
211 data-dojo-props="value: at(model3, 'Email')">
212 Model3 Email is: <span data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(model3, 'Email')"></span>
213 </div>
214 </div>
215 </div>
216 </div>
217 </body>
218 </html>