OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
6 * @fileoverview 'password-edit-dialog' is the dialog that allows showing a | 6 * @fileoverview 'password-edit-dialog' is the dialog that allows showing a |
7 * saved password. | 7 * saved password. |
8 */ | 8 */ |
9 (function() { | 9 (function() { |
10 'use strict'; | 10 'use strict'; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 onCountryChange_: function() { | 193 onCountryChange_: function() { |
194 var countrySelect = /** @type {!HTMLSelectElement} */ (this.$$('select')); | 194 var countrySelect = /** @type {!HTMLSelectElement} */ (this.$$('select')); |
195 this.countryCode_ = countrySelect.value; | 195 this.countryCode_ = countrySelect.value; |
196 }, | 196 }, |
197 }); | 197 }); |
198 })(); | 198 })(); |
199 | 199 |
200 cr.define('settings.address', function() { | 200 cr.define('settings.address', function() { |
201 /** | 201 /** |
202 * Creates a wrapper against a single data member for an address. | 202 * Creates a wrapper against a single data member for an address. |
203 * @param {!chrome.autofillPrivate.AddressEntry} address | |
204 * @param {!chrome.autofillPrivate.AddressComponent} component | |
205 * @constructor | |
206 */ | 203 */ |
207 function AddressComponentUI(address, component) { | 204 class AddressComponentUI { |
208 Object.defineProperty(this, 'value', { | 205 /** |
209 get: function() { | 206 * @param {!chrome.autofillPrivate.AddressEntry} address |
210 return this.getValue_(); | 207 * @param {!chrome.autofillPrivate.AddressComponent} component |
211 }, | 208 */ |
212 set: function(newValue) { | 209 constructor(address, component) { |
213 this.setValue_(newValue); | 210 Object.defineProperty(this, 'value', { |
214 }, | 211 get: function() { |
215 }); | 212 return this.getValue_(); |
216 this.address_ = address; | 213 }, |
217 this.component = component; | 214 set: function(newValue) { |
218 this.isTextArea = | 215 this.setValue_(newValue); |
219 component.field == chrome.autofillPrivate.AddressField.ADDRESS_LINES; | 216 }, |
220 } | 217 }); |
| 218 this.address_ = address; |
| 219 this.component = component; |
| 220 this.isTextArea = |
| 221 component.field == chrome.autofillPrivate.AddressField.ADDRESS_LINES; |
| 222 } |
221 | 223 |
222 AddressComponentUI.prototype = { | |
223 /** | 224 /** |
224 * Gets the value from the address that's associated with this component. | 225 * Gets the value from the address that's associated with this component. |
225 * @return {string|undefined} | 226 * @return {string|undefined} |
226 * @private | 227 * @private |
227 */ | 228 */ |
228 getValue_: function() { | 229 getValue_() { |
229 var address = this.address_; | 230 var address = this.address_; |
230 switch (this.component.field) { | 231 switch (this.component.field) { |
231 case chrome.autofillPrivate.AddressField.FULL_NAME: | 232 case chrome.autofillPrivate.AddressField.FULL_NAME: |
232 // |fullNames| is a single item array. See crbug.com/497934 for | 233 // |fullNames| is a single item array. See crbug.com/497934 for |
233 // details. | 234 // details. |
234 return address.fullNames ? address.fullNames[0] : undefined; | 235 return address.fullNames ? address.fullNames[0] : undefined; |
235 case chrome.autofillPrivate.AddressField.COMPANY_NAME: | 236 case chrome.autofillPrivate.AddressField.COMPANY_NAME: |
236 return address.companyName; | 237 return address.companyName; |
237 case chrome.autofillPrivate.AddressField.ADDRESS_LINES: | 238 case chrome.autofillPrivate.AddressField.ADDRESS_LINES: |
238 return address.addressLines; | 239 return address.addressLines; |
239 case chrome.autofillPrivate.AddressField.ADDRESS_LEVEL_1: | 240 case chrome.autofillPrivate.AddressField.ADDRESS_LEVEL_1: |
240 return address.addressLevel1; | 241 return address.addressLevel1; |
241 case chrome.autofillPrivate.AddressField.ADDRESS_LEVEL_2: | 242 case chrome.autofillPrivate.AddressField.ADDRESS_LEVEL_2: |
242 return address.addressLevel2; | 243 return address.addressLevel2; |
243 case chrome.autofillPrivate.AddressField.ADDRESS_LEVEL_3: | 244 case chrome.autofillPrivate.AddressField.ADDRESS_LEVEL_3: |
244 return address.addressLevel3; | 245 return address.addressLevel3; |
245 case chrome.autofillPrivate.AddressField.POSTAL_CODE: | 246 case chrome.autofillPrivate.AddressField.POSTAL_CODE: |
246 return address.postalCode; | 247 return address.postalCode; |
247 case chrome.autofillPrivate.AddressField.SORTING_CODE: | 248 case chrome.autofillPrivate.AddressField.SORTING_CODE: |
248 return address.sortingCode; | 249 return address.sortingCode; |
249 case chrome.autofillPrivate.AddressField.COUNTRY_CODE: | 250 case chrome.autofillPrivate.AddressField.COUNTRY_CODE: |
250 return address.countryCode; | 251 return address.countryCode; |
251 default: | 252 default: |
252 assertNotReached(); | 253 assertNotReached(); |
253 } | 254 } |
254 }, | 255 } |
255 | 256 |
256 /** | 257 /** |
257 * Sets the value in the address that's associated with this component. | 258 * Sets the value in the address that's associated with this component. |
258 * @param {string} value | 259 * @param {string} value |
259 * @private | 260 * @private |
260 */ | 261 */ |
261 setValue_: function(value) { | 262 setValue_(value) { |
262 var address = this.address_; | 263 var address = this.address_; |
263 switch (this.component.field) { | 264 switch (this.component.field) { |
264 case chrome.autofillPrivate.AddressField.FULL_NAME: | 265 case chrome.autofillPrivate.AddressField.FULL_NAME: |
265 address.fullNames = [value]; | 266 address.fullNames = [value]; |
266 break; | 267 break; |
267 case chrome.autofillPrivate.AddressField.COMPANY_NAME: | 268 case chrome.autofillPrivate.AddressField.COMPANY_NAME: |
268 address.companyName = value; | 269 address.companyName = value; |
269 break; | 270 break; |
270 case chrome.autofillPrivate.AddressField.ADDRESS_LINES: | 271 case chrome.autofillPrivate.AddressField.ADDRESS_LINES: |
271 address.addressLines = value; | 272 address.addressLines = value; |
(...skipping 12 matching lines...) Expand all Loading... |
284 break; | 285 break; |
285 case chrome.autofillPrivate.AddressField.SORTING_CODE: | 286 case chrome.autofillPrivate.AddressField.SORTING_CODE: |
286 address.sortingCode = value; | 287 address.sortingCode = value; |
287 break; | 288 break; |
288 case chrome.autofillPrivate.AddressField.COUNTRY_CODE: | 289 case chrome.autofillPrivate.AddressField.COUNTRY_CODE: |
289 address.countryCode = value; | 290 address.countryCode = value; |
290 break; | 291 break; |
291 default: | 292 default: |
292 assertNotReached(); | 293 assertNotReached(); |
293 } | 294 } |
294 }, | 295 } |
295 }; | 296 } |
296 | 297 |
297 /** @interface */ | 298 /** @interface */ |
298 function CountryDetailManager() {} | 299 class CountryDetailManager { |
299 CountryDetailManager.prototype = { | |
300 /** | 300 /** |
301 * Gets the list of available countries. | 301 * Gets the list of available countries. |
302 * The default country will be first, followed by a separator, followed by | 302 * The default country will be first, followed by a separator, followed by |
303 * an alphabetized list of countries available. | 303 * an alphabetized list of countries available. |
304 * @return {!Promise<!Array<!chrome.autofillPrivate.CountryEntry>>} | 304 * @return {!Promise<!Array<!chrome.autofillPrivate.CountryEntry>>} |
305 */ | 305 */ |
306 getCountryList: assertNotReached, | 306 getCountryList() {} |
307 | 307 |
308 /** | 308 /** |
309 * Gets the address format for a given country code. | 309 * Gets the address format for a given country code. |
310 * @param {string} countryCode | 310 * @param {string} countryCode |
311 * @return {!Promise<!chrome.autofillPrivate.AddressComponents>} | 311 * @return {!Promise<!chrome.autofillPrivate.AddressComponents>} |
312 */ | 312 */ |
313 getAddressFormat: assertNotReached, | 313 getAddressFormat(countryCode) {} |
314 }; | 314 } |
315 | 315 |
316 /** | 316 /** |
317 * Default implementation. Override for testing. | 317 * Default implementation. Override for testing. |
318 * @implements {settings.address.CountryDetailManager} | 318 * @implements {settings.address.CountryDetailManager} |
319 * @constructor | |
320 */ | 319 */ |
321 function CountryDetailManagerImpl() {} | 320 class CountryDetailManagerImpl { |
322 cr.addSingletonGetter(CountryDetailManagerImpl); | |
323 CountryDetailManagerImpl.prototype = { | |
324 __proto__: CountryDetailManager, | |
325 | |
326 /** @override */ | 321 /** @override */ |
327 getCountryList: function() { | 322 getCountryList() { |
328 return new Promise(function(callback) { | 323 return new Promise(function(callback) { |
329 chrome.autofillPrivate.getCountryList(callback); | 324 chrome.autofillPrivate.getCountryList(callback); |
330 }); | 325 }); |
331 }, | 326 } |
332 | 327 |
333 /** @override */ | 328 /** @override */ |
334 getAddressFormat: function(countryCode) { | 329 getAddressFormat(countryCode) { |
335 return new Promise(function(callback) { | 330 return new Promise(function(callback) { |
336 chrome.autofillPrivate.getAddressComponents(countryCode, callback); | 331 chrome.autofillPrivate.getAddressComponents(countryCode, callback); |
337 }); | 332 }); |
338 }, | 333 } |
339 }; | 334 } |
| 335 |
| 336 cr.addSingletonGetter(CountryDetailManagerImpl); |
340 | 337 |
341 return { | 338 return { |
342 AddressComponentUI: AddressComponentUI, | 339 AddressComponentUI: AddressComponentUI, |
343 CountryDetailManager: CountryDetailManager, | 340 CountryDetailManager: CountryDetailManager, |
344 CountryDetailManagerImpl: CountryDetailManagerImpl, | 341 CountryDetailManagerImpl: CountryDetailManagerImpl, |
345 }; | 342 }; |
346 }); | 343 }); |
OLD | NEW |