| 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 | 8 |
| 9 /** | 9 /** |
| 10 * AutofillEditCreditCardOverlay class | 10 * AutofillEditCreditCardOverlay class |
| 11 * Encapsulated handling of the 'Add Page' overlay page. | 11 * Encapsulated handling of the 'Add Page' overlay page. |
| 12 * @class | 12 * @class |
| 13 */ | 13 */ |
| 14 function AutofillEditCreditCardOverlay() { | 14 function AutofillEditCreditCardOverlay() { |
| 15 Page.call(this, 'autofillEditCreditCard', | 15 Page.call( |
| 16 loadTimeData.getString('autofillEditCreditCardTitle'), | 16 this, 'autofillEditCreditCard', |
| 17 'autofill-edit-credit-card-overlay'); | 17 loadTimeData.getString('autofillEditCreditCardTitle'), |
| 18 'autofill-edit-credit-card-overlay'); |
| 18 } | 19 } |
| 19 | 20 |
| 20 cr.addSingletonGetter(AutofillEditCreditCardOverlay); | 21 cr.addSingletonGetter(AutofillEditCreditCardOverlay); |
| 21 | 22 |
| 22 AutofillEditCreditCardOverlay.prototype = { | 23 AutofillEditCreditCardOverlay.prototype = { |
| 23 __proto__: Page.prototype, | 24 __proto__: Page.prototype, |
| 24 | 25 |
| 25 /** @override */ | 26 /** @override */ |
| 26 initializePage: function() { | 27 initializePage: function() { |
| 27 Page.prototype.initializePage.call(this); | 28 Page.prototype.initializePage.call(this); |
| 28 | 29 |
| 29 var self = this; | 30 var self = this; |
| 30 $('autofill-edit-credit-card-cancel-button').onclick = function(event) { | 31 $('autofill-edit-credit-card-cancel-button').onclick = function(event) { |
| 31 self.dismissOverlay_(); | 32 self.dismissOverlay_(); |
| 32 }; | 33 }; |
| 33 $('autofill-edit-credit-card-apply-button').onclick = function(event) { | 34 $('autofill-edit-credit-card-apply-button').onclick = function(event) { |
| 34 self.saveCreditCard_(); | 35 self.saveCreditCard_(); |
| 35 self.dismissOverlay_(); | 36 self.dismissOverlay_(); |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 self.guid_ = ''; | 39 self.guid_ = ''; |
| 39 self.clearInputFields_(); | 40 self.clearInputFields_(); |
| 40 self.connectInputEvents_(); | 41 self.connectInputEvents_(); |
| 41 self.setDefaultSelectOptions_(); | 42 self.setDefaultSelectOptions_(); |
| 42 }, | 43 }, |
| 43 | 44 |
| 44 /** | 45 /** |
| 45 * Specifically catch the situations in which the overlay is cancelled | 46 * Specifically catch the situations in which the overlay is cancelled |
| 46 * externally (e.g. by pressing <Esc>), so that the input fields and | 47 * externally (e.g. by pressing <Esc>), so that the input fields and |
| 47 * GUID can be properly cleared. | 48 * GUID can be properly cleared. |
| 48 * @override | 49 * @override |
| 49 */ | 50 */ |
| 50 handleCancel: function() { | 51 handleCancel: function() { |
| 51 this.dismissOverlay_(); | 52 this.dismissOverlay_(); |
| 52 }, | 53 }, |
| 53 | 54 |
| 54 /** | 55 /** |
| 55 * Clears any uncommitted input, and dismisses the overlay. | 56 * Clears any uncommitted input, and dismisses the overlay. |
| 56 * @private | 57 * @private |
| 57 */ | 58 */ |
| 58 dismissOverlay_: function() { | 59 dismissOverlay_: function() { |
| 59 this.clearInputFields_(); | 60 this.clearInputFields_(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 creditCard[0] = this.guid_; | 72 creditCard[0] = this.guid_; |
| 72 creditCard[1] = $('name-on-card').value; | 73 creditCard[1] = $('name-on-card').value; |
| 73 creditCard[2] = $('credit-card-number').value; | 74 creditCard[2] = $('credit-card-number').value; |
| 74 creditCard[3] = $('expiration-month').value; | 75 creditCard[3] = $('expiration-month').value; |
| 75 creditCard[4] = $('expiration-year').value; | 76 creditCard[4] = $('expiration-year').value; |
| 76 chrome.send('setCreditCard', creditCard); | 77 chrome.send('setCreditCard', creditCard); |
| 77 | 78 |
| 78 // If the GUID is empty, this form is being used to add a new card, | 79 // If the GUID is empty, this form is being used to add a new card, |
| 79 // rather than edit an existing one. | 80 // rather than edit an existing one. |
| 80 if (!this.guid_.length) { | 81 if (!this.guid_.length) { |
| 81 chrome.send('coreOptionsUserMetricsAction', | 82 chrome.send( |
| 82 ['Options_AutofillCreditCardAdded']); | 83 'coreOptionsUserMetricsAction', |
| 84 ['Options_AutofillCreditCardAdded']); |
| 83 } | 85 } |
| 84 }, | 86 }, |
| 85 | 87 |
| 86 /** | 88 /** |
| 87 * Connects each input field to the inputFieldChanged_() method that enables | 89 * Connects each input field to the inputFieldChanged_() method that enables |
| 88 * or disables the 'Ok' button based on whether all the fields are empty or | 90 * or disables the 'Ok' button based on whether all the fields are empty or |
| 89 * not. | 91 * not. |
| 90 * @private | 92 * @private |
| 91 */ | 93 */ |
| 92 connectInputEvents_: function() { | 94 connectInputEvents_: function() { |
| 93 var ccNumber = $('credit-card-number'); | 95 var ccNumber = $('credit-card-number'); |
| 94 $('name-on-card').oninput = ccNumber.oninput = | 96 $('name-on-card').oninput = ccNumber.oninput = |
| 95 $('expiration-month').onchange = $('expiration-year').onchange = | 97 $('expiration-month').onchange = $('expiration-year').onchange = |
| 96 this.inputFieldChanged_.bind(this); | 98 this.inputFieldChanged_.bind(this); |
| 97 }, | 99 }, |
| 98 | 100 |
| 99 /** | 101 /** |
| 100 * Checks the values of each of the input fields and disables the 'Ok' | 102 * Checks the values of each of the input fields and disables the 'Ok' |
| 101 * button if all of the fields are empty. | 103 * button if all of the fields are empty. |
| 102 * @param {Event} opt_event Optional data for the 'input' event. | 104 * @param {Event} opt_event Optional data for the 'input' event. |
| 103 * @private | 105 * @private |
| 104 */ | 106 */ |
| 105 inputFieldChanged_: function(opt_event) { | 107 inputFieldChanged_: function(opt_event) { |
| 106 var disabled = !$('name-on-card').value.trim() && | 108 var disabled = !$('name-on-card').value.trim() && |
| 107 !$('credit-card-number').value.trim(); | 109 !$('credit-card-number').value.trim(); |
| 108 $('autofill-edit-credit-card-apply-button').disabled = disabled; | 110 $('autofill-edit-credit-card-apply-button').disabled = disabled; |
| 109 }, | 111 }, |
| 110 | 112 |
| 111 /** | 113 /** |
| 112 * Sets the default values of the options in the 'Expiration date' select | 114 * Sets the default values of the options in the 'Expiration date' select |
| 113 * controls. | 115 * controls. |
| 114 * @private | 116 * @private |
| 115 */ | 117 */ |
| 116 setDefaultSelectOptions_: function() { | 118 setDefaultSelectOptions_: function() { |
| 117 // Set the 'Expiration month' default options. | 119 // Set the 'Expiration month' default options. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 212 |
| 211 AutofillEditCreditCardOverlay.loadCreditCard = function(creditCard) { | 213 AutofillEditCreditCardOverlay.loadCreditCard = function(creditCard) { |
| 212 AutofillEditCreditCardOverlay.getInstance().loadCreditCard_(creditCard); | 214 AutofillEditCreditCardOverlay.getInstance().loadCreditCard_(creditCard); |
| 213 }; | 215 }; |
| 214 | 216 |
| 215 AutofillEditCreditCardOverlay.setTitle = function(title) { | 217 AutofillEditCreditCardOverlay.setTitle = function(title) { |
| 216 $('autofill-credit-card-title').textContent = title; | 218 $('autofill-credit-card-title').textContent = title; |
| 217 }; | 219 }; |
| 218 | 220 |
| 219 // Export | 221 // Export |
| 220 return { | 222 return {AutofillEditCreditCardOverlay: AutofillEditCreditCardOverlay}; |
| 221 AutofillEditCreditCardOverlay: AutofillEditCreditCardOverlay | |
| 222 }; | |
| 223 }); | 223 }); |
| OLD | NEW |