Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5368)

Unified Diff: chrome/browser/resources/options/autofill_edit_address_overlay.js

Issue 6484022: Autofill i18n: Set postal code and state field labels based on the selected country. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Properly merged with ToT Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_();
},
};

Powered by Google App Engine
This is Rietveld 408576698