| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>Step 8 of test for Controllers, uses an EditStoreRefListController.</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/_base/declare', |
| 17 | 'dojo/ready', |
| 18 | 'dojo/when', |
| 19 | 'dojo/store/Memory', |
| 20 | 'dojox/mvc/getStateful', |
| 21 | 'dojox/mvc/EditStoreRefListController', |
| 22 | 'dojox/mvc/parserExtension', |
| 23 | 'dijit/form/TextBox', |
| 24 | 'dijit/form/Button', |
| 25 | 'dijit/form/RadioButton', |
| 26 | 'dojox/mvc/Group', |
| 27 | 'dojox/mvc/WidgetList', |
| 28 | 'dojox/mvc/_InlineTemplateMixin', |
| 29 | 'dojox/mvc/Output' |
| 30 | ], function(parser, declare, ready, when, Memory, getStateful, EditStoreRefListController){ |
| 31 | // Initial data |
| 32 | var storeData = { |
| 33 | "identifier": "id", |
| 34 | "items": [ |
| 35 | { |
| 36 | "id" : "360324", |
| 37 | "AddressName" : "Home", |
| 38 | "Checked" : true, |
| 39 | "FullName" : "Mr. John Doe", |
| 40 | "Email" : "[email protected]", |
| 41 | "AddressLine1" : "123 Valley Rd.", |
| 42 | "AddressLine2" : "", |
| 43 | "City" : "Cary", |
| 44 | "State" : "NC", |
| 45 | "Zip" : "27513" |
| 46 | }, |
| 47 | { |
| 48 | "id" : "360325", |
| 49 | "AddressName" : "Work", |
| 50 | "Checked" : false, |
| 51 | "FullName" : "Mr. John Doe", |
| 52 | "Email" : "[email protected]", |
| 53 | "AddressLine1" : "4567 S Miami Blvd", |
| 54 | "AddressLine2" : "Bldg:502, Office:M120", |
| 55 | "City" : "Durham", |
| 56 | "State" : "NC", |
| 57 | "Zip" : "27703" |
| 58 | } |
| 59 | ] |
| 60 | }; |
| 61 | |
| 62 | |
| 63 | // To move from ModelRefController with EditModelRefController and a ListController to a EditStoreRefListController |
| 64 | // Need to require the EditStoreRefListController, when, and Memory |
| 65 | // I also needed to change the data to be valid for a store query. |
| 66 | // Needed to setup ctrlclz with EditStoreRefListController, and use when and ctrl.queryStore() to setup the models. |
| 67 | // |
| 68 | // This test uses holdModelUntilCommit: false on the WidgetList, so updates to the address will immediately show-up in |
| 69 | // the verify section and in the select an address section, but changes can be "Reset" back to their last saved state. |
| 70 | // |
| 71 | |
| 72 | var ctrlclz = declare([EditStoreRefListController], { |
| 73 | |
| 74 | transformRadioChecked : { |
| 75 | format: function(checked){ |
| 76 | if(checked){ |
| 77 | ctrl.set('cursorIndex', this.target.index); |
| 78 | console.log("in transformRadioChecked setting cursorIndex to "+this.target.index); |
| 79 | } |
| 80 | return checked; |
| 81 | }, |
| 82 | parse: function(checked){ |
| 83 | return checked; |
| 84 | } |
| 85 | }, |
| 86 | |
| 87 | transformAddress2Class : { |
| 88 | format: function(value){ |
| 89 | if(value && value.trim().length > 0){ |
| 90 | return "row" // if AddressLine2 is set return row for class |
| 91 | } |
| 92 | return "hiderow"; // if AddressLine2 is not set return hiderow for class |
| 93 | } |
| 94 | }, |
| 95 | |
| 96 | addEmpty : function(empty){ |
| 97 | var idx = this.model.length; |
| 98 | var data = { |
| 99 | "id" : Math.random(), |
| 100 | "AddressName" : "New Address", |
| 101 | "Checked" : true, |
| 102 | "FullName" : "", |
| 103 | "Email" : "", |
| 104 | "AddressLine1" : "", |
| 105 | "AddressLine2" : "", |
| 106 | "City" : "", |
| 107 | "State" : "", |
| 108 | "Zip" : "" |
| 109 | }; |
| 110 | if(!empty){ |
| 111 | data = { |
| 112 | "id" : Math.random(), |
| 113 | "AddressName" : "Copy of "+this.cursor.AddressName, |
| 114 | "Checked" : true, |
| 115 | "FullName" : "" || this.cursor.Name, |
| 116 | "Email" : this.cursor.Email, |
| 117 | "AddressLine1" : this.cursor.AddressLine1, |
| 118 | "AddressLine2" : this.cursor.AddressLine2, |
| 119 | "City" : this.cursor.City, |
| 120 | "State" : this.cursor.State, |
| 121 | "Zip" : this.cursor.Zip |
| 122 | }; |
| 123 | } |
| 124 | this.model.splice(idx, 0, getStateful(data)); |
| 125 | } |
| 126 | |
| 127 | }); |
| 128 | ctrl = new ctrlclz({store: new Memory({data:storeData}), holdModelUntilCommit: false}); |
| 129 | when(ctrl.queryStore(), function(){ |
| 130 | parser.parse(); |
| 131 | }); |
| 132 | }); |
| 133 | </script> |
| 134 | </head> |
| 135 | <body class="claro"> |
| 136 | <script type="dojo/require">at: "dojox/mvc/at"</script> |
| 137 | <div id="wrapper"> |
| 138 | <div id="main"> |
| 139 | <div> |
| 140 | <h2>Step 8 of test for Controllers, uses an EditStoreRefListController with holdModelUntilCommit: false</h2> |
| 141 | <h2>Select the Shipping Address to use.</h2> |
| 142 | </div> |
| 143 | |
| 144 | <div data-dojo-type="dojox/mvc/WidgetList" |
| 145 | data-dojo-mixins="dojox/mvc/_InlineTemplateMixin" |
| 146 | data-dojo-props="children: at(ctrl, 'model'), partialRebuild:true"> |
| 147 | <script type="dojox/mvc/InlineTemplate"> |
| 148 | <div> |
| 149 | <input type="radio" data-dojo-type="dijit/form/RadioButton" name="AddressName" id="radio${indexAtStartup}" |
| 150 | data-dojo-props="index: ${indexAtStartup}, |
| 151 | // value: at('rel:', 'AddressName'), // do not set value on the radio button or it will also set checked. |
| 152 | checked: at('rel:', 'Checked').transform(ctrl.transformRadioChecked)"/> |
| 153 | <label class="radioLabel" for="radio${indexAtStartup}" data-dojo-type="dojox/mvc/Output" |
| 154 | data-dojo-props="value: at('rel:', 'AddressName')"></label> <br /> |
| 155 | </div> |
| 156 | </script> |
| 157 | </div> |
| 158 | <div class="fullrow"> |
| 159 | <button class="buttoncell" id="add" type="button" data-dojo-type="dijit/form/Button" |
| 160 | data-dojo-props="onClick: function(){ ctrl.addEmpty(true); }">New Address</button> |
| 161 | <button class="buttoncell" id="addcopy" type="button" data-dojo-type="dijit/form/Button" |
| 162 | data-dojo-props="onClick: function(){ ctrl.addEmpty(false); }">New copy of selected.</button> |
| 163 | </div> |
| 164 | |
| 165 | <div class="spacer"></div> |
| 166 | <h2>Enter the Shipping Address</h2> |
| 167 | |
| 168 | <div class="fullrow" data-dojo-type="dojox/mvc/Group" data-dojo-props="target: at(ctrl,'cursor')"> |
| 169 | <div class="fullrow"> |
| 170 | <label class="cell" for="AddressNameInput">Address Name:</label> |
| 171 | <input class="cell" id="AddressNameInput" data-dojo-type="dijit/form/TextBox" |
| 172 | data-dojo-props="value: at('rel:', 'AddressName')"> |
| 173 | </div> |
| 174 | <br/> |
| 175 | <div class="fullrow"> |
| 176 | <label class="cell" for="nameInput">Full Name:</label> |
| 177 | <input class="cell" id="nameInput" data-dojo-type="dijit/form/TextBox" |
| 178 | data-dojo-props="value: at('rel:', 'FullName')"> |
| 179 | </div> |
| 180 | <div class="fullrow"> |
| 181 | <label class="cell" for="AddressLine1Input">Address Line1:</label> |
| 182 | <input class="cell" id="AddressLine1Input" data-dojo-type="dijit/form/TextBox" |
| 183 | data-dojo-props="value: at('rel:', 'AddressLine1')"> |
| 184 | </div> |
| 185 | <div class="fullrow"> |
| 186 | <label class="cell" for="AddressLine2Input">Address Line2:</label> |
| 187 | <input class="cell" id="AddressLine2Input" data-dojo-type="dijit/form/TextBox" |
| 188 | data-dojo-props="value: at('rel:', 'AddressLine2')"> |
| 189 | </div> |
| 190 | <div class="fullrow"> |
| 191 | <label class="cell" for="cityInput">City:</label> |
| 192 | <input class="cell" id="cityInput" data-dojo-type="dijit/form/TextBox" |
| 193 | data-dojo-props="value: at('rel:', 'City')"> |
| 194 | </div> |
| 195 | <div class="fullrow"> |
| 196 | <label class="cell" for="stateInput">State:</label> |
| 197 | <input class="cell" id="stateInput" data-dojo-type="dijit/form/TextBox" |
| 198 | data-dojo-props="value: at('rel:', 'State')"> |
| 199 | </div> |
| 200 | <div class="fullrow"> |
| 201 | <label class="cell" for="zipInput">Zipcode:</label> |
| 202 | <input class="cell" id="zipInput" data-dojo-type="dijit/form/TextBox" |
| 203 | data-dojo-props="value: at('rel:', 'Zip')"> |
| 204 | </div> |
| 205 | </div> |
| 206 | <br/> |
| 207 | |
| 208 | <div class="fullrow"> |
| 209 | <button class="buttoncell" id="reset" type="button" data-dojo-type="dijit/form/Button" data-dojo-props="onClick: function(){ ctrl.reset(); }">Reset</button> |
| 210 | <button class="buttoncell" id="commit" type="button" data-dojo-type="dijit/form/Button" data-dojo-props="onClick: function(){ ctrl.commit(); }">Save</button> |
| 211 | </div> |
| 212 | |
| 213 | <br/> |
| 214 | |
| 215 | <div class="fullrow" data-dojo-type="dojox/mvc/Group" data-dojo-props="target: at(ctrl,'cursor')"> |
| 216 | <div> |
| 217 | <h2>Verify the shipping address for: |
| 218 | <div class="namecell" id="AddressNameOutput" data-dojo-type="dojox/mvc/Output" |
| 219 | data-dojo-props="value: at('rel:', 'AddressName')"></div> |
| 220 | |
| 221 | </h2> |
| 222 | </div> |
| 223 | <div class="fullrow"> |
| 224 | <div class="boldnamecell" data-dojo-type="dojox/mvc/Output" |
| 225 | data-dojo-props="value: at('rel:', 'FullName')"></div> |
| 226 | </div> |
| 227 | <div class="fullrow"> |
| 228 | <div class="namecell" data-dojo-type="dojox/mvc/Output" |
| 229 | data-dojo-props="value: at('rel:', 'AddressLine1')"></div> |
| 230 | </div> |
| 231 | <div class="hiderow" data-mvc-bindings="class: at('rel:', 'AddressLine2').direction(at.from).transform(ctrl.transformAddress2Class)"> |
| 232 | <div class="namecell" data-dojo-type="dojox/mvc/Output" |
| 233 | data-dojo-props="value: at('rel:', 'AddressLine2')"></div> |
| 234 | </div> |
| 235 | <div class="fullrow"> |
| 236 | <div class="namecell" data-dojo-type="dojox/mvc/Output" |
| 237 | data-dojo-props="exprchar:'%', value: at('rel:', 'City')">%{this.value},</div> |
| 238 | <div class="namecell" data-dojo-type="dojox/mvc/Output" |
| 239 | data-dojo-props="value: at('rel:', 'State')"></div> |
| 240 | <div class="namecell" data-dojo-type="dojox/mvc/Output" |
| 241 | data-dojo-props="value: at('rel:', 'Zip')"></div> |
| 242 | </div> |
| 243 | </div> |
| 244 | </div> |
| 245 | </div> |
| 246 | </body> |
| 247 | </html> |