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

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: Properly merged with ToT Created 9 years, 9 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 $('autofill-edit-address-cancel-button').onclick = function(event) { 34 $('autofill-edit-address-cancel-button').onclick = function(event) {
35 self.dismissOverlay_(); 35 self.dismissOverlay_();
36 } 36 }
37 $('autofill-edit-address-apply-button').onclick = function(event) { 37 $('autofill-edit-address-apply-button').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] = $('full-name').value; 67 address[1] = $('full-name').value;
67 address[2] = $('company-name').value; 68 address[2] = $('company-name').value;
68 address[3] = $('addr-line-1').value; 69 address[3] = $('addr-line-1').value;
69 address[4] = $('addr-line-2').value; 70 address[4] = $('addr-line-2').value;
70 address[5] = $('city').value; 71 address[5] = $('city').value;
71 address[6] = $('state').value; 72 address[6] = $('state').value;
72 address[7] = $('zip-code').value; 73 address[7] = $('postal-code').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 $('full-name').oninput = $('company-name').oninput = 90 $('full-name').oninput = $('company-name').oninput =
90 $('addr-line-1').oninput = $('addr-line-2').oninput = $('city').oninput = 91 $('addr-line-1').oninput = $('addr-line-2').oninput = $('city').oninput =
91 $('state').oninput = $('country').oninput = $('zip-code').oninput = 92 $('state').oninput = $('postal-code').oninput = $('phone').oninput =
92 $('phone').oninput = $('fax').oninput = 93 $('fax').oninput = $('email').oninput = function(event) {
93 $('email').oninput = function(event) {
94 self.inputFieldChanged_(); 94 self.inputFieldChanged_();
95 } 95 }
96
97 $('country').onchange = function(event) {
98 self.countryChanged_();
99 }
96 }, 100 },
97 101
98 /** 102 /**
99 * Checks the values of each of the input fields and disables the 'Ok' 103 * Checks the values of each of the input fields and disables the 'Ok'
100 * button if all of the fields are empty. 104 * button if all of the fields are empty.
101 * @private 105 * @private
102 */ 106 */
103 inputFieldChanged_: function() { 107 inputFieldChanged_: function() {
104 var disabled = 108 var disabled =
105 !$('full-name').value && !$('company-name').value && 109 !$('full-name').value && !$('company-name').value &&
106 !$('addr-line-1').value && !$('addr-line-2').value && 110 !$('addr-line-1').value && !$('addr-line-2').value &&
107 !$('city').value && !$('state').value && !$('zip-code').value && 111 !$('city').value && !$('state').value && !$('postal-code').value &&
108 !$('country').value && !$('phone').value && !$('fax').value && 112 !$('country').value && !$('phone').value && !$('fax').value &&
109 !$('email').value; 113 !$('email').value;
110 $('autofill-edit-address-apply-button').disabled = disabled; 114 $('autofill-edit-address-apply-button').disabled = disabled;
111 }, 115 },
112 116
113 /** 117 /**
118 * Updates the postal code and state field labels appropriately for the
119 * selected country.
120 * @private
121 */
122 countryChanged_: function() {
123 var countryCode = $('country').value;
124 if (!countryCode)
125 countryCode = templateData.defaultCountryCode;
126
127 var details = templateData.autofillCountryData[countryCode];
128 var postal = $('postal-code-label');
129 postal.textContent = details['postalCodeLabel'];
130 $('state-label').textContent = details['stateLabel'];
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;
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 = [];
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,
155 name: countryData[countryCode]['name']
156 };
157 countries.push(country);
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;
163 });
164
165 // Insert the empty and default countries at the beginning of the array.
166 var emptyCountry = {
167 countryCode: '',
168 name: ''
169 };
170 var defaultCountry = {
171 countryCode: defaultCountryCode,
172 name: countryData[defaultCountryCode]['name']
173 };
174 countries.unshift(emptyCountry, defaultCountry);
175
176 // Add the countries to the country <select> list.
177 var countryList = $('country');
178 for (var i = 0; i < countries.length; i++) {
179 var country = new Option(countries[i].name, countries[i].countryCode);
180 countryList.appendChild(country)
181 }
182 },
183
184 /**
114 * Clears the value of each input field. 185 * Clears the value of each input field.
115 * @private 186 * @private
116 */ 187 */
117 clearInputFields_: function() { 188 clearInputFields_: function() {
118 $('full-name').value = ''; 189 $('full-name').value = '';
119 $('company-name').value = ''; 190 $('company-name').value = '';
120 $('addr-line-1').value = ''; 191 $('addr-line-1').value = '';
121 $('addr-line-2').value = ''; 192 $('addr-line-2').value = '';
122 $('city').value = ''; 193 $('city').value = '';
123 $('state').value = ''; 194 $('state').value = '';
124 $('zip-code').value = ''; 195 $('postal-code').value = '';
125 $('country').value = ''; 196 $('country').value = '';
126 $('phone').value = ''; 197 $('phone').value = '';
127 $('fax').value = ''; 198 $('fax').value = '';
128 $('email').value = ''; 199 $('email').value = '';
200
201 this.countryChanged_();
129 }, 202 },
130 203
131 /** 204 /**
132 * Loads the address data from |address|, sets the input fields based on 205 * Loads the address data from |address|, sets the input fields based on
133 * this data and stores the GUID of the address. 206 * this data and stores the GUID of the address.
134 * @private 207 * @private
135 */ 208 */
136 loadAddress_: function(address) { 209 loadAddress_: function(address) {
137 this.setInputFields_(address); 210 this.setInputFields_(address);
138 this.inputFieldChanged_(); 211 this.inputFieldChanged_();
139 this.guid = address['guid']; 212 this.guid = address['guid'];
140 }, 213 },
141 214
142 /** 215 /**
143 * Sets the value of each input field according to |address| 216 * Sets the value of each input field according to |address|
144 * @private 217 * @private
145 */ 218 */
146 setInputFields_: function(address) { 219 setInputFields_: function(address) {
147 $('full-name').value = address['fullName']; 220 $('full-name').value = address['fullName'];
148 $('company-name').value = address['companyName']; 221 $('company-name').value = address['companyName'];
149 $('addr-line-1').value = address['addrLine1']; 222 $('addr-line-1').value = address['addrLine1'];
150 $('addr-line-2').value = address['addrLine2']; 223 $('addr-line-2').value = address['addrLine2'];
151 $('city').value = address['city']; 224 $('city').value = address['city'];
152 $('state').value = address['state']; 225 $('state').value = address['state'];
153 $('zip-code').value = address['zipCode']; 226 $('postal-code').value = address['postalCode'];
154 $('country').value = address['country']; 227 $('country').value = address['country'];
155 $('phone').value = address['phone']; 228 $('phone').value = address['phone'];
156 $('fax').value = address['fax']; 229 $('fax').value = address['fax'];
157 $('email').value = address['email']; 230 $('email').value = address['email'];
231
232 this.countryChanged_();
158 }, 233 },
159 }; 234 };
160 235
161 AutoFillEditAddressOverlay.clearInputFields = function() { 236 AutoFillEditAddressOverlay.clearInputFields = function() {
162 AutoFillEditAddressOverlay.getInstance().clearInputFields_(); 237 AutoFillEditAddressOverlay.getInstance().clearInputFields_();
163 }; 238 };
164 239
165 AutoFillEditAddressOverlay.loadAddress = function(address) { 240 AutoFillEditAddressOverlay.loadAddress = function(address) {
166 AutoFillEditAddressOverlay.getInstance().loadAddress_(address); 241 AutoFillEditAddressOverlay.getInstance().loadAddress_(address);
167 }; 242 };
168 243
169 AutoFillEditAddressOverlay.setTitle = function(title) { 244 AutoFillEditAddressOverlay.setTitle = function(title) {
170 $('autofill-address-title').textContent = title; 245 $('autofill-address-title').textContent = title;
171 }; 246 };
172 247
173 // Export 248 // Export
174 return { 249 return {
175 AutoFillEditAddressOverlay: AutoFillEditAddressOverlay 250 AutoFillEditAddressOverlay: AutoFillEditAddressOverlay
176 }; 251 };
177 }); 252 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698