| 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" djConfig="isDebug: true"></script> |
| 13 | <script type="text/javascript" src="../helpers.js"></script> |
| 14 | <script type="text/javascript"> |
| 15 | dojo.require("dojox.mvc"); |
| 16 | dojo.require("dojox.mvc.Output"); |
| 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.store.Memory"); |
| 22 | dojo.require("dojo.parser"); |
| 23 | |
| 24 | var search_results_init1 = |
| 25 | [{ |
| 26 | "Query" : "Engineers1", |
| 27 | "Results" : [ |
| 28 | { |
| 29 | "First" : "Anne1", |
| 30 | "Last" : "Ackerman1" |
| 31 | }, |
| 32 | { |
| 33 | "First" : "Ben1", |
| 34 | "Last" : "Beckham1" |
| 35 | }, |
| 36 | { |
| 37 | "First" : "Chad1", |
| 38 | "Last" : "Chapman1" |
| 39 | } |
| 40 | ] |
| 41 | }]; |
| 42 | var search_results_init2 = |
| 43 | [{ |
| 44 | "Query" : "Engineers2", |
| 45 | "Results" : [ |
| 46 | { |
| 47 | "First" : "Anne2", |
| 48 | "Last" : "Ackerman2" |
| 49 | }, |
| 50 | { |
| 51 | "First" : "Ben2", |
| 52 | "Last" : "Beckham2" |
| 53 | } |
| 54 | ] |
| 55 | }]; |
| 56 | var search_results_init3 = |
| 57 | [{ |
| 58 | "Query" : "Engineers3", |
| 59 | "Results" : [ |
| 60 | { |
| 61 | "First" : "", |
| 62 | "Last" : "" |
| 63 | } |
| 64 | ] |
| 65 | }]; |
| 66 | |
| 67 | var memStore1 = new dojo.store.Memory({data : search_results_init1}); |
| 68 | var model1 = dojox.mvc.newStatefulModel({ store : memStore1 })[0]; |
| 69 | var memStore2 = new dojo.store.Memory({data : search_results_init2}); |
| 70 | var model2 = dojox.mvc.newStatefulModel({ store : memStore2 })[0]; |
| 71 | var memStore3 = new dojo.store.Memory({data : search_results_init3}); |
| 72 | var model3 = dojox.mvc.newStatefulModel({ store : memStore3 })[0]; |
| 73 | </script> |
| 74 | |
| 75 | <script type="text/javascript"> |
| 76 | dojo.require('doh.runner'); |
| 77 | dojo.require("dijit.dijit"); // optimize: load dijit layer |
| 78 | dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
| 79 | |
| 80 | dojo.addOnLoad(function() { |
| 81 | |
| 82 | doh.register("parse", function() { |
| 83 | dojo.parser.parse(); |
| 84 | }); |
| 85 | |
| 86 | // should be able to verify all of the inputs |
| 87 | doh.register("check initial values and bindings", [{ |
| 88 | name : "initial", |
| 89 | runTest : function() { |
| 90 | doh.is("Anne1", dijit.byId("nameInput0").get('value'),"nameInput0 should be Anne1"); |
| 91 | doh.is("Ben1", dijit.byId("nameInput1").get('value'),"nameInput1 should be Ben1 "); |
| 92 | doh.is("Chad1", dijit.byId("nameInput2").get('value'),"nameInput2 should be Chad1"); |
| 93 | |
| 94 | doh.is("Anne1", dijit.byId("firstnameOutput10").get('value'),"firstnameOutput10 should be Anne1"); |
| 95 | doh.is("Ben1", dijit.byId("firstnameOutput11").get('value'),"firstnameOutput11 should be Ben1 "); |
| 96 | doh.is("Chad1", dijit.byId("firstnameOutput12").get('value'),"firstnameOutput12 should be Chad1"); |
| 97 | |
| 98 | doh.is("Anne2", dijit.byId("firstnameOutput20").get('value'),"firstnameOutput20 should be Anne2"); |
| 99 | doh.is("Ben2", dijit.byId("firstnameOutput21").get('value'),"firstnameOutput21 should be Ben2 "); |
| 100 | |
| 101 | doh.is("", dijit.byId("firstnameOutput30").get('value'),"firstnameOutput30 should be blank"); |
| 102 | } |
| 103 | }]); |
| 104 | |
| 105 | doh.register("SelectModel2", [{ |
| 106 | name : "SelectModel2", |
| 107 | runTest : function() { |
| 108 | //doh.robot.mouseMoveAt("dijit_form_Button_1", 500, 0); |
| 109 | //doh.robot.mouseClick({left:true}, 500); |
| 110 | dijit.byId('outergroupId').set('ref',model2); |
| 111 | |
| 112 | doh.is("Anne2", dijit.byId("nameInput0").get('value'),"nameInput0 should be Anne2"); |
| 113 | doh.is("Ben2", dijit.byId("nameInput1").get('value'),"nameInput1 should be Ben2 "); |
| 114 | } |
| 115 | }]); |
| 116 | |
| 117 | doh.register("ChangeModel2", [{ |
| 118 | name : "ChangeModel2", |
| 119 | runTest : function() { |
| 120 | dijit.byId('nameInput0').set('value',"Anne2-Update"); |
| 121 | |
| 122 | doh.is("Anne2-Update", dijit.byId("nameInput0").get('value'),"nameInput0 should be Anne2-Update"); |
| 123 | doh.is("Ben2", dijit.byId("nameInput1").get('value'),"nameInput1 should be Ben2 "); |
| 124 | |
| 125 | doh.is("Anne2-Update", dijit.byId("firstnameOutput20").get('value'),"firstnameOutput20 should be Anne2-Update"); |
| 126 | doh.is("Ben2", dijit.byId("firstnameOutput21").get('value'),"firstnameOutput21 should be Ben2 "); |
| 127 | } |
| 128 | }]); |
| 129 | |
| 130 | doh.register("SelectModel3", [{ |
| 131 | name : "SelectModel3", |
| 132 | runTest : function() { |
| 133 | dijit.byId('outergroupId').set('ref',model3); |
| 134 | |
| 135 | doh.is("", dijit.byId("nameInput0").get('value'),"nameInput0 should be blank"); |
| 136 | } |
| 137 | }]); |
| 138 | |
| 139 | doh.register("ChangeModel3", [{ |
| 140 | name : "ChangeModel3", |
| 141 | runTest : function() { |
| 142 | dijit.byId('nameInput0').set('value',"Anne3-Update"); |
| 143 | |
| 144 | doh.is("Anne3-Update", dijit.byId("nameInput0").get('value'),"nameInput0 should be Anne3-Update"); |
| 145 | |
| 146 | doh.is("Anne3-Update", dijit.byId("firstnameOutput30").get('value'),"firstnameOutput30 should be Anne3-Update"); |
| 147 | } |
| 148 | }]); |
| 149 | |
| 150 | doh.register("ResetAll", [{ |
| 151 | name : "ResetAll", |
| 152 | runTest : function() { |
| 153 | dijit.byId('outergroupId').set('ref',model1); |
| 154 | model1.reset(); |
| 155 | model2.reset(); |
| 156 | model3.reset(); |
| 157 | |
| 158 | doh.is("Anne1", dijit.byId("nameInput0").get('value'),"nameInput0 should be Anne1"); |
| 159 | doh.is("Ben1", dijit.byId("nameInput1").get('value'),"nameInput1 should be Ben1 "); |
| 160 | doh.is("Chad1", dijit.byId("nameInput2").get('value'),"nameInput2 should be Chad1"); |
| 161 | |
| 162 | doh.is("Anne1", dijit.byId("firstnameOutput10").get('value'),"firstnameOutput10 should be Anne1"); |
| 163 | doh.is("Ben1", dijit.byId("firstnameOutput11").get('value'),"firstnameOutput11 should be Ben1 "); |
| 164 | doh.is("Chad1", dijit.byId("firstnameOutput12").get('value'),"firstnameOutput12 should be Chad1"); |
| 165 | |
| 166 | doh.is("Anne2", dijit.byId("firstnameOutput20").get('value'),"firstnameOutput20 should be Anne2"); |
| 167 | doh.is("Ben2", dijit.byId("firstnameOutput21").get('value'),"firstnameOutput21 should be Ben2 "); |
| 168 | |
| 169 | doh.is("", dijit.byId("firstnameOutput30").get('value'),"firstnameOutput30 should be blank"); |
| 170 | } |
| 171 | }]); |
| 172 | |
| 173 | doh.run(); |
| 174 | |
| 175 | }); |
| 176 | </script> |
| 177 | </head> |
| 178 | |
| 179 | |
| 180 | <body class="claro"> |
| 181 | <div id="wrapper"> |
| 182 | <div id="header"> |
| 183 | <div id="navigation"></div> |
| 184 | <div id="headerInsert"> |
| 185 | <h1>Input Output Sync</h1> |
| 186 | <h2>Data Binding Example</h2> |
| 187 | </div> |
| 188 | </div> |
| 189 | <div id="main"> |
| 190 | <div id="leftNav"></div> |
| 191 | <div id="mainContent"> |
| 192 | <div class="row"> |
| 193 | <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){dijit.byId('outergroupId').set('ref',model1);}">Swap Model1</button> |
| 194 | <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){dijit.byId('outergroupId').set('ref',model2);}">Swap Model2</button> |
| 195 | <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){dijit.byId('outergroupId').set('ref',model3);}">Swap Model3</button> |
| 196 | </div> |
| 197 | <div id="outergroupId" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'model1'"> |
| 198 | <div id="innergroupId" data-dojo-type="dojox.mvc.Group"> |
| 199 | <div id="repeatId" data-dojo-type="dojox.mvc.Repeat" data-dojo-props="ref: 'Results'"> |
| 200 | <div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: '${this.index}'"> |
| 201 | <label class="cell" for="nameInput${this.index}">Name:</label> |
| 202 | <input class="cell" data-dojo-type="dijit.form.TextBox" id="nameInput${this.index}" data-dojo-props="ref: 'First'"/> |
| 203 | </div> |
| 204 | </div> |
| 205 | </div> |
| 206 | </div> |
| 207 | <div class="row"> |
| 208 | <span> |
| 209 | Model1 Output is ==> |
| 210 | </span> |
| 211 | <span id="firstnameOutput10" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model1.Results[0].First"> |
| 212 | Name1 is "${this.value}" : |
| 213 | </span> |
| 214 | <span id="firstnameOutput11" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model1.Results[1].First"> |
| 215 | Name2 is "${this.value}" : |
| 216 | </span> |
| 217 | <span id="firstnameOutput12" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model1.Results[2].First"> |
| 218 | Name3 is "${this.value}" |
| 219 | </span> |
| 220 | </div> |
| 221 | <div class="row"> |
| 222 | <span> |
| 223 | Model2 Output is ==> |
| 224 | </span> |
| 225 | <span id="firstnameOutput20" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model2.Results[0].First"> |
| 226 | Name1 is "${this.value}" : |
| 227 | </span> |
| 228 | <span id="firstnameOutput21" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model2.Results[1].First"> |
| 229 | Name2 is "${this.value}" |
| 230 | </span> |
| 231 | </div> |
| 232 | <div class="row"> |
| 233 | <span> |
| 234 | Model3 Output is ==> |
| 235 | </span> |
| 236 | <span id="firstnameOutput30" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model3.Results[0].First"> |
| 237 | Name1 is "${this.value}" |
| 238 | </span> |
| 239 | </div> |
| 240 | <br/>Model: |
| 241 | <button id="reset" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){model1.reset();model2.reset();model3.reset();}">Reset all</button> |
| 242 | </div> |
| 243 | </div> |
| 244 | </div> |
| 245 | </body> |
| 246 | |
| 247 | </html> |