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

Side by Side 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: I see you, ICU 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 OptionsPage = options.OptionsPage; 6 const OptionsPage = options.OptionsPage;
7 7
8 // The GUID of the loaded address. 8 // The GUID of the loaded address.
9 var guid; 9 var guid;
10 10
(...skipping 22 matching lines...) Expand all
33 var self = this; 33 var self = this;
34 $('autoFillEditAddressCancelButton').onclick = function(event) { 34 $('autoFillEditAddressCancelButton').onclick = function(event) {
35 self.dismissOverlay_(); 35 self.dismissOverlay_();
36 } 36 }
37 $('autoFillEditAddressApplyButton').onclick = function(event) { 37 $('autoFillEditAddressApplyButton').onclick = function(event) {
38 self.saveAddress_(); 38 self.saveAddress_();
39 self.dismissOverlay_(); 39 self.dismissOverlay_();
40 } 40 }
41 41
42 self.guid = ''; 42 self.guid = '';
43 self.populateCountryList_();
43 self.clearInputFields_(); 44 self.clearInputFields_();
44 self.connectInputEvents_(); 45 self.connectInputEvents_();
45 }, 46 },
46 47
47 /** 48 /**
48 * Clears any uncommitted input, resets the stored GUID and dismisses the 49 * Clears any uncommitted input, resets the stored GUID and dismisses the
49 * overlay. 50 * overlay.
50 * @private 51 * @private
51 */ 52 */
52 dismissOverlay_: function() { 53 dismissOverlay_: function() {
53 this.clearInputFields_(); 54 this.clearInputFields_();
54 this.guid = ''; 55 this.guid = '';
55 OptionsPage.closeOverlay(); 56 OptionsPage.closeOverlay();
56 }, 57 },
57 58
58 /** 59 /**
59 * Aggregates the values in the input fields into an array and sends the 60 * Aggregates the values in the input fields into an array and sends the
60 * array to the AutoFill handler. 61 * array to the AutoFill handler.
61 * @private 62 * @private
62 */ 63 */
63 saveAddress_: function() { 64 saveAddress_: function() {
64 var address = new Array(); 65 var address = new Array();
65 address[0] = this.guid; 66 address[0] = this.guid;
66 address[1] = $('fullName').value; 67 address[1] = $('fullName').value;
67 address[2] = $('companyName').value; 68 address[2] = $('companyName').value;
68 address[3] = $('addrLine1').value; 69 address[3] = $('addrLine1').value;
69 address[4] = $('addrLine2').value; 70 address[4] = $('addrLine2').value;
70 address[5] = $('city').value; 71 address[5] = $('city').value;
71 address[6] = $('state').value; 72 address[6] = $('state').value;
72 address[7] = $('zipCode').value; 73 address[7] = $('postalCode').value;
73 address[8] = $('country').value; 74 address[8] = $('country').value;
74 address[9] = $('phone').value; 75 address[9] = $('phone').value;
75 address[10] = $('fax').value; 76 address[10] = $('fax').value;
76 address[11] = $('email').value; 77 address[11] = $('email').value;
77 78
78 chrome.send('setAddress', address); 79 chrome.send('setAddress', address);
79 }, 80 },
80 81
81 /** 82 /**
82 * Connects each input field to the inputFieldChanged_() method that enables 83 * Connects each input field to the inputFieldChanged_() method that enables
83 * or disables the 'Ok' button based on whether all the fields are empty or 84 * or disables the 'Ok' button based on whether all the fields are empty or
84 * not. 85 * not.
85 * @private 86 * @private
86 */ 87 */
87 connectInputEvents_: function() { 88 connectInputEvents_: function() {
88 var self = this; 89 var self = this;
89 $('fullName').oninput = $('companyName').oninput = 90 $('fullName').oninput = $('companyName').oninput =
90 $('addrLine1').oninput = $('addrLine2').oninput = $('city').oninput = 91 $('addrLine1').oninput = $('addrLine2').oninput = $('city').oninput =
91 $('state').oninput = $('country').oninput = $('zipCode').oninput = 92 $('state').oninput = $('country').oninput = $('postalCode').oninput =
92 $('phone').oninput = $('fax').oninput = 93 $('phone').oninput = $('fax').oninput =
93 $('email').oninput = function(event) { 94 $('email').oninput = function(event) {
94 self.inputFieldChanged_(); 95 self.inputFieldChanged_();
95 } 96 }
97
98 $('country').onchange = function(event) {
99 self.countryChanged_(event);
100 }
96 }, 101 },
97 102
98 /** 103 /**
99 * Checks the values of each of the input fields and disables the 'Ok' 104 * Checks the values of each of the input fields and disables the 'Ok'
100 * button if all of the fields are empty. 105 * button if all of the fields are empty.
101 * @private 106 * @private
102 */ 107 */
103 inputFieldChanged_: function() { 108 inputFieldChanged_: function() {
104 var disabled = 109 var disabled =
105 !$('fullName').value && !$('companyName').value && 110 !$('fullName').value && !$('companyName').value &&
106 !$('addrLine1').value && !$('addrLine2').value && !$('city').value && 111 !$('addrLine1').value && !$('addrLine2').value && !$('city').value &&
107 !$('state').value && !$('zipCode').value && !('country').value && 112 !$('state').value && !$('postalCode').value && !('country').value &&
108 !$('phone').value && !$('fax').value && !$('email').value; 113 !$('phone').value && !$('fax').value && !$('email').value;
109 $('autoFillEditAddressApplyButton').disabled = disabled; 114 $('autoFillEditAddressApplyButton').disabled = disabled;
110 }, 115 },
111 116
112 /** 117 /**
118 * Updates the postal code and state field labels appropriately for the
119 * selected country.
120 * @private
121 */
122 countryChanged_: function(event) {
James Hawkins 2011/02/12 20:32:45 Document parameter.
Ilya Sherman 2011/02/16 10:27:18 Removed.
123 var countryCode = $('country').value;
124 if (countryCode == '')
James Hawkins 2011/02/12 20:32:45 if (!countryCode)
Ilya Sherman 2011/02/16 10:27:18 Done.
125 countryCode = templateData.defaultCountryCode;
126
127 var details = templateData.autofillCountryData[countryCode];
128 var postal = $('postalCodeLabel');
129 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
130 $('stateLabel').textContent = details['stateLabel'];
arv (Not doing code reviews) 2011/02/14 18:36:41 same here
131
132 // Also update the 'Ok' button as needed.
133 this.inputFieldChanged_();
134 },
135
136 /**
137 * Populates the country <select> list.
138 * @private
139 */
140 populateCountryList_: function() {
141 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
142 var defaultCountryCode = templateData.defaultCountryCode;
143
144 // Build an array of the country names and their corresponding country
145 // codes, so that we can sort and insert them in order.
146 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.
147 for (var countryCode in countryData) {
148 // We always want the default country to be at the top of the list, so
149 // we handle it separately.
150 if (countryCode == defaultCountryCode)
151 continue;
152
153 var country = {
154 '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.
155 'name': countryData[countryCode]['name']
156 };
157 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.
158 }
159
160 // Sort the countries in alphabetical order by name.
161 countries = countries.sort(function(a, b) {
162 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.
163 });
164
165 // Insert the default country at the beginning of the array.
166 var defaultCountry = {
167 'countryCode': defaultCountryCode,
168 'name': countryData[defaultCountryCode]['name']
169 };
170 countries.unshift(defaultCountry);
171
172 // Add the countries to the country <select> list.
173 var countryList = $('country');
174 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.
175 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.
176 option.value = countries[i]['countryCode'];
177 option.textContent = countries[i]['name'];
178 countryList.appendChild(option)
179 }
180 },
181
182 /**
113 * Clears the value of each input field. 183 * Clears the value of each input field.
114 * @private 184 * @private
115 */ 185 */
116 clearInputFields_: function() { 186 clearInputFields_: function() {
117 $('fullName').value = ''; 187 $('fullName').value = '';
118 $('companyName').value = ''; 188 $('companyName').value = '';
119 $('addrLine1').value = ''; 189 $('addrLine1').value = '';
120 $('addrLine2').value = ''; 190 $('addrLine2').value = '';
121 $('city').value = ''; 191 $('city').value = '';
122 $('state').value = ''; 192 $('state').value = '';
123 $('zipCode').value = ''; 193 $('postalCode').value = '';
124 $('country').value = ''; 194 $('country').value = '';
125 $('phone').value = ''; 195 $('phone').value = '';
126 $('fax').value = ''; 196 $('fax').value = '';
127 $('email').value = ''; 197 $('email').value = '';
198
199 this.countryChanged_();
128 }, 200 },
129 201
130 /** 202 /**
131 * Loads the address data from |address|, sets the input fields based on 203 * Loads the address data from |address|, sets the input fields based on
132 * this data and stores the GUID of the address. 204 * this data and stores the GUID of the address.
133 * @private 205 * @private
134 */ 206 */
135 loadAddress_: function(address) { 207 loadAddress_: function(address) {
136 this.setInputFields_(address); 208 this.setInputFields_(address);
137 this.inputFieldChanged_(); 209 this.inputFieldChanged_();
138 this.guid = address['guid']; 210 this.guid = address['guid'];
139 }, 211 },
140 212
141 /** 213 /**
142 * Sets the value of each input field according to |address| 214 * Sets the value of each input field according to |address|
143 * @private 215 * @private
144 */ 216 */
145 setInputFields_: function(address) { 217 setInputFields_: function(address) {
146 $('fullName').value = address['fullName']; 218 $('fullName').value = address['fullName'];
147 $('companyName').value = address['companyName']; 219 $('companyName').value = address['companyName'];
148 $('addrLine1').value = address['addrLine1']; 220 $('addrLine1').value = address['addrLine1'];
149 $('addrLine2').value = address['addrLine2']; 221 $('addrLine2').value = address['addrLine2'];
150 $('city').value = address['city']; 222 $('city').value = address['city'];
151 $('state').value = address['state']; 223 $('state').value = address['state'];
152 $('zipCode').value = address['zipCode']; 224 $('postalCode').value = address['postalCode'];
153 $('country').value = address['country']; 225 $('country').value = address['country'];
154 $('phone').value = address['phone']; 226 $('phone').value = address['phone'];
155 $('fax').value = address['fax']; 227 $('fax').value = address['fax'];
156 $('email').value = address['email']; 228 $('email').value = address['email'];
229
230 this.countryChanged_();
157 }, 231 },
158 }; 232 };
159 233
160 AutoFillEditAddressOverlay.clearInputFields = function() { 234 AutoFillEditAddressOverlay.clearInputFields = function() {
161 AutoFillEditAddressOverlay.getInstance().clearInputFields_(); 235 AutoFillEditAddressOverlay.getInstance().clearInputFields_();
162 }; 236 };
163 237
164 AutoFillEditAddressOverlay.loadAddress = function(address) { 238 AutoFillEditAddressOverlay.loadAddress = function(address) {
165 AutoFillEditAddressOverlay.getInstance().loadAddress_(address); 239 AutoFillEditAddressOverlay.getInstance().loadAddress_(address);
166 }; 240 };
167 241
168 AutoFillEditAddressOverlay.setTitle = function(title) { 242 AutoFillEditAddressOverlay.setTitle = function(title) {
169 $('autoFillAddressTitle').textContent = title; 243 $('autoFillAddressTitle').textContent = title;
170 }; 244 };
171 245
172 // Export 246 // Export
173 return { 247 return {
174 AutoFillEditAddressOverlay: AutoFillEditAddressOverlay 248 AutoFillEditAddressOverlay: AutoFillEditAddressOverlay
175 }; 249 };
176 }); 250 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698