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 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 /** | 103 /** |
104 * Sets the default values of the options in the 'Expiration date' select | 104 * Sets the default values of the options in the 'Expiration date' select |
105 * controls. | 105 * controls. |
106 * @private | 106 * @private |
107 */ | 107 */ |
108 setDefaultSelectOptions_: function() { | 108 setDefaultSelectOptions_: function() { |
109 // Set the 'Expiration month' default options. | 109 // Set the 'Expiration month' default options. |
110 var expirationMonth = $('expiration-month'); | 110 var expirationMonth = $('expiration-month'); |
111 expirationMonth.options.length = 0; | 111 expirationMonth.options.length = 0; |
112 for (var i = 1; i <= 12; ++i) { | 112 for (var i = 1; i <= 12; ++i) { |
113 var text; | 113 var text = (i < 10 ? '0' : '') + i; |
114 if (i < 10) | |
115 text = '0' + i; | |
116 else | |
117 text = i; | |
118 | 114 |
119 var option = document.createElement('option'); | 115 var option = document.createElement('option'); |
120 option.text = text; | 116 option.text = option.value = text; |
121 option.value = text; | |
122 expirationMonth.add(option, null); | 117 expirationMonth.add(option, null); |
123 } | 118 } |
124 | 119 |
125 // Set the 'Expiration year' default options. | 120 // Set the 'Expiration year' default options. |
126 var expirationYear = $('expiration-year'); | 121 var expirationYear = $('expiration-year'); |
127 expirationYear.options.length = 0; | 122 expirationYear.options.length = 0; |
128 | 123 |
129 var date = new Date(); | 124 var date = new Date(); |
130 var year = parseInt(date.getFullYear(), 10); | 125 var year = parseInt(date.getFullYear(), 10); |
131 for (var i = 0; i < 10; ++i) { | 126 for (var i = 0; i < 10; ++i) { |
132 var text = year + i; | 127 var text = year + i; |
133 var option = document.createElement('option'); | 128 var option = document.createElement('option'); |
134 option.text = text; | 129 option.text = String(text); |
135 option.value = text; | 130 option.value = text; |
136 expirationYear.add(option, null); | 131 expirationYear.add(option, null); |
137 } | 132 } |
138 }, | 133 }, |
139 | 134 |
140 /** | 135 /** |
141 * Clears the value of each input field. | 136 * Clears the value of each input field. |
142 * @private | 137 * @private |
143 */ | 138 */ |
144 clearInputFields_: function() { | 139 clearInputFields_: function() { |
145 $('name-on-card').value = ''; | 140 $('name-on-card').value = ''; |
146 $('credit-card-number').value = ''; | 141 $('credit-card-number').value = ''; |
147 $('expiration-month').selectedIndex = 0; | 142 $('expiration-month').selectedIndex = 0; |
148 $('expiration-year').selectedIndex = 0; | 143 $('expiration-year').selectedIndex = 0; |
149 | 144 |
150 // Reset the enabled status of the 'Ok' button. | 145 // Reset the enabled status of the 'Ok' button. |
151 this.inputFieldChanged_(); | 146 this.inputFieldChanged_(); |
152 }, | 147 }, |
153 | 148 |
154 /** | 149 /** |
155 * Sets the value of each input field according to |creditCard| | 150 * Sets the value of each input field according to |creditCard| |
| 151 * @param {CreditCardData} creditCard |
156 * @private | 152 * @private |
157 */ | 153 */ |
158 setInputFields_: function(creditCard) { | 154 setInputFields_: function(creditCard) { |
159 $('name-on-card').value = creditCard.nameOnCard; | 155 $('name-on-card').value = creditCard.nameOnCard; |
160 $('credit-card-number').value = creditCard.creditCardNumber; | 156 $('credit-card-number').value = creditCard.creditCardNumber; |
161 | 157 |
162 // The options for the year select control may be out-dated at this point, | 158 // The options for the year select control may be out-dated at this point, |
163 // e.g. the user opened the options page before midnight on New Year's Eve | 159 // e.g. the user opened the options page before midnight on New Year's Eve |
164 // and then loaded a credit card profile to edit in the new year, so | 160 // and then loaded a credit card profile to edit in the new year, so |
165 // reload the select options just to be safe. | 161 // reload the select options just to be safe. |
166 this.setDefaultSelectOptions_(); | 162 this.setDefaultSelectOptions_(); |
167 | 163 |
168 var idx = parseInt(creditCard.expirationMonth, 10); | 164 var idx = parseInt(creditCard.expirationMonth, 10); |
169 $('expiration-month').selectedIndex = idx - 1; | 165 $('expiration-month').selectedIndex = idx - 1; |
170 | 166 |
171 expYear = creditCard.expirationYear; | 167 var expYear = creditCard.expirationYear; |
172 var date = new Date(); | 168 var date = new Date(); |
173 var year = parseInt(date.getFullYear(), 10); | 169 var year = parseInt(date.getFullYear(), 10); |
174 for (var i = 0; i < 10; ++i) { | 170 for (var i = 0; i < 10; ++i) { |
175 var text = year + i; | 171 var text = year + i; |
176 if (expYear == String(text)) | 172 if (expYear == String(text)) |
177 $('expiration-year').selectedIndex = i; | 173 $('expiration-year').selectedIndex = i; |
178 } | 174 } |
179 }, | 175 }, |
180 | 176 |
181 /** | 177 /** |
182 * Called to prepare the overlay when a new card is being added. | 178 * Called to prepare the overlay when a new card is being added. |
183 * @private | 179 * @private |
184 */ | 180 */ |
185 prepForNewCard_: function() { | 181 prepForNewCard_: function() { |
186 // Focus the first element. | 182 // Focus the first element. |
187 this.pageDiv.querySelector('input').focus(); | 183 this.pageDiv.querySelector('input').focus(); |
188 }, | 184 }, |
189 | 185 |
190 /** | 186 /** |
191 * Loads the credit card data from |creditCard|, sets the input fields based | 187 * Loads the credit card data from |creditCard|, sets the input fields based |
192 * on this data and stores the GUID of the credit card. | 188 * on this data and stores the GUID of the credit card. |
| 189 * @param {CreditCardData} creditCard |
193 * @private | 190 * @private |
194 */ | 191 */ |
195 loadCreditCard_: function(creditCard) { | 192 loadCreditCard_: function(creditCard) { |
196 this.setInputFields_(creditCard); | 193 this.setInputFields_(creditCard); |
197 this.inputFieldChanged_(); | 194 this.inputFieldChanged_(); |
198 this.guid_ = creditCard.guid; | 195 this.guid_ = creditCard.guid; |
199 }, | 196 }, |
200 }; | 197 }; |
201 | 198 |
202 AutofillEditCreditCardOverlay.prepForNewCard = function() { | 199 AutofillEditCreditCardOverlay.prepForNewCard = function() { |
203 AutofillEditCreditCardOverlay.getInstance().prepForNewCard_(); | 200 AutofillEditCreditCardOverlay.getInstance().prepForNewCard_(); |
204 }; | 201 }; |
205 | 202 |
206 AutofillEditCreditCardOverlay.loadCreditCard = function(creditCard) { | 203 AutofillEditCreditCardOverlay.loadCreditCard = function(creditCard) { |
207 AutofillEditCreditCardOverlay.getInstance().loadCreditCard_(creditCard); | 204 AutofillEditCreditCardOverlay.getInstance().loadCreditCard_(creditCard); |
208 }; | 205 }; |
209 | 206 |
210 AutofillEditCreditCardOverlay.setTitle = function(title) { | 207 AutofillEditCreditCardOverlay.setTitle = function(title) { |
211 $('autofill-credit-card-title').textContent = title; | 208 $('autofill-credit-card-title').textContent = title; |
212 }; | 209 }; |
213 | 210 |
214 // Export | 211 // Export |
215 return { | 212 return { |
216 AutofillEditCreditCardOverlay: AutofillEditCreditCardOverlay | 213 AutofillEditCreditCardOverlay: AutofillEditCreditCardOverlay |
217 }; | 214 }; |
218 }); | 215 }); |
OLD | NEW |