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

Side by Side Diff: chrome/browser/resources/options/autofill_edit_creditcard_overlay.js

Issue 6258022: DOMUI: Fix AF CC field some more. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/resources/options/options_page.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 credit card. 8 // The GUID of the loaded credit card.
9 var guid_; 9 var guid_;
10 10
(...skipping 28 matching lines...) Expand all
39 OptionsPage.prototype.initializePage.call(this); 39 OptionsPage.prototype.initializePage.call(this);
40 40
41 var self = this; 41 var self = this;
42 $('autoFillEditCreditCardCancelButton').onclick = function(event) { 42 $('autoFillEditCreditCardCancelButton').onclick = function(event) {
43 self.dismissOverlay_(); 43 self.dismissOverlay_();
44 } 44 }
45 $('autoFillEditCreditCardApplyButton').onclick = function(event) { 45 $('autoFillEditCreditCardApplyButton').onclick = function(event) {
46 self.saveCreditCard_(); 46 self.saveCreditCard_();
47 self.dismissOverlay_(); 47 self.dismissOverlay_();
48 } 48 }
49 $('creditCardNumber').onkeydown = this.onTextInput_.bind(this);
50 $('creditCardNumber').addEventListener('textInput',
51 this.onTextInput_.bind(this));
52 49
53 self.guid_ = ''; 50 self.guid_ = '';
54 self.storedCCNumber_ = ''; 51 self.storedCCNumber_ = '';
55 self.hasEditedNumber_ = false; 52 self.hasEditedNumber_ = false;
56 self.clearInputFields_(); 53 self.clearInputFields_();
57 self.connectInputEvents_(); 54 self.connectInputEvents_();
58 self.setDefaultSelectOptions_(); 55 self.setDefaultSelectOptions_();
59 }, 56 },
60 57
61 /** 58 /**
62 * Handles the textInput and keydown events.
63 * @private
64 */
65 onTextInput_: function(event) {
66 // For some reason, the textInput event doesn't consider
67 // backspace/deletion an input event, so we have to handle those here.
68 // 8 - backspace
69 // 46 - delete
70 if (event.type == 'keydown' && event.keyCode != '8' &&
71 event.keyCode != '46')
72 return;
73
74 // If the user hasn't edited the text yet, delete it all on edit.
75 if (!this.hasEditedNumber_ &&
76 $('creditCardNumber').value != this.storedCCNumber_) {
77 this.hasEditedNumber_ = true;
78 $('creditCardNumber').value = '';
79 }
80 },
81
82 /**
83 * Clears any uncommitted input, and dismisses the overlay. 59 * Clears any uncommitted input, and dismisses the overlay.
84 * @private 60 * @private
85 */ 61 */
86 dismissOverlay_: function() { 62 dismissOverlay_: function() {
87 this.clearInputFields_(); 63 this.clearInputFields_();
88 this.guid_ = ''; 64 this.guid_ = '';
89 this.storedCCNumber_ = ''; 65 this.storedCCNumber_ = '';
90 this.hasEditedNumber_ = false; 66 this.hasEditedNumber_ = false;
91 OptionsPage.clearOverlays(); 67 OptionsPage.clearOverlays();
92 }, 68 },
(...skipping 18 matching lines...) Expand all
111 chrome.send('setCreditCard', creditCard); 87 chrome.send('setCreditCard', creditCard);
112 }, 88 },
113 89
114 /** 90 /**
115 * Connects each input field to the inputFieldChanged_() method that enables 91 * Connects each input field to the inputFieldChanged_() method that enables
116 * or disables the 'Ok' button based on whether all the fields are empty or 92 * or disables the 'Ok' button based on whether all the fields are empty or
117 * not. 93 * not.
118 * @private 94 * @private
119 */ 95 */
120 connectInputEvents_: function() { 96 connectInputEvents_: function() {
121 var self = this;
122 $('nameOnCard').oninput = $('creditCardNumber').oninput = 97 $('nameOnCard').oninput = $('creditCardNumber').oninput =
123 $('expirationMonth').onchange = $('expirationYear').onchange = 98 $('expirationMonth').onchange = $('expirationYear').onchange =
124 function(event) { 99 this.inputFieldChanged_.bind(this);
125 self.inputFieldChanged_();
126 }
127 }, 100 },
128 101
129 /** 102 /**
130 * 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'
131 * button if all of the fields are empty. 104 * button if all of the fields are empty.
132 * @private 105 * @private
133 */ 106 */
134 inputFieldChanged_: function() { 107 inputFieldChanged_: function(event) {
135 var disabled = !$('nameOnCard').value && !$('creditCardNumber').value; 108 var disabled = !$('nameOnCard').value && !$('creditCardNumber').value;
136 $('autoFillEditCreditCardApplyButton').disabled = disabled; 109 $('autoFillEditCreditCardApplyButton').disabled = disabled;
110
111 // If the user hasn't edited the text yet, delete it all on edit.
112 if (!this.hasEditedNumber_ &&
113 event && event.target == $('creditCardNumber') &&
arv (Not doing code reviews) 2011/01/26 19:27:35 Why would event be undefined?
arv (Not doing code reviews) 2011/01/26 19:27:35 Please create a var for $('creditCardNumber') so t
James Hawkins 2011/01/26 19:38:30 This method is called on overlay load w/out a para
James Hawkins 2011/01/26 19:38:30 Done.
arv (Not doing code reviews) 2011/01/26 20:00:41 Please rename the param to opt_event and document
James Hawkins 2011/01/26 21:31:36 Done.
114 $('creditCardNumber').value != this.storedCCNumber_) {
115 this.hasEditedNumber_ = true;
116 $('creditCardNumber').value = '';
117 }
137 }, 118 },
138 119
139 /** 120 /**
140 * Sets the default values of the options in the 'Expiration date' select 121 * Sets the default values of the options in the 'Expiration date' select
141 * controls. 122 * controls.
142 * @private 123 * @private
143 */ 124 */
144 setDefaultSelectOptions_: function() { 125 setDefaultSelectOptions_: function() {
145 // Set the 'Expiration month' default options. 126 // Set the 'Expiration month' default options.
146 var expirationMonth = $('expirationMonth'); 127 var expirationMonth = $('expirationMonth');
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 /** 195 /**
215 * Loads the credit card data from |creditCard|, sets the input fields based 196 * Loads the credit card data from |creditCard|, sets the input fields based
216 * on this data and stores the GUID of the credit card. 197 * on this data and stores the GUID of the credit card.
217 * @private 198 * @private
218 */ 199 */
219 loadCreditCard_: function(creditCard) { 200 loadCreditCard_: function(creditCard) {
220 this.setInputFields_(creditCard); 201 this.setInputFields_(creditCard);
221 this.inputFieldChanged_(); 202 this.inputFieldChanged_();
222 this.guid_ = creditCard['guid']; 203 this.guid_ = creditCard['guid'];
223 this.storedCCNumber_ = creditCard['creditCardNumber']; 204 this.storedCCNumber_ = creditCard['creditCardNumber'];
205 this.hasEditedNumber_ = $('creditCardNumber').value.length == 0;
224 }, 206 },
225 }; 207 };
226 208
227 AutoFillEditCreditCardOverlay.clearInputFields = function(title) { 209 AutoFillEditCreditCardOverlay.clearInputFields = function(title) {
228 AutoFillEditCreditCardOverlay.getInstance().clearInputFields_(); 210 AutoFillEditCreditCardOverlay.getInstance().clearInputFields_();
229 }; 211 };
230 212
231 AutoFillEditCreditCardOverlay.loadCreditCard = function(creditCard) { 213 AutoFillEditCreditCardOverlay.loadCreditCard = function(creditCard) {
232 AutoFillEditCreditCardOverlay.getInstance().loadCreditCard_(creditCard); 214 AutoFillEditCreditCardOverlay.getInstance().loadCreditCard_(creditCard);
233 }; 215 };
234 216
235 AutoFillEditCreditCardOverlay.setTitle = function(title) { 217 AutoFillEditCreditCardOverlay.setTitle = function(title) {
236 $('autoFillCreditCardTitle').textContent = title; 218 $('autoFillCreditCardTitle').textContent = title;
237 }; 219 };
238 220
239 // Export 221 // Export
240 return { 222 return {
241 AutoFillEditCreditCardOverlay: AutoFillEditCreditCardOverlay 223 AutoFillEditCreditCardOverlay: AutoFillEditCreditCardOverlay
242 }; 224 };
243 225
244 }); 226 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/options/options_page.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698