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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 /** @private */ | 44 /** @private */ |
45 email_: String, | 45 email_: String, |
46 | 46 |
47 /** @private */ | 47 /** @private */ |
48 canSave_: Boolean, | 48 canSave_: Boolean, |
49 }, | 49 }, |
50 | 50 |
51 /** @override */ | 51 /** @override */ |
52 attached: function() { | 52 attached: function() { |
53 this.countryInfo = settings.address.CountryDetailManagerImpl.getInstance(); | 53 this.countryInfo = settings.address.CountryDetailManagerImpl.getInstance(); |
54 this.countryInfo.getCountryList().then(function(countryList) { | 54 this.countryInfo.getCountryList().then(countryList => { |
55 this.countries_ = countryList; | 55 this.countries_ = countryList; |
56 | 56 |
57 this.title_ = | 57 this.title_ = |
58 this.i18n(this.address.guid ? 'editAddressTitle' : 'addAddressTitle'); | 58 this.i18n(this.address.guid ? 'editAddressTitle' : 'addAddressTitle'); |
59 | 59 |
60 // |phoneNumbers| and |emailAddresses| are a single item array. | 60 // |phoneNumbers| and |emailAddresses| are a single item array. |
61 // See crbug.com/497934 for details. | 61 // See crbug.com/497934 for details. |
62 this.phoneNumber_ = | 62 this.phoneNumber_ = |
63 this.address.phoneNumbers ? this.address.phoneNumbers[0] : ''; | 63 this.address.phoneNumbers ? this.address.phoneNumbers[0] : ''; |
64 this.email_ = | 64 this.email_ = |
65 this.address.emailAddresses ? this.address.emailAddresses[0] : ''; | 65 this.address.emailAddresses ? this.address.emailAddresses[0] : ''; |
66 | 66 |
67 this.async(function() { | 67 this.async(() => { |
68 if (this.countryCode_ == this.address.countryCode) | 68 if (this.countryCode_ == this.address.countryCode) |
69 this.updateAddressWrapper_(); | 69 this.updateAddressWrapper_(); |
70 else | 70 else |
71 this.countryCode_ = this.address.countryCode; | 71 this.countryCode_ = this.address.countryCode; |
72 }.bind(this)); | 72 }); |
73 }.bind(this)); | 73 }); |
74 | 74 |
75 // Open is called on the dialog after the address wrapper has been updated. | 75 // Open is called on the dialog after the address wrapper has been updated. |
76 }, | 76 }, |
77 | 77 |
78 /** | 78 /** |
79 * Returns a class to denote how long this entry is. | 79 * Returns a class to denote how long this entry is. |
80 * @param {settings.address.AddressComponentUI} setting | 80 * @param {settings.address.AddressComponentUI} setting |
81 * @return {string} | 81 * @return {string} |
82 */ | 82 */ |
83 long_: function(setting) { | 83 long_: function(setting) { |
84 return setting.component.isLongField ? 'long' : ''; | 84 return setting.component.isLongField ? 'long' : ''; |
85 }, | 85 }, |
86 | 86 |
87 /** | 87 /** |
88 * Updates the wrapper that represents this address in the country's format. | 88 * Updates the wrapper that represents this address in the country's format. |
89 * @private | 89 * @private |
90 */ | 90 */ |
91 updateAddressWrapper_: function() { | 91 updateAddressWrapper_: function() { |
92 // Default to the last country used if no country code is provided. | 92 // Default to the last country used if no country code is provided. |
93 var countryCode = this.countryCode_ || this.countries_[0].countryCode; | 93 var countryCode = this.countryCode_ || this.countries_[0].countryCode; |
94 this.countryInfo.getAddressFormat(countryCode).then(function(format) { | 94 this.countryInfo.getAddressFormat(countryCode).then(format => { |
95 this.addressWrapper_ = format.components.map(function(component) { | 95 this.addressWrapper_ = format.components.map( |
96 return component.row.map(function(c) { | 96 component => component.row.map( |
97 return new settings.address.AddressComponentUI(this.address, c); | 97 c => new settings.address.AddressComponentUI(this.address, c))); |
98 }.bind(this)); | |
99 }.bind(this)); | |
100 | 98 |
101 // Flush dom before resize and savability updates. | 99 // Flush dom before resize and savability updates. |
102 Polymer.dom.flush(); | 100 Polymer.dom.flush(); |
103 | 101 |
104 this.updateCanSave_(); | 102 this.updateCanSave_(); |
105 | 103 |
106 this.fire('on-update-address-wrapper'); // For easier testing. | 104 this.fire('on-update-address-wrapper'); // For easier testing. |
107 | 105 |
108 var dialog = /** @type {HTMLDialogElement} */ (this.$.dialog); | 106 var dialog = /** @type {HTMLDialogElement} */ (this.$.dialog); |
109 if (!dialog.open) | 107 if (!dialog.open) |
110 dialog.showModal(); | 108 dialog.showModal(); |
111 }.bind(this)); | 109 }); |
112 }, | 110 }, |
113 | 111 |
114 updateCanSave_: function() { | 112 updateCanSave_: function() { |
115 var inputs = this.$.dialog.querySelectorAll('.address-column, select'); | 113 var inputs = this.$.dialog.querySelectorAll('.address-column, select'); |
116 | 114 |
117 for (var i = 0; i < inputs.length; ++i) { | 115 for (var i = 0; i < inputs.length; ++i) { |
118 if (inputs[i].value) { | 116 if (inputs[i].value) { |
119 this.canSave_ = true; | 117 this.canSave_ = true; |
120 this.fire('on-update-can-save'); // For easier testing. | 118 this.fire('on-update-can-save'); // For easier testing. |
121 return; | 119 return; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 } | 332 } |
335 | 333 |
336 cr.addSingletonGetter(CountryDetailManagerImpl); | 334 cr.addSingletonGetter(CountryDetailManagerImpl); |
337 | 335 |
338 return { | 336 return { |
339 AddressComponentUI: AddressComponentUI, | 337 AddressComponentUI: AddressComponentUI, |
340 CountryDetailManager: CountryDetailManager, | 338 CountryDetailManager: CountryDetailManager, |
341 CountryDetailManagerImpl: CountryDetailManagerImpl, | 339 CountryDetailManagerImpl: CountryDetailManagerImpl, |
342 }; | 340 }; |
343 }); | 341 }); |
OLD | NEW |