Chromium Code Reviews| 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 fe461f3e7ad4599586909eae97d3f8f4cb34aee6..243a30b7c6858b816a7f36275b02eb668d803eef 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] = $('addrLine2').value; |
| address[5] = $('city').value; |
| address[6] = $('state').value; |
| - address[7] = $('zipCode').value; |
| + address[7] = $('postalCode').value; |
| address[8] = $('country').value; |
| address[9] = $('phone').value; |
| address[10] = $('fax').value; |
| @@ -88,11 +89,15 @@ cr.define('options', function() { |
| var self = this; |
| $('fullName').oninput = $('companyName').oninput = |
| $('addrLine1').oninput = $('addrLine2').oninput = $('city').oninput = |
| - $('state').oninput = $('country').oninput = $('zipCode').oninput = |
| + $('state').oninput = $('country').oninput = $('postalCode').oninput = |
| $('phone').oninput = $('fax').oninput = |
| $('email').oninput = function(event) { |
| self.inputFieldChanged_(); |
| } |
| + |
| + $('country').onchange = function(event) { |
| + self.countryChanged_(event); |
| + } |
| }, |
| /** |
| @@ -104,12 +109,77 @@ cr.define('options', function() { |
| var disabled = |
| !$('fullName').value && !$('companyName').value && |
| !$('addrLine1').value && !$('addrLine2').value && !$('city').value && |
| - !$('state').value && !$('zipCode').value && !('country').value && |
| + !$('state').value && !$('postalCode').value && !('country').value && |
| !$('phone').value && !$('fax').value && !$('email').value; |
| $('autoFillEditAddressApplyButton').disabled = disabled; |
| }, |
| /** |
| + * Updates the postal code and state field labels appropriately for the |
| + * selected country. |
| + * @private |
| + */ |
| + countryChanged_: function(event) { |
|
James Hawkins
2011/02/12 20:32:45
Document parameter.
Ilya Sherman
2011/02/16 10:27:18
Removed.
|
| + var countryCode = $('country').value; |
| + if (countryCode == '') |
|
James Hawkins
2011/02/12 20:32:45
if (!countryCode)
Ilya Sherman
2011/02/16 10:27:18
Done.
|
| + countryCode = templateData.defaultCountryCode; |
| + |
| + var details = templateData.autofillCountryData[countryCode]; |
| + var postal = $('postalCodeLabel'); |
| + postal.textContent = details['postalCodeLabel']; |
|
arv (Not doing code reviews)
2011/02/14 18:36:41
Use i18n-content attribute instead
Ilya Sherman
2011/02/16 10:27:18
As discussed on irc, can't use i18n-content becaus
|
| + $('stateLabel').textContent = details['stateLabel']; |
|
arv (Not doing code reviews)
2011/02/14 18:36:41
same here
|
| + |
| + // Also update the 'Ok' button as needed. |
| + this.inputFieldChanged_(); |
| + }, |
| + |
| + /** |
| + * Populates the country <select> list. |
| + * @private |
| + */ |
| + populateCountryList_: function() { |
| + var countryData = templateData.autofillCountryData; |
|
James Hawkins
2011/02/12 20:32:45
localStrings.getString('autofillCountryData');
Ilya Sherman
2011/02/16 10:27:18
It's not actually a string, so getString() doesn't
|
| + 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 = new Array(); |
|
arv (Not doing code reviews)
2011/02/14 18:36:41
Use literals where possible.
var countries = [];
Ilya Sherman
2011/02/16 10:27:18
Done.
|
| + 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, |
|
arv (Not doing code reviews)
2011/02/14 18:36:41
Skip the quotes?
The Google3 style rule is to use
Ilya Sherman
2011/02/16 10:27:18
Done.
|
| + 'name': countryData[countryCode]['name'] |
| + }; |
| + countries[countries.length] = country; |
|
arv (Not doing code reviews)
2011/02/14 18:36:41
countries.push(country)
Ilya Sherman
2011/02/16 10:27:18
Done.
|
| + } |
| + |
| + // Sort the countries in alphabetical order by name. |
| + countries = countries.sort(function(a, b) { |
| + return a['name'] < b['name']? -1 : 1; |
|
arv (Not doing code reviews)
2011/02/14 18:36:41
ws around ?
arv (Not doing code reviews)
2011/02/14 18:36:41
a.name < b.name ? -1 : 1
Ilya Sherman
2011/02/16 10:27:18
Done.
Ilya Sherman
2011/02/16 10:27:18
Done.
|
| + }); |
| + |
| + // Insert the default country at the beginning of the array. |
| + var defaultCountry = { |
| + 'countryCode': defaultCountryCode, |
| + 'name': countryData[defaultCountryCode]['name'] |
| + }; |
| + countries.unshift(defaultCountry); |
| + |
| + // Add the countries to the country <select> list. |
| + var countryList = $('country'); |
| + for (var i = 0; i < countries.length; ++i) { |
|
arv (Not doing code reviews)
2011/02/14 18:36:41
i++ is the norm in js
Ilya Sherman
2011/02/16 10:27:18
Done.
|
| + var option = document.createElement('option'); |
|
arv (Not doing code reviews)
2011/02/14 18:36:41
or
var option = new Option(text, value);
Ilya Sherman
2011/02/16 10:27:18
Done.
|
| + option.value = countries[i]['countryCode']; |
| + option.textContent = countries[i]['name']; |
| + countryList.appendChild(option) |
| + } |
| + }, |
| + |
| + /** |
| * Clears the value of each input field. |
| * @private |
| */ |
| @@ -120,11 +190,13 @@ cr.define('options', function() { |
| $('addrLine2').value = ''; |
| $('city').value = ''; |
| $('state').value = ''; |
| - $('zipCode').value = ''; |
| + $('postalCode').value = ''; |
| $('country').value = ''; |
| $('phone').value = ''; |
| $('fax').value = ''; |
| $('email').value = ''; |
| + |
| + this.countryChanged_(); |
| }, |
| /** |
| @@ -149,11 +221,13 @@ cr.define('options', function() { |
| $('addrLine2').value = address['addrLine2']; |
| $('city').value = address['city']; |
| $('state').value = address['state']; |
| - $('zipCode').value = address['zipCode']; |
| + $('postalCode').value = address['postalCode']; |
| $('country').value = address['country']; |
| $('phone').value = address['phone']; |
| $('fax').value = address['fax']; |
| $('email').value = address['email']; |
| + |
| + this.countryChanged_(); |
| }, |
| }; |