| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>Step 4 of test for Controllers, uses a StoreRefController.</title> |
| 6 | <style type="text/css"> |
| 7 | @import "../css/app-format.css"; |
| 8 | @import "../../../../dijit/themes/claro/claro.css"; |
| 9 | </style> |
| 10 | <script type="text/javascript" data-dojo-config="parseOnLoad:0,isDebug:1,async:1,mvc:{debugBindings:1}" src="../../../../dojo/dojo.js"></script> |
| 11 | <script type="text/javascript"> |
| 12 | var ctrl; |
| 13 | |
| 14 | require([ |
| 15 | 'dojo/parser', |
| 16 | 'dojo/ready', |
| 17 | 'dojo/when', |
| 18 | 'dojo/store/Memory', |
| 19 | 'dojox/mvc/getStateful', |
| 20 | 'dojox/mvc/StoreRefController', |
| 21 | 'dojox/mvc/parserExtension', |
| 22 | 'dijit/form/TextBox', |
| 23 | 'dijit/form/Button', |
| 24 | 'dojox/mvc/Group', |
| 25 | 'dojox/mvc/Output' |
| 26 | ], function(parser, ready, when, Memory, getStateful, StoreRefController){ |
| 27 | |
| 28 | // Initial data |
| 29 | var storeData = { |
| 30 | "identifier": "id", |
| 31 | "items": [ |
| 32 | { |
| 33 | "id" : "360324", |
| 34 | "FullName" : "Mr. John Doe", |
| 35 | "Email" : "[email protected]", |
| 36 | "AddressLine1" : "123 Valley Rd.", |
| 37 | "AddressLine2" : "", |
| 38 | "City" : "Cary", |
| 39 | "State" : "NC", |
| 40 | "Zip" : "27513" |
| 41 | } |
| 42 | ] |
| 43 | }; |
| 44 | |
| 45 | // To move from ModelRefController to use StoreRefController, need to require StoreRefController, Memory, and when |
| 46 | // also needed to change the data to be valid for a store query. |
| 47 | // Setup StoreRefController and use ctrl.queryStore() to setup the models. |
| 48 | // |
| 49 | // Because of the queryStore call had to move the call to parser.parse inside the when to wait for it. |
| 50 | // The change in the data for queryStore required changes to the bindings. had to add a group with target: at('rel:','0') |
| 51 | // for the bindings of fields. |
| 52 | // |
| 53 | // An exprchar:'%' was used for an mvc/Output just to show how it is used. |
| 54 | // |
| 55 | |
| 56 | transformAddress2Class = { |
| 57 | format: function(value){ |
| 58 | if(value && value.trim().length > 0){ |
| 59 | return "row" // if AddressLine2 is set return row for class |
| 60 | } |
| 61 | return "hiderow"; // if AddressLine2 is not set return hiderow for class |
| 62 | } |
| 63 | |
| 64 | }; |
| 65 | |
| 66 | ctrl = new StoreRefController({store: new Memory({data:storeData})}); |
| 67 | when(ctrl.queryStore(), function(){ |
| 68 | parser.parse(); |
| 69 | }); |
| 70 | |
| 71 | }); |
| 72 | </script> |
| 73 | </head> |
| 74 | <body class="claro"> |
| 75 | <script type="dojo/require">at: "dojox/mvc/at"</script> |
| 76 | <div id="wrapper"> |
| 77 | <div id="main"> |
| 78 | <div> |
| 79 | <h2>Step 4 of test for Controllers, uses a StoreRefController.</h2> |
| 80 | <h2>Enter Shipping Address</h2> |
| 81 | </div> |
| 82 | <div class="fullrow" data-dojo-type="dojox/mvc/Group" data-dojo-props="target: at(ctrl,'model')"> |
| 83 | <div class="fullrow" data-dojo-type="dojox/mvc/Group" data-dojo-props="target: at('rel:','0')"> |
| 84 | <div class="fullrow"> |
| 85 | <label class="cell" for="nameInput">Full Name:</label> |
| 86 | <input class="cell" id="nameInput" data-dojo-type="dijit/form/TextBox" |
| 87 | data-dojo-props="value: at('rel:', 'FullName')"> |
| 88 | </div> |
| 89 | <div class="fullrow"> |
| 90 | <label class="cell" for="AddressLine1Input">Address Line1:</label> |
| 91 | <input class="cell" id="AddressLine1Input" data-dojo-type="dijit/form/TextBox" |
| 92 | data-dojo-props="value: at('rel:', 'AddressLine1')"> |
| 93 | </div> |
| 94 | <div class="fullrow"> |
| 95 | <label class="cell" for="AddressLine2Input">Address Line2:</label> |
| 96 | <input class="cell" id="AddressLine2Input" data-dojo-type="dijit/form/TextBox" |
| 97 | data-dojo-props="value: at('rel:', 'AddressLine2')"> |
| 98 | </div> |
| 99 | <div class="fullrow"> |
| 100 | <label class="cell" for="cityInput">City:</label> |
| 101 | <input class="cell" id="cityInput" data-dojo-type="dijit/form/TextBox" |
| 102 | data-dojo-props="value: at('rel:', 'City')"> |
| 103 | </div> |
| 104 | <div class="fullrow"> |
| 105 | <label class="cell" for="stateInput">State:</label> |
| 106 | <input class="cell" id="stateInput" data-dojo-type="dijit/form/TextBox" |
| 107 | data-dojo-props="value: at('rel:', 'State')"> |
| 108 | </div> |
| 109 | <div class="fullrow"> |
| 110 | <label class="cell" for="zipInput">Zipcode:</label> |
| 111 | <input class="cell" id="zipInput" data-dojo-type="dijit/form/TextBox" |
| 112 | data-dojo-props="value: at('rel:', 'Zip')"> |
| 113 | </div> |
| 114 | </div> |
| 115 | </div> |
| 116 | |
| 117 | <br/> |
| 118 | <div> |
| 119 | <h2>Verify the shipping address</h2> |
| 120 | </div> |
| 121 | <div class="fullrow" data-dojo-type="dojox/mvc/Group" data-dojo-props="target: at(ctrl,'model')"> |
| 122 | <div class="fullrow" data-dojo-type="dojox/mvc/Group" data-dojo-props="target: at('rel:','0')"> |
| 123 | <div class="fullrow"> |
| 124 | <div class="boldnamecell" id="nameOutput" data-dojo-type="dojox/mvc/Output" |
| 125 | data-dojo-props="value: at('rel:', 'FullName')"></div> |
| 126 | </div> |
| 127 | <div class="fullrow"> |
| 128 | <div class="namecell" data-dojo-type="dojox/mvc/Output" |
| 129 | data-dojo-props="value: at('rel:', 'AddressLine1')"></div> |
| 130 | </div> |
| 131 | <div class="hiderow" data-mvc-bindings="class: at('rel:', 'AddressLine2').direction(at.from).transform(transformAddress2Class)"> |
| 132 | <div class="namecell" data-dojo-type="dojox/mvc/Output" |
| 133 | data-dojo-props="value: at('rel:', 'AddressLine2')"></div> |
| 134 | </div> |
| 135 | <div class="fullrow"> |
| 136 | <div class="namecell" data-dojo-type="dojox/mvc/Output" |
| 137 | data-dojo-props="exprchar:'%', value: at('rel:', 'City')">%{this.value},</div> |
| 138 | <div class="namecell" data-dojo-type="dojox/mvc/Output" |
| 139 | data-dojo-props="value: at('rel:', 'State')"></div> |
| 140 | <div class="namecell" data-dojo-type="dojox/mvc/Output" |
| 141 | data-dojo-props="value: at('rel:', 'Zip')"></div> |
| 142 | </div> |
| 143 | </div> |
| 144 | </div> |
| 145 | </div> |
| 146 | </div> |
| 147 | </body> |
| 148 | </html> |