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 'settings-credit-card-edit-dialog' is the dialog that allows | 6 * @fileoverview 'settings-credit-card-edit-dialog' is the dialog that allows |
7 * editing or creating a credit card entry. | 7 * editing or creating a credit card entry. |
8 */ | 8 */ |
9 | 9 |
10 (function() { | 10 (function() { |
(...skipping 16 matching lines...) Expand all Loading... |
27 */ | 27 */ |
28 title_: String, | 28 title_: String, |
29 | 29 |
30 /** | 30 /** |
31 * The list of months to show in the dropdown. | 31 * The list of months to show in the dropdown. |
32 * @private {!Array<string>} | 32 * @private {!Array<string>} |
33 */ | 33 */ |
34 monthList_: { | 34 monthList_: { |
35 type: Array, | 35 type: Array, |
36 value: [ | 36 value: [ |
37 '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', | 37 '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12' |
38 ], | 38 ], |
39 }, | 39 }, |
40 | 40 |
41 /** | 41 /** |
42 * The list of years to show in the dropdown. | 42 * The list of years to show in the dropdown. |
43 * @private {!Array<string>} | 43 * @private {!Array<string>} |
44 */ | 44 */ |
45 yearList_: Array, | 45 yearList_: Array, |
46 | 46 |
47 /** @private */ | 47 /** @private */ |
48 expirationYear_: String, | 48 expirationYear_: String, |
49 | 49 |
50 /** @private {string|undefined} */ | 50 /** @private {string|undefined} */ |
51 expirationMonth_: String, | 51 expirationMonth_: String, |
52 }, | 52 }, |
53 | 53 |
54 behaviors: [ | 54 behaviors: [ |
55 I18nBehavior, | 55 I18nBehavior, |
56 ], | 56 ], |
57 | 57 |
58 /** | 58 /** |
59 * @return {boolean} True iff the provided expiration date is passed. | 59 * @return {boolean} True iff the provided expiration date is passed. |
60 * @private | 60 * @private |
61 */ | 61 */ |
62 checkIfCardExpired_: function(expirationMonth_, expirationYear_) { | 62 checkIfCardExpired_: function(expirationMonth_, expirationYear_) { |
63 var now = new Date(); | 63 var now = new Date(); |
64 return (expirationYear_ < now.getFullYear() || | 64 return ( |
65 (expirationYear_ == now.getFullYear() && | 65 expirationYear_ < now.getFullYear() || |
66 expirationMonth_ <= now.getMonth())); | 66 (expirationYear_ == now.getFullYear() && |
| 67 expirationMonth_ <= now.getMonth())); |
67 }, | 68 }, |
68 | 69 |
69 /** @override */ | 70 /** @override */ |
70 attached: function() { | 71 attached: function() { |
71 this.title_ = this.i18n( | 72 this.title_ = this.i18n( |
72 this.creditCard.guid ? 'editCreditCardTitle' : 'addCreditCardTitle'); | 73 this.creditCard.guid ? 'editCreditCardTitle' : 'addCreditCardTitle'); |
73 | 74 |
74 // Needed to initialize the disabled state of the Save button. | 75 // Needed to initialize the disabled state of the Save button. |
75 this.onCreditCardNameOrNumberChanged_(); | 76 this.onCreditCardNameOrNumberChanged_(); |
76 | 77 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 /** | 121 /** |
121 * Handler for tapping the save button. | 122 * Handler for tapping the save button. |
122 * @private | 123 * @private |
123 */ | 124 */ |
124 onSaveButtonTap_: function() { | 125 onSaveButtonTap_: function() { |
125 if (!this.saveEnabled_()) | 126 if (!this.saveEnabled_()) |
126 return; | 127 return; |
127 | 128 |
128 // If the card is expired, reflect the error to the user. | 129 // If the card is expired, reflect the error to the user. |
129 // Otherwise, update the card, save and close the dialog. | 130 // Otherwise, update the card, save and close the dialog. |
130 if (!this.checkIfCardExpired_(this.expirationMonth_, | 131 if (!this.checkIfCardExpired_( |
131 this.expirationYear_)) { | 132 this.expirationMonth_, this.expirationYear_)) { |
132 this.creditCard.expirationYear = this.expirationYear_; | 133 this.creditCard.expirationYear = this.expirationYear_; |
133 this.creditCard.expirationMonth = this.expirationMonth_; | 134 this.creditCard.expirationMonth = this.expirationMonth_; |
134 this.fire('save-credit-card', this.creditCard); | 135 this.fire('save-credit-card', this.creditCard); |
135 this.close(); | 136 this.close(); |
136 } | 137 } |
137 }, | 138 }, |
138 | 139 |
139 /** @private */ | 140 /** @private */ |
140 onMonthChange_: function() { | 141 onMonthChange_: function() { |
141 this.expirationMonth_ = this.monthList_[this.$.month.selectedIndex]; | 142 this.expirationMonth_ = this.monthList_[this.$.month.selectedIndex]; |
142 }, | 143 }, |
143 | 144 |
144 /** @private */ | 145 /** @private */ |
145 onYearChange_: function() { | 146 onYearChange_: function() { |
146 this.expirationYear_ = this.yearList_[this.$.year.selectedIndex]; | 147 this.expirationYear_ = this.yearList_[this.$.year.selectedIndex]; |
147 }, | 148 }, |
148 | 149 |
149 /** @private */ | 150 /** @private */ |
150 onCreditCardNameOrNumberChanged_: function() { | 151 onCreditCardNameOrNumberChanged_: function() { |
151 this.$.saveButton.disabled = !this.saveEnabled_(); | 152 this.$.saveButton.disabled = !this.saveEnabled_(); |
152 }, | 153 }, |
153 | 154 |
154 /** @private */ | 155 /** @private */ |
155 saveEnabled_: function() { | 156 saveEnabled_: function() { |
156 return (this.creditCard.name && this.creditCard.name.trim()) || | 157 return (this.creditCard.name && this.creditCard.name.trim()) || |
157 (this.creditCard.cardNumber && this.creditCard.cardNumber.trim()); | 158 (this.creditCard.cardNumber && this.creditCard.cardNumber.trim()); |
158 }, | 159 }, |
159 }); | 160 }); |
160 })(); | 161 })(); |
OLD | NEW |