| 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 | <style> |
| 7 | @import "../../../../dojo/resources/dojo.css"; |
| 8 | @import "../../../../dijit/tests/css/dijitTests.css"; |
| 9 | @import "../css/app-format.css"; |
| 10 | </style> |
| 11 | <link id="themeStyles" rel="stylesheet" href="../../../../dijit/themes/claro/claro.css"/> |
| 12 | <script src="../../../../dojo/dojo.js" type="text/javascript" data-dojo-config="isDebug: true, mvc: {debugBindings: true}"></script> |
| 13 | <script type="text/javascript" src="./helpers.js"></script> |
| 14 | <script type="text/javascript"> |
| 15 | var ctrl, data1, data2, data3; |
| 16 | |
| 17 | require([ |
| 18 | "doh/runner", |
| 19 | "dojo/_base/array", |
| 20 | "dojo/_base/lang", |
| 21 | "dojo/when", |
| 22 | "dojo/parser", |
| 23 | "dojo/store/Memory", |
| 24 | "dijit/registry", |
| 25 | "dojox/mvc/getStateful", |
| 26 | "dojox/mvc/ModelRefController", |
| 27 | "dijit/form/TextBox", |
| 28 | "dijit/form/Button", |
| 29 | "dojox/mvc/Group", |
| 30 | "dojox/mvc/Output", |
| 31 | "dojox/mvc/Repeat", |
| 32 | "dojo/domReady!" |
| 33 | ], function(doh, array, lang, when, parser, MemoryStore, registry, getStateful, ModelRefController){ |
| 34 | |
| 35 | function runTests(){ |
| 36 | doh.register("Tests", [ |
| 37 | { |
| 38 | name : "initial", |
| 39 | runTest : function() { |
| 40 | ctrl.set("model", ctrl.get("model1")); |
| 41 | doh.is("Anne1", registry.byId("nameInput0").get("value"), "nameInput0 should be Anne1"); |
| 42 | doh.is("Ben1", registry.byId("nameInput1").get("value"), "nameInput1 should be Ben1 "); |
| 43 | doh.is("Chad1", registry.byId("nameInput2").get("value"), "nameInput2 should be Chad1"); |
| 44 | doh.is("Anne1", registry.byId("firstnameOutput10").get("value"), "firstnameOutput10 should be Anne1"); |
| 45 | doh.is("Ben1", registry.byId("firstnameOutput11").get("value"), "firstnameOutput11 should be Ben1 "); |
| 46 | doh.is("Chad1", registry.byId("firstnameOutput12").get("value"), "firstnameOutput12 should be Chad1"); |
| 47 | doh.is("Anne2", registry.byId("firstnameOutput20").get("value"), "firstnameOutput20 should be Anne2"); |
| 48 | doh.is("Ben2", registry.byId("firstnameOutput21").get("value"), "firstnameOutput21 should be Ben2 "); |
| 49 | doh.is("", registry.byId("firstnameOutput30").get("value"), "firstnameOutput30 should be blank"); |
| 50 | } |
| 51 | }, { |
| 52 | name : "SelectModel2", |
| 53 | runTest : function() { |
| 54 | ctrl.set("model", ctrl.get("model2")); |
| 55 | doh.is("Anne2", registry.byId("nameInput0").get("value"), "nameInput0 should be Anne2"); |
| 56 | doh.is("Ben2", registry.byId("nameInput1").get("value"), "nameInput1 should be Ben2 "); |
| 57 | } |
| 58 | }, { |
| 59 | name : "ChangeModel2", |
| 60 | runTest : function() { |
| 61 | registry.byId("nameInput0").set("value", "Anne2-Update"); |
| 62 | doh.is("Anne2-Update", registry.byId("nameInput0").get("value"), "nameInput0 should be Anne2-Update"); |
| 63 | doh.is("Ben2", registry.byId("nameInput1").get("value"), "nameInput1 should be Ben2 "); |
| 64 | doh.is("Anne2-Update", registry.byId("firstnameOutput20").get("value"), "firstnameOutput20 should be Anne2-Update"); |
| 65 | doh.is("Ben2", registry.byId("firstnameOutput21").get("value"), "firstnameOutput21 should be Ben2 "); |
| 66 | } |
| 67 | }, { |
| 68 | name : "SelectModel3", |
| 69 | runTest : function() { |
| 70 | ctrl.set("model", ctrl.get("model3")); |
| 71 | doh.is("", registry.byId("nameInput0").get("value"), "nameInput0 should be blank"); |
| 72 | } |
| 73 | }, { |
| 74 | name : "ChangeModel3", |
| 75 | runTest : function() { |
| 76 | registry.byId("nameInput0").set("value", "Anne3-Update"); |
| 77 | doh.is("Anne3-Update", registry.byId("nameInput0").get("value"), "nameInput0 should be Anne3-Update"); |
| 78 | doh.is("Anne3-Update", registry.byId("firstnameOutput30").get("value"), "firstnameOutput30 should be Anne3-Update"); |
| 79 | } |
| 80 | }, { |
| 81 | name : "UpdateData1", |
| 82 | runTest : function() { |
| 83 | var newdata = { |
| 84 | "Results": [ |
| 85 | { |
| 86 | "First": "Anne1x", |
| 87 | "Last": "Ackerman1x" |
| 88 | }, |
| 89 | { |
| 90 | "First": "Ben1x", |
| 91 | "Last": "Beckham1x" |
| 92 | } |
| 93 | ] |
| 94 | }; |
| 95 | ctrl.set("model", newdata); |
| 96 | doh.is("Anne1x", registry.byId("nameInput0").get("value"), "nameInput0 should be Anne1X"); |
| 97 | } |
| 98 | } |
| 99 | ]); |
| 100 | |
| 101 | doh.run(); |
| 102 | } |
| 103 | |
| 104 | ctrl = new ModelRefController({ownProps: {model1: 1, model2: 1, model3: 1}}); |
| 105 | |
| 106 | when(parser.parse(), function(){ |
| 107 | when((new MemoryStore({data: data1 = [ |
| 108 | { |
| 109 | "Query": "Engineers1", |
| 110 | "Results": [ |
| 111 | { |
| 112 | "First": "Anne1", |
| 113 | "Last": "Ackerman1" |
| 114 | }, |
| 115 | { |
| 116 | "First": "Ben1", |
| 117 | "Last": "Beckham1" |
| 118 | }, |
| 119 | { |
| 120 | "First": "Chad1", |
| 121 | "Last": "Chapman1" |
| 122 | } |
| 123 | ] |
| 124 | } |
| 125 | ]})).query(), function(data){ |
| 126 | ctrl.set("model1", getStateful(data)[0]); |
| 127 | if(ctrl.get("model1") && ctrl.get("model2") && ctrl.get("model3")){ runTests(); } |
| 128 | }); |
| 129 | |
| 130 | when((new MemoryStore({data: data2 = [ |
| 131 | { |
| 132 | "Query": "Engineers2", |
| 133 | "Results": [ |
| 134 | { |
| 135 | "First": "Anne2", |
| 136 | "Last": "Ackerman2" |
| 137 | }, |
| 138 | { |
| 139 | "First": "Ben2", |
| 140 | "Last": "Beckham2" |
| 141 | } |
| 142 | ] |
| 143 | } |
| 144 | ]}).query()), function(data){ |
| 145 | ctrl.set("model2", getStateful(data)[0]); |
| 146 | if(ctrl.get("model1") && ctrl.get("model2") && ctrl.get("model3")){ runTests(); } |
| 147 | }); |
| 148 | |
| 149 | when((new MemoryStore({data: data3 = [ |
| 150 | { |
| 151 | "Query": "Engineers3", |
| 152 | "Results": [ |
| 153 | { |
| 154 | "First": "", |
| 155 | "Last": "" |
| 156 | } |
| 157 | ] |
| 158 | } |
| 159 | ]}).query()), function(data){ |
| 160 | ctrl.set("model3", getStateful(data)[0]); |
| 161 | if(ctrl.get("model1") && ctrl.get("model2") && ctrl.get("model3")){ runTests(); } |
| 162 | }); |
| 163 | }); |
| 164 | }); |
| 165 | </script> |
| 166 | </head> |
| 167 | <body class="claro"> |
| 168 | <script type="dojo/require">at: "dojox/mvc/at"</script> |
| 169 | <div id="wrapper"> |
| 170 | <div id="header"> |
| 171 | <div id="navigation"></div> |
| 172 | <div id="headerInsert"> |
| 173 | <h1>Input Output Sync</h1> |
| 174 | <h2>Data Binding Example</h2> |
| 175 | </div> |
| 176 | </div> |
| 177 | <div id="main"> |
| 178 | <div id="leftNav"></div> |
| 179 | <div id="mainContent"> |
| 180 | <div id="repeatId" data-dojo-type="dojox.mvc.Repeat" data-dojo-props="children: at(ctrl, 'Results')"> |
| 181 | <div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at('rel:${this.index}')"> |
| 182 | <label class="cell" for="nameInput${this.index}">Name:</label> |
| 183 | <input class="cell" data-dojo-type="dijit.form.TextBox" id="nameInput${this.index}" data-dojo-props="value: at('rel:', 'First')"/> |
| 184 | </div> |
| 185 | </div> |
| 186 | <div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at(ctrl, 'model1')"> |
| 187 | <div data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at('rel:', 'Results')"> |
| 188 | <span> |
| 189 | Model1 Output is ==> |
| 190 | </span> |
| 191 | <span id="firstnameOutput10" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at('rel:0', 'First')"> |
| 192 | Name1 is "${this.value}" : |
| 193 | </span> |
| 194 | <span id="firstnameOutput11" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at('rel:1', 'First')"> |
| 195 | Name2 is "${this.value}" : |
| 196 | </span> |
| 197 | <span id="firstnameOutput12" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at('rel:2', 'First')"> |
| 198 | Name3 is "${this.value}" |
| 199 | </span> |
| 200 | </div> |
| 201 | </div> |
| 202 | <div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at(ctrl, 'model2')"> |
| 203 | <div data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at('rel:', 'Results')"> |
| 204 | <span> |
| 205 | Model2 Output is ==> |
| 206 | </span> |
| 207 | <span id="firstnameOutput20" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at('rel:0', 'First')"> |
| 208 | Name1 is "${this.value}" : |
| 209 | </span> |
| 210 | <span id="firstnameOutput21" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at('rel:1', 'First')"> |
| 211 | Name2 is "${this.value}" |
| 212 | </span> |
| 213 | </div> |
| 214 | </div> |
| 215 | <div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at(ctrl, 'model3')"> |
| 216 | <div data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at('rel:', 'Results')"> |
| 217 | <span> |
| 218 | Model3 Output is ==> |
| 219 | </span> |
| 220 | <span id="firstnameOutput30" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at('rel:0', 'First')"> |
| 221 | Name1 is "${this.value}" |
| 222 | </span> |
| 223 | </div> |
| 224 | </div> |
| 225 | </div> |
| 226 | </div> |
| 227 | </div> |
| 228 | </body> |
| 229 | </html> |