OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 */ var Page = cr.ui.pageManager.Page; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
9 | 9 |
10 /** | 10 /** |
11 * AutofillEditAddressOverlay class | 11 * AutofillEditAddressOverlay class |
12 * Encapsulated handling of the 'Add Page' overlay page. | 12 * Encapsulated handling of the 'Add Page' overlay page. |
13 * @constructor | 13 * @constructor |
14 * @extends {cr.ui.pageManager.Page} | 14 * @extends {cr.ui.pageManager.Page} |
15 */ | 15 */ |
16 function AutofillEditAddressOverlay() { | 16 function AutofillEditAddressOverlay() { |
17 Page.call(this, 'autofillEditAddress', | 17 Page.call( |
18 loadTimeData.getString('autofillEditAddressTitle'), | 18 this, 'autofillEditAddress', |
19 'autofill-edit-address-overlay'); | 19 loadTimeData.getString('autofillEditAddressTitle'), |
| 20 'autofill-edit-address-overlay'); |
20 } | 21 } |
21 | 22 |
22 cr.addSingletonGetter(AutofillEditAddressOverlay); | 23 cr.addSingletonGetter(AutofillEditAddressOverlay); |
23 | 24 |
24 AutofillEditAddressOverlay.prototype = { | 25 AutofillEditAddressOverlay.prototype = { |
25 __proto__: Page.prototype, | 26 __proto__: Page.prototype, |
26 | 27 |
27 /** | 28 /** |
28 * The GUID of the loaded address. | 29 * The GUID of the loaded address. |
29 * @type {string} | 30 * @type {string} |
(...skipping 29 matching lines...) Expand all Loading... |
59 $('autofill-edit-address-apply-button').onclick = function(event) { | 60 $('autofill-edit-address-apply-button').onclick = function(event) { |
60 // Blur active element to ensure that pending changes are committed. | 61 // Blur active element to ensure that pending changes are committed. |
61 if (document.activeElement) | 62 if (document.activeElement) |
62 document.activeElement.blur(); | 63 document.activeElement.blur(); |
63 self.saveAddress_(); | 64 self.saveAddress_(); |
64 self.dismissOverlay_(); | 65 self.dismissOverlay_(); |
65 }; | 66 }; |
66 | 67 |
67 this.guid_ = ''; | 68 this.guid_ = ''; |
68 this.populateCountryList_(); | 69 this.populateCountryList_(); |
69 this.rebuildInputFields_(/** @type {Array<Array<Object>>} */( | 70 this.rebuildInputFields_(/** @type {Array<Array<Object>>} */ ( |
70 loadTimeData.getValue('autofillDefaultCountryComponents'))); | 71 loadTimeData.getValue('autofillDefaultCountryComponents'))); |
71 this.languageCode_ = | 72 this.languageCode_ = |
72 loadTimeData.getString('autofillDefaultCountryLanguageCode'); | 73 loadTimeData.getString('autofillDefaultCountryLanguageCode'); |
73 this.connectInputEvents_(); | 74 this.connectInputEvents_(); |
74 this.setInputFields_({}); | 75 this.setInputFields_({}); |
75 this.getCountrySwitcher_().onchange = function(event) { | 76 this.getCountrySwitcher_().onchange = function(event) { |
76 self.countryChanged_(); | 77 self.countryChanged_(); |
77 }; | 78 }; |
78 }, | 79 }, |
79 | 80 |
80 /** | 81 /** |
81 * Specifically catch the situations in which the overlay is cancelled | 82 * Specifically catch the situations in which the overlay is cancelled |
82 * externally (e.g. by pressing <Esc>), so that the input fields and | 83 * externally (e.g. by pressing <Esc>), so that the input fields and |
83 * GUID can be properly cleared. | 84 * GUID can be properly cleared. |
84 * @override | 85 * @override |
85 */ | 86 */ |
86 handleCancel: function() { | 87 handleCancel: function() { |
87 this.dismissOverlay_(); | 88 this.dismissOverlay_(); |
88 }, | 89 }, |
89 | 90 |
90 /** | 91 /** |
91 * Clears any uncommitted input, resets the stored GUID and dismisses the | 92 * Clears any uncommitted input, resets the stored GUID and dismisses the |
92 * overlay. | 93 * overlay. |
93 * @private | 94 * @private |
94 */ | 95 */ |
95 dismissOverlay_: function() { | 96 dismissOverlay_: function() { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 inputFields['country'] || loadTimeData.getString('defaultCountryCode'), | 169 inputFields['country'] || loadTimeData.getString('defaultCountryCode'), |
169 inputFields['phone'] || [], | 170 inputFields['phone'] || [], |
170 inputFields['email'] || [], | 171 inputFields['email'] || [], |
171 this.languageCode_, | 172 this.languageCode_, |
172 ]; | 173 ]; |
173 chrome.send('setAddress', address); | 174 chrome.send('setAddress', address); |
174 | 175 |
175 // If the GUID is empty, this form is being used to add a new address, | 176 // If the GUID is empty, this form is being used to add a new address, |
176 // rather than edit an existing one. | 177 // rather than edit an existing one. |
177 if (!this.guid_.length) { | 178 if (!this.guid_.length) { |
178 chrome.send('coreOptionsUserMetricsAction', | 179 chrome.send( |
179 ['Options_AutofillAddressAdded']); | 180 'coreOptionsUserMetricsAction', ['Options_AutofillAddressAdded']); |
180 } | 181 } |
181 }, | 182 }, |
182 | 183 |
183 /** | 184 /** |
184 * Connects each input field to the inputFieldChanged_() method that enables | 185 * Connects each input field to the inputFieldChanged_() method that enables |
185 * or disables the 'Ok' button based on whether all the fields are empty or | 186 * or disables the 'Ok' button based on whether all the fields are empty or |
186 * not. | 187 * not. |
187 * @private | 188 * @private |
188 */ | 189 */ |
189 connectInputEvents_: function() { | 190 connectInputEvents_: function() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 * @private | 230 * @private |
230 */ | 231 */ |
231 populateCountryList_: function() { | 232 populateCountryList_: function() { |
232 var countryList = loadTimeData.getValue('autofillCountrySelectList'); | 233 var countryList = loadTimeData.getValue('autofillCountrySelectList'); |
233 | 234 |
234 // Add the countries to the country <select>. | 235 // Add the countries to the country <select>. |
235 var countrySelect = this.getCountrySwitcher_(); | 236 var countrySelect = this.getCountrySwitcher_(); |
236 // Add an empty option. | 237 // Add an empty option. |
237 countrySelect.appendChild(new Option('', '')); | 238 countrySelect.appendChild(new Option('', '')); |
238 for (var i = 0; i < countryList.length; i++) { | 239 for (var i = 0; i < countryList.length; i++) { |
239 var option = new Option(countryList[i].name, | 240 var option = new Option(countryList[i].name, countryList[i].value); |
240 countryList[i].value); | |
241 option.disabled = countryList[i].value == 'separator'; | 241 option.disabled = countryList[i].value == 'separator'; |
242 countrySelect.appendChild(option); | 242 countrySelect.appendChild(option); |
243 } | 243 } |
244 }, | 244 }, |
245 | 245 |
246 /** | 246 /** |
247 * Called to prepare the overlay when a new address is being added. | 247 * Called to prepare the overlay when a new address is being added. |
248 * @private | 248 * @private |
249 */ | 249 */ |
250 prepForNewAddress_: function() { | 250 prepForNewAddress_: function() { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 337 |
338 AutofillEditAddressOverlay.loadAddressComponents = function(input) { | 338 AutofillEditAddressOverlay.loadAddressComponents = function(input) { |
339 AutofillEditAddressOverlay.getInstance().loadAddressComponents_(input); | 339 AutofillEditAddressOverlay.getInstance().loadAddressComponents_(input); |
340 }; | 340 }; |
341 | 341 |
342 AutofillEditAddressOverlay.setTitle = function(title) { | 342 AutofillEditAddressOverlay.setTitle = function(title) { |
343 $('autofill-address-title').textContent = title; | 343 $('autofill-address-title').textContent = title; |
344 }; | 344 }; |
345 | 345 |
346 // Export | 346 // Export |
347 return { | 347 return {AutofillEditAddressOverlay: AutofillEditAddressOverlay}; |
348 AutofillEditAddressOverlay: AutofillEditAddressOverlay | |
349 }; | |
350 }); | 348 }); |
OLD | NEW |