| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>DOH MVC Mobile Demo Test</title> |
| 6 | <link rel="stylesheet" type="text/css" href="../1.7/mobile/demo/demo.css"/> |
| 7 | <style> |
| 8 | html, body{ |
| 9 | height: 100%; |
| 10 | overflow: hidden; |
| 11 | position: relative; |
| 12 | } |
| 13 | .mblEdgeToEdgeList { |
| 14 | background-color: #DBDDE2; |
| 15 | } |
| 16 | </style> |
| 17 | <script type="text/javascript" data-dojo-config="parseOnLoad:0,isDebug:1,async:1, mvc: {debugBindings: 1}" src="../../../../dojo/dojo.js"></script> |
| 18 | <script type="text/javascript"> |
| 19 | var ctrl, listCtrl; |
| 20 | var updateView, updateModel; |
| 21 | |
| 22 | require([ |
| 23 | "doh/runner", |
| 24 | "dojo/_base/declare", |
| 25 | "dojo/_base/json", |
| 26 | "dojo/when", |
| 27 | "dojo/dom", |
| 28 | "dojo/store/JsonRest", |
| 29 | "dojo/store/Memory", |
| 30 | "dijit/registry", |
| 31 | "dojox/mobile/parser", |
| 32 | "dojox/mvc/getPlainValue", |
| 33 | "dojox/mvc/getStateful", |
| 34 | "dojox/mvc/EditModelRefController", |
| 35 | "dojox/mvc/ListController", |
| 36 | "dojox/mvc/StoreRefController", |
| 37 | "dojox/mvc/at", |
| 38 | "dojox/mobile", |
| 39 | "dojox/mobile/compat", |
| 40 | "dojox/mobile/ScrollableView", |
| 41 | "dojox/mobile/Button", |
| 42 | "dojox/mobile/TextArea", |
| 43 | "dojox/mobile/TextBox", |
| 44 | "dojox/mobile/ViewController", |
| 45 | "dojox/mobile/FixedSplitter", |
| 46 | "dojox/mobile/EdgeToEdgeList", |
| 47 | "dojox/mobile/EdgeToEdgeCategory", |
| 48 | "dojox/mobile/deviceTheme", |
| 49 | "dojox/mobile/RoundRectCategory", |
| 50 | "dojox/mobile/Heading", |
| 51 | "dojox/mvc/Group", |
| 52 | "dojox/mvc/Generate", |
| 53 | "dojox/mvc/Repeat", |
| 54 | "dojo/domReady!" |
| 55 | ], function(doh, declare, djson, when, ddom, JsonRest, Memory, registry, parser, getPlainValue, getStateful, EditModelRefController, ListController, StoreRefController, at){ |
| 56 | window.at = at; |
| 57 | |
| 58 | ctrlClass = declare([EditModelRefController, ListController], {}); |
| 59 | ctrl = new ctrlClass({sourceModel: getStateful({ |
| 60 | Serial: "360324", |
| 61 | First: "John", |
| 62 | Last: "Doe", |
| 63 | Email: "[email protected]", |
| 64 | ShipTo: { |
| 65 | Street: "123 Valley Rd", |
| 66 | City: "Katonah", |
| 67 | State: "NY", |
| 68 | Zip: "10536" |
| 69 | }, |
| 70 | BillTo: { |
| 71 | Street: "17 Skyline Dr", |
| 72 | City: "Hawthorne", |
| 73 | State: "NY", |
| 74 | Zip: "10532" |
| 75 | } |
| 76 | })}); |
| 77 | ctrl.set("cursorIndex", "ShipTo"); |
| 78 | |
| 79 | // used in the Generate View demo |
| 80 | var genmodel; |
| 81 | updateView = function() { |
| 82 | try { |
| 83 | genmodel = getStateful(djson.fromJson(ddom.byId("modelArea").value)); |
| 84 | registry.byId("view").set("children", genmodel); |
| 85 | ddom.byId("outerModelArea").style.display = "none"; |
| 86 | ddom.byId("viewArea").style.display = ""; |
| 87 | }catch(err){ |
| 88 | console.error("Error parsing json from model: "+err); |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | // used in the Generate View demo |
| 93 | updateModel = function() { |
| 94 | ddom.byId("outerModelArea").style.display = ""; |
| 95 | try { |
| 96 | ddom.byId("modelArea").focus(); // hack: do this to force focus off of the textbox, bug on mobile? |
| 97 | ddom.byId("viewArea").style.display = "none"; |
| 98 | registry.byId("modelArea").set("value", djson.toJson(getPlainValue(genmodel), true)); |
| 99 | } catch(e) { |
| 100 | console.log(e); |
| 101 | }; |
| 102 | }; |
| 103 | |
| 104 | var listCtrlClass = declare([StoreRefController, EditModelRefController, ListController], { |
| 105 | addEmpty: function(){ |
| 106 | var modelToInsert = getStateful({ |
| 107 | First: "", |
| 108 | Last: "", |
| 109 | Location: "CA", |
| 110 | Office: "", |
| 111 | Email: "", |
| 112 | Tel: "", |
| 113 | Fax: "" |
| 114 | }); |
| 115 | this.model.push(modelToInsert); |
| 116 | this.set("cursor", modelToInsert); |
| 117 | } |
| 118 | }); |
| 119 | |
| 120 | listCtrl = new listCtrlClass({cursorIndex: 0}); |
| 121 | |
| 122 | parser.parse(); |
| 123 | ddom.byId("wholepage").style.display = ""; |
| 124 | |
| 125 | when((new JsonRest({target: require.toUrl("dojox/mvc/tests/_data/mvcRepeatData.json")})).query({}), function(results){ |
| 126 | listCtrl.set("store", new Memory({data: results.items})); |
| 127 | when(listCtrl.queryStore({Location: "CA"}), function(results){ |
| 128 | doh.register("Ship to - Bill to Address page", [{ |
| 129 | name: "Initial", |
| 130 | runTest: function(){ |
| 131 | registry.byId("settings").show(); |
| 132 | doh.is("360324", registry.byId("serialInput").get("value"), "Order# should be set"); |
| 133 | doh.is("123 Valley Rd", registry.byId("streetInput").get("value"), "Street should be set of Ship To"); |
| 134 | } |
| 135 | }, { |
| 136 | name: "TestBillTo", |
| 137 | runTest : function(){ |
| 138 | ctrl.set("cursorIndex", "BillTo"); |
| 139 | doh.is("17 Skyline Dr", registry.byId("streetInput").get("value"), "Street should be set of Bill To"); |
| 140 | } |
| 141 | }, { |
| 142 | name: "TestReset", |
| 143 | runTest: function(){ |
| 144 | var addr1 = registry.byId("streetInput"); |
| 145 | addr1.set("value", "Foo"); |
| 146 | doh.is("Foo", ctrl.get("Street"), "Street should be Foo"); |
| 147 | ctrl.reset(); |
| 148 | doh.is("17 Skyline Dr", addr1.get("value"), "Street should be set back to of Bill To"); |
| 149 | } |
| 150 | }]); |
| 151 | |
| 152 | doh.register("Repeat Data Binding Example page", [{ |
| 153 | name: "Initial", |
| 154 | runTest: function(){ |
| 155 | registry.byId("repeat").show(); |
| 156 | doh.is("Chad", registry.byId("nameInput0").get("value"), "nameInput0 should be Chad"); |
| 157 | doh.is("Hunter", registry.byId("nameInput1").get("value"), "nameInput1 should be Hunter"); |
| 158 | doh.is("John", registry.byId("nameInput2").get("value"), "nameInput2 should be John"); |
| 159 | } |
| 160 | }, { |
| 161 | name: "ChangeCursor", |
| 162 | runTest: function(){ |
| 163 | listCtrl.set("cursorIndex", 1); |
| 164 | doh.is("Hunter", registry.byId("firstnameInputDetail").get("value"), "firstnameInputDetail should be Hunter"); |
| 165 | } |
| 166 | }, { |
| 167 | name : "ResetAll", |
| 168 | runTest : function(){ |
| 169 | var first = registry.byId("firstnameInputDetail"); |
| 170 | first.set("value", "Foo"); |
| 171 | doh.is("Foo", listCtrl.get("First"), "First should be Foo"); |
| 172 | listCtrl.reset(); |
| 173 | doh.is("Hunter", registry.byId("firstnameInputDetail").get("value"), "firstnameInputDetail should be Hunter"); |
| 174 | } |
| 175 | }]); |
| 176 | |
| 177 | doh.register("Simple Form Generate Example page", [{ |
| 178 | name: "Initial", |
| 179 | runTest: function(){ |
| 180 | registry.byId("generate").show(); |
| 181 | updateView(); |
| 182 | var tb0 = registry.byId("TB0"); |
| 183 | doh.is("11111", tb0 && tb0.get("value"), "Serial should be 11111"); |
| 184 | var tb6 = registry.byId("TB6"); |
| 185 | doh.is("111-111-1111", tb6 && tb6.get("value"), "Office should be 111-111-1111"); |
| 186 | tb6.set("value", "333-333-3333"); |
| 187 | updateModel(); |
| 188 | doh.t(ddom.byId("modelArea").value.indexOf("\"Office\": \"333-333-3333\""), "Model should be updated with newer Office phone number"); |
| 189 | } |
| 190 | }]); |
| 191 | |
| 192 | doh.run(); |
| 193 | }); |
| 194 | }); |
| 195 | }); // end function |
| 196 | </script> |
| 197 | </head> |
| 198 | <body> |
| 199 | <div id="wholepage" style="display:none"> |
| 200 | <div id="foo" data-dojo-type="dojox.mobile.View" selected="true"> |
| 201 | <h1 data-dojo-type="dojox.mobile.Heading">Mobile MVC Demo</h1> |
| 202 | <h2 data-dojo-type="dojox.mobile.RoundRectCategory">Mobile MVC Views</h2> |
| 203 | <ul data-dojo-type="dojox.mobile.RoundRectList"> |
| 204 | <li id="sdb" data-dojo-type="dojox.mobile.ListItem" icon="../1.7/mobile/demo/images/i-icon-1.png" transition="slide" moveTo="settings"> |
| 205 | Simple Data Binding |
| 206 | </li> |
| 207 | <li id="rdb" data-dojo-type="dojox.mobile.ListItem" icon="../1.7/mobile/demo/images/i-icon-2.png" transition="slide" moveTo="repeat"> |
| 208 | Repeat Data Binding |
| 209 | </li> |
| 210 | <li id="sfg" data-dojo-type="dojox.mobile.ListItem" icon="../1.7/mobile/demo/images/i-icon-3.png" transition="slide" moveTo="generate"> |
| 211 | Simple Form Generate |
| 212 | </li> |
| 213 | </ul> |
| 214 | </div> |
| 215 | <div id="settings" data-dojo-type="dojox.mobile.ScrollableView"> |
| 216 | <h1 id="home" data-dojo-type="dojox.mobile.Heading" back="Home" moveTo="foo">Data Binding Example</h1> |
| 217 | <form name="testForm" id="testForm"> |
| 218 | <div class="field-title">Ship to - Bill to Address</div> |
| 219 | <div class="fieldset" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at(ctrl, 'model')"> |
| 220 | <div class="field-row"> |
| 221 | <span>Order #</span> |
| 222 | <input id="serialInput" placeholder="Order #" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'Serial')" /> |
| 223 | </div> |
| 224 | <div class="field-row"> |
| 225 | <span>Last</span> |
| 226 | <input placeholder="Last" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'Last')" /> |
| 227 | </div> |
| 228 | <div class="field-row"> |
| 229 | <span>Email</span> |
| 230 | <input placeholder="Last" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'Email')" /> |
| 231 | </div> |
| 232 | </div> |
| 233 | <div class="spacer"></div> |
| 234 | <button id="shipto" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" onclick="ctrl.set('cursorIndex', 'ShipTo');">Ship To</button> |
| 235 | <button id="billto" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" onclick="ctrl.set('cursorIndex', 'BillTo');">Bill To</button> |
| 236 | <br/> |
| 237 | <div class="fieldset" id="addrGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at(ctrl, 'cursor')"> |
| 238 | <div class="field-row"> |
| 239 | <span>Street</span> |
| 240 | <input id="streetInput" placeholder="Street" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'Street')" /> |
| 241 | </div> |
| 242 | <div class="field-row"> |
| 243 | <span>City</span> |
| 244 | <input placeholder="City" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'City')" /> |
| 245 | </div> |
| 246 | <div class="field-row"> |
| 247 | <span>State</span> |
| 248 | <input placeholder="State" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'State')" /> |
| 249 | </div> |
| 250 | <div class="field-row"> |
| 251 | <span>ZIP Code</span> |
| 252 | <input placeholder="ZIP Code" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'Zip')" /> |
| 253 | </div> |
| 254 | </div> |
| 255 | <div class="spacer"></div> |
| 256 | <button id="reset1" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" onclick="ctrl.reset()">Reset</button> |
| 257 | </form> |
| 258 | </div> |
| 259 | <div id="repeat" data-dojo-type="dojox.mobile.ScrollableView"> |
| 260 | <h1 data-dojo-type="dojox.mobile.Heading" back="Home" moveTo="foo">Repeat Data Binding Example</h1> |
| 261 | <form name="repeatTestForm" id="repeatTestForm"> |
| 262 | <div class="field-title">Search Results</div> |
| 263 | <div class="fieldset" class="row" data-dojo-type="dojox.mvc.Repeat" data-dojo-props="children: at(listCtrl, 'model')"> |
| 264 | <div data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at('rel:', '${this.index}')"> |
| 265 | <div class="row"> |
| 266 | <input id="nameInput${this.index}" placeHolder="First Name" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'First')" /> |
| 267 | <button id="details${this.index}" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" onclick="listCtrl.set('cursorIndex', '${this.index}')">Details</button> |
| 268 | </div> |
| 269 | </div> |
| 270 | </div> |
| 271 | <div class="spacer"></div> |
| 272 | <div id="detailsBanner">Details for selected index:</div> |
| 273 | <div class="fieldset" id="detailsGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at(listCtrl, 'cursor')"> |
| 274 | <div class="field-row"> |
| 275 | <span>First Name</span> |
| 276 | <input id="firstnameInputDetail" placeholder="First Name" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'First')" /> |
| 277 | </div> |
| 278 | <div class="field-row"> |
| 279 | <span>Last Name</span> |
| 280 | <input placeholder="Last Name" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'Last') "/> |
| 281 | </div> |
| 282 | <div class="field-row"> |
| 283 | <span>Email</span> |
| 284 | <input placeholder="Email" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'Email')" /> |
| 285 | </div> |
| 286 | <div class="field-row"> |
| 287 | <span>Telephone</span> |
| 288 | <input placeholder="Telephone" data-dojo-type="dojox.mobile.TextBox" data-dojo-props="value: at('rel:', 'Tel')" /> |
| 289 | </div> |
| 290 | </div> |
| 291 | <div class="spacer"></div> |
| 292 | <button id="add" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" onclick="listCtrl.addEmpty();">Add</button> |
| 293 | <button id="save" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" onclick="listCtrl.commit();">Save</button> |
| 294 | <button id="reset2" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" onclick="listCtrl.reset();">Reset</button> |
| 295 | </form> |
| 296 | </div> |
| 297 | <div id="generate" data-dojo-type="dojox.mobile.ScrollableView"> |
| 298 | <h1 data-dojo-type="dojox.mobile.Heading" back="Home" moveTo="foo">Simple Form Generate Example</h1> |
| 299 | <div class="field-title"></div> |
| 300 | <div id="main"> |
| 301 | <div id="leftNav"></div> |
| 302 | <div id="mainContent" class="generate-maincontent"> |
| 303 | <div id="outerModelArea"> |
| 304 | <h3 data-dojo-type="dojox.mobile.RoundRectCategory">Model</h3> |
| 305 | <div class="generate-textarea-row"> |
| 306 | <textarea class="generate-textarea-cell" data-dojo-type="dojox.mobile.TextArea" id="modelArea"> |
| 307 | { |
| 308 | "Serial": "11111", |
| 309 | "First": "John", |
| 310 | "Last": "Doe", |
| 311 | "Email": "[email protected]", |
| 312 | "Phones": [ |
| 313 | { |
| 314 | "Office": "111-111-1111" |
| 315 | }, |
| 316 | { |
| 317 | "Mobile": "222-222-2222" |
| 318 | } |
| 319 | ] |
| 320 | } |
| 321 | </textarea> |
| 322 | </div> |
| 323 | <div class="fieldset"> |
| 324 | <div class="spacer"></div> |
| 325 | <button id="generate1" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" onclick="updateView()">Generate Form</button> |
| 326 | </div> |
| 327 | </div> |
| 328 | <div id="viewArea" style="display:none"> |
| 329 | <h3 data-dojo-type="dojox.mobile.RoundRectCategory">Generated View</h3> |
| 330 | <div class="fieldset"> |
| 331 | <div id="view" data-dojo-type="dojox.mvc.Generate" data-dojo-props="widgetMapping: {'String': 'dojox.mobile.TextBox'}, idNameMapping: {'String' : 'TB'}"></div> |
| 332 | </div> |
| 333 | <div class="fieldset"> |
| 334 | <div class="spacer"></div> |
| 335 | <button id="updateModel" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" onclick="updateModel()">Update Model</button> |
| 336 | </div> |
| 337 | </div> |
| 338 | </div> |
| 339 | </div> |
| 340 | </div> |
| 341 | </div> |
| 342 | </div> |
| 343 | </body> |
| 344 | </html> |