Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 /** @const */ var OptionsPage = options.OptionsPage; | 6 /** @const */ var OptionsPage = options.OptionsPage; |
| 7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| 8 | 8 |
| 9 // The GUID of the loaded address. | 9 // The GUID of the loaded address. |
| 10 var guid; | 10 var guid; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 | 53 |
| 54 // Prevent 'blur' events on the OK and cancel buttons, which can trigger | 54 // Prevent 'blur' events on the OK and cancel buttons, which can trigger |
| 55 // insertion of new placeholder elements. The addition of placeholders | 55 // insertion of new placeholder elements. The addition of placeholders |
| 56 // affects layout, which interferes with being able to click on the | 56 // affects layout, which interferes with being able to click on the |
| 57 // buttons. | 57 // buttons. |
| 58 $('autofill-edit-address-apply-button').onmousedown = function(event) { | 58 $('autofill-edit-address-apply-button').onmousedown = function(event) { |
| 59 event.preventDefault(); | 59 event.preventDefault(); |
| 60 }; | 60 }; |
| 61 $('autofill-edit-address-cancel-button').onmousedown = function(event) { | 61 $('autofill-edit-address-cancel-button').onmousedown = function(event) { |
| 62 event.preventDefault(); | 62 event.preventDefault(); |
| 63 } | 63 }; |
| 64 | 64 |
| 65 self.guid = ''; | 65 self.guid = ''; |
| 66 self.populateCountryList_(); | 66 self.populateCountryList_(); |
| 67 self.clearInputFields_(); | 67 self.clearInputFields_(); |
| 68 self.connectInputEvents_(); | 68 self.connectInputEvents_(); |
| 69 }, | 69 }, |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * Creates, decorates and initializes the multi-value lists for full name, | 72 * Creates, decorates and initializes the multi-value lists for full name, |
| 73 * phone, and email. | 73 * phone, and email. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * Updates the data model for the list named |listName| with the values from | 91 * Updates the data model for the list named |listName| with the values from |
| 92 * |entries|. | 92 * |entries|. |
| 93 * @param {String} listName The id of the list. | 93 * @param {String} listName The id of the list. |
| 94 * @param {Array} entries The list of items to be added to the list. | 94 * @param {Array} entries The list of items to be added to the list. |
| 95 */ | 95 */ |
| 96 setMultiValueList_: function(listName, entries) { | 96 setMultiValueList_: function(listName, entries) { |
| 97 // Add data entries. | 97 // Add data entries. |
| 98 var list = $(listName); | 98 var list = $(listName); |
| 99 list.dataModel = new ArrayDataModel(entries); | |
| 100 | 99 |
| 101 // Add special entry for adding new values. | 100 // Add special entry for adding new values. |
| 102 list.dataModel.splice(list.dataModel.length, 0, null); | 101 var augmentedList = entries.slice(); |
| 102 augmentedList.push(null); | |
| 103 list.dataModel = new ArrayDataModel(augmentedList); | |
|
arv (Not doing code reviews)
2012/08/16 15:29:37
Good catch
pneubeck (no reviews)
2012/08/17 11:35:11
Done.
| |
| 103 | 104 |
| 104 // Update the status of the 'OK' button. | 105 // Update the status of the 'OK' button. |
| 105 this.inputFieldChanged_(); | 106 this.inputFieldChanged_(); |
| 106 | 107 |
| 107 var self = this; | 108 list.dataModel.addEventListener('splice', |
| 108 list.dataModel.addEventListener( | 109 this.inputFieldChanged_.bind(this)); |
| 109 'splice', function(event) { self.inputFieldChanged_(); }); | 110 list.dataModel.addEventListener('change', |
| 110 list.dataModel.addEventListener( | 111 this.inputFieldChanged_.bind(this)); |
| 111 'change', function(event) { self.inputFieldChanged_(); }); | |
| 112 }, | 112 }, |
| 113 | 113 |
| 114 /** | 114 /** |
| 115 * Updates the data model for the name list with the values from |entries|. | |
| 116 * @param {Array} names The list of names to be added to the list. | |
| 117 */ | |
| 118 setNameList_: function(names) { | |
| 119 // Add the given |names| as backing data for the list. | |
| 120 var list = $('full-name-list'); | |
| 121 list.dataModel = new ArrayDataModel(names); | |
| 122 | |
| 123 // Add special entry for adding new values. | |
| 124 list.dataModel.splice(list.dataModel.length, 0, null); | |
| 125 | |
| 126 var self = this; | |
| 127 list.dataModel.addEventListener( | |
| 128 'splice', function(event) { self.inputFieldChanged_(); }); | |
| 129 list.dataModel.addEventListener( | |
| 130 'change', function(event) { self.inputFieldChanged_(); }); | |
| 131 }, | |
| 132 | |
| 133 /** | |
| 134 * Clears any uncommitted input, resets the stored GUID and dismisses the | 115 * Clears any uncommitted input, resets the stored GUID and dismisses the |
| 135 * overlay. | 116 * overlay. |
| 136 * @private | 117 * @private |
| 137 */ | 118 */ |
| 138 dismissOverlay_: function() { | 119 dismissOverlay_: function() { |
| 139 this.clearInputFields_(); | 120 this.clearInputFields_(); |
| 140 this.guid = ''; | 121 this.guid = ''; |
| 141 OptionsPage.closeOverlay(); | 122 OptionsPage.closeOverlay(); |
| 142 }, | 123 }, |
| 143 | 124 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 country.disabled = countries[i].disabled; | 249 country.disabled = countries[i].disabled; |
| 269 countryList.appendChild(country); | 250 countryList.appendChild(country); |
| 270 } | 251 } |
| 271 }, | 252 }, |
| 272 | 253 |
| 273 /** | 254 /** |
| 274 * Clears the value of each input field. | 255 * Clears the value of each input field. |
| 275 * @private | 256 * @private |
| 276 */ | 257 */ |
| 277 clearInputFields_: function() { | 258 clearInputFields_: function() { |
| 278 this.setNameList_([]); | 259 this.setMultiValueList_('full-name-list', []); |
| 279 $('company-name').value = ''; | 260 $('company-name').value = ''; |
| 280 $('addr-line-1').value = ''; | 261 $('addr-line-1').value = ''; |
| 281 $('addr-line-2').value = ''; | 262 $('addr-line-2').value = ''; |
| 282 $('city').value = ''; | 263 $('city').value = ''; |
| 283 $('state').value = ''; | 264 $('state').value = ''; |
| 284 $('postal-code').value = ''; | 265 $('postal-code').value = ''; |
| 285 $('country').value = ''; | 266 $('country').value = ''; |
| 286 this.setMultiValueList_('phone-list', []); | 267 this.setMultiValueList_('phone-list', []); |
| 287 this.setMultiValueList_('email-list', []); | 268 this.setMultiValueList_('email-list', []); |
| 288 | 269 |
| 289 this.countryChanged_(); | 270 this.countryChanged_(); |
| 290 }, | 271 }, |
| 291 | 272 |
| 292 /** | 273 /** |
| 293 * Loads the address data from |address|, sets the input fields based on | 274 * Loads the address data from |address|, sets the input fields based on |
| 294 * this data and stores the GUID of the address. | 275 * this data and stores the GUID of the address. |
| 295 * @private | 276 * @private |
| 296 */ | 277 */ |
| 297 loadAddress_: function(address) { | 278 loadAddress_: function(address) { |
| 298 this.setInputFields_(address); | 279 this.setInputFields_(address); |
| 299 this.inputFieldChanged_(); | 280 this.inputFieldChanged_(); |
| 300 this.guid = address['guid']; | 281 this.guid = address['guid']; |
| 301 }, | 282 }, |
| 302 | 283 |
| 303 /** | 284 /** |
| 304 * Sets the value of each input field according to |address| | 285 * Sets the value of each input field according to |address| |
| 305 * @private | 286 * @private |
| 306 */ | 287 */ |
| 307 setInputFields_: function(address) { | 288 setInputFields_: function(address) { |
| 308 this.setNameList_(address['fullName']); | 289 this.setMultiValueList_('full-name-list', address['fullName']); |
| 309 $('company-name').value = address['companyName']; | 290 $('company-name').value = address['companyName']; |
| 310 $('addr-line-1').value = address['addrLine1']; | 291 $('addr-line-1').value = address['addrLine1']; |
| 311 $('addr-line-2').value = address['addrLine2']; | 292 $('addr-line-2').value = address['addrLine2']; |
| 312 $('city').value = address['city']; | 293 $('city').value = address['city']; |
| 313 $('state').value = address['state']; | 294 $('state').value = address['state']; |
| 314 $('postal-code').value = address['postalCode']; | 295 $('postal-code').value = address['postalCode']; |
| 315 $('country').value = address['country']; | 296 $('country').value = address['country']; |
| 316 this.setMultiValueList_('phone-list', address['phone']); | 297 this.setMultiValueList_('phone-list', address['phone']); |
| 317 this.setMultiValueList_('email-list', address['email']); | 298 this.setMultiValueList_('email-list', address['email']); |
| 318 | 299 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 335 AutofillEditAddressOverlay.setValidatedPhoneNumbers = function(numbers) { | 316 AutofillEditAddressOverlay.setValidatedPhoneNumbers = function(numbers) { |
| 336 AutofillEditAddressOverlay.getInstance().setMultiValueList_('phone-list', | 317 AutofillEditAddressOverlay.getInstance().setMultiValueList_('phone-list', |
| 337 numbers); | 318 numbers); |
| 338 }; | 319 }; |
| 339 | 320 |
| 340 // Export | 321 // Export |
| 341 return { | 322 return { |
| 342 AutofillEditAddressOverlay: AutofillEditAddressOverlay | 323 AutofillEditAddressOverlay: AutofillEditAddressOverlay |
| 343 }; | 324 }; |
| 344 }); | 325 }); |
| OLD | NEW |