| Index: chrome/browser/resources/options/autofill_edit_address_overlay.js
|
| diff --git a/chrome/browser/resources/options/autofill_edit_address_overlay.js b/chrome/browser/resources/options/autofill_edit_address_overlay.js
|
| index 3556e2ed0f0af4d9a8cf7b28d940b00eb8a9f278..6f9e87259303a1e90f86c95a9537427decb74986 100644
|
| --- a/chrome/browser/resources/options/autofill_edit_address_overlay.js
|
| +++ b/chrome/browser/resources/options/autofill_edit_address_overlay.js
|
| @@ -40,6 +40,7 @@ cr.define('options', function() {
|
| }
|
|
|
| self.guid = '';
|
| + self.populateCountryList_();
|
| self.clearInputFields_();
|
| self.connectInputEvents_();
|
| },
|
| @@ -69,7 +70,7 @@ cr.define('options', function() {
|
| address[4] = $('addr-line-2').value;
|
| address[5] = $('city').value;
|
| address[6] = $('state').value;
|
| - address[7] = $('zip-code').value;
|
| + address[7] = $('postal-code').value;
|
| address[8] = $('country').value;
|
| address[9] = $('phone').value;
|
| address[10] = $('fax').value;
|
| @@ -88,11 +89,14 @@ cr.define('options', function() {
|
| var self = this;
|
| $('full-name').oninput = $('company-name').oninput =
|
| $('addr-line-1').oninput = $('addr-line-2').oninput = $('city').oninput =
|
| - $('state').oninput = $('country').oninput = $('zip-code').oninput =
|
| - $('phone').oninput = $('fax').oninput =
|
| - $('email').oninput = function(event) {
|
| + $('state').oninput = $('postal-code').oninput = $('phone').oninput =
|
| + $('fax').oninput = $('email').oninput = function(event) {
|
| self.inputFieldChanged_();
|
| }
|
| +
|
| + $('country').onchange = function(event) {
|
| + self.countryChanged_();
|
| + }
|
| },
|
|
|
| /**
|
| @@ -104,13 +108,80 @@ cr.define('options', function() {
|
| var disabled =
|
| !$('full-name').value && !$('company-name').value &&
|
| !$('addr-line-1').value && !$('addr-line-2').value &&
|
| - !$('city').value && !$('state').value && !$('zip-code').value &&
|
| + !$('city').value && !$('state').value && !$('postal-code').value &&
|
| !$('country').value && !$('phone').value && !$('fax').value &&
|
| !$('email').value;
|
| $('autofill-edit-address-apply-button').disabled = disabled;
|
| },
|
|
|
| /**
|
| + * Updates the postal code and state field labels appropriately for the
|
| + * selected country.
|
| + * @private
|
| + */
|
| + countryChanged_: function() {
|
| + var countryCode = $('country').value;
|
| + if (!countryCode)
|
| + countryCode = templateData.defaultCountryCode;
|
| +
|
| + var details = templateData.autofillCountryData[countryCode];
|
| + var postal = $('postal-code-label');
|
| + postal.textContent = details['postalCodeLabel'];
|
| + $('state-label').textContent = details['stateLabel'];
|
| +
|
| + // Also update the 'Ok' button as needed.
|
| + this.inputFieldChanged_();
|
| + },
|
| +
|
| + /**
|
| + * Populates the country <select> list.
|
| + * @private
|
| + */
|
| + populateCountryList_: function() {
|
| + var countryData = templateData.autofillCountryData;
|
| + var defaultCountryCode = templateData.defaultCountryCode;
|
| +
|
| + // Build an array of the country names and their corresponding country
|
| + // codes, so that we can sort and insert them in order.
|
| + var countries = [];
|
| + for (var countryCode in countryData) {
|
| + // We always want the default country to be at the top of the list, so
|
| + // we handle it separately.
|
| + if (countryCode == defaultCountryCode)
|
| + continue;
|
| +
|
| + var country = {
|
| + countryCode: countryCode,
|
| + name: countryData[countryCode]['name']
|
| + };
|
| + countries.push(country);
|
| + }
|
| +
|
| + // Sort the countries in alphabetical order by name.
|
| + countries = countries.sort(function(a, b) {
|
| + return a.name < b.name ? -1 : 1;
|
| + });
|
| +
|
| + // Insert the empty and default countries at the beginning of the array.
|
| + var emptyCountry = {
|
| + countryCode: '',
|
| + name: ''
|
| + };
|
| + var defaultCountry = {
|
| + countryCode: defaultCountryCode,
|
| + name: countryData[defaultCountryCode]['name']
|
| + };
|
| + countries.unshift(emptyCountry, defaultCountry);
|
| +
|
| + // Add the countries to the country <select> list.
|
| + var countryList = $('country');
|
| + for (var i = 0; i < countries.length; i++) {
|
| + var country = new Option(countries[i].name, countries[i].countryCode);
|
| + countryList.appendChild(country)
|
| + }
|
| + },
|
| +
|
| + /**
|
| * Clears the value of each input field.
|
| * @private
|
| */
|
| @@ -121,11 +192,13 @@ cr.define('options', function() {
|
| $('addr-line-2').value = '';
|
| $('city').value = '';
|
| $('state').value = '';
|
| - $('zip-code').value = '';
|
| + $('postal-code').value = '';
|
| $('country').value = '';
|
| $('phone').value = '';
|
| $('fax').value = '';
|
| $('email').value = '';
|
| +
|
| + this.countryChanged_();
|
| },
|
|
|
| /**
|
| @@ -150,11 +223,13 @@ cr.define('options', function() {
|
| $('addr-line-2').value = address['addrLine2'];
|
| $('city').value = address['city'];
|
| $('state').value = address['state'];
|
| - $('zip-code').value = address['zipCode'];
|
| + $('postal-code').value = address['postalCode'];
|
| $('country').value = address['country'];
|
| $('phone').value = address['phone'];
|
| $('fax').value = address['fax'];
|
| $('email').value = address['email'];
|
| +
|
| + this.countryChanged_();
|
| },
|
| };
|
|
|
|
|