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
3 // found in the LICENSE file.
7 * creditCardNumber: string,
8 * expirationMonth: string,
9 * expirationYear: string,
13 * @see chrome/browser/ui/webui/options/autofill_options_handler.cc
17 cr
.define('options', function() {
18 var Page
= cr
.ui
.pageManager
.Page
;
19 var PageManager
= cr
.ui
.pageManager
.PageManager
;
20 var ArrayDataModel
= cr
.ui
.ArrayDataModel
;
22 /////////////////////////////////////////////////////////////////////////////
23 // AutofillOptions class:
26 * Encapsulated handling of Autofill options page.
28 * @extends {cr.ui.pageManager.Page}
30 function AutofillOptions() {
31 Page
.call(this, 'autofill',
32 loadTimeData
.getString('autofillOptionsPageTabTitle'),
36 cr
.addSingletonGetter(AutofillOptions
);
38 AutofillOptions
.prototype = {
39 __proto__
: Page
.prototype,
43 * @type {options.DeletableItemList}
49 * The credit card list.
50 * @type {options.DeletableItemList}
53 creditCardList_
: null,
56 initializePage: function() {
57 Page
.prototype.initializePage
.call(this);
59 this.createAddressList_();
60 this.createCreditCardList_();
63 $('autofill-add-address').onclick = function(event
) {
64 self
.showAddAddressOverlay_();
66 $('autofill-add-creditcard').onclick = function(event
) {
67 self
.showAddCreditCardOverlay_();
69 $('autofill-options-confirm').onclick = function(event
) {
70 PageManager
.closeOverlay();
73 $('autofill-help').onclick = function(event
) {
74 chrome
.send('coreOptionsUserMetricsAction',
75 ['Options_AutofillShowAbout']);
76 return true; // Always follow the href
79 this.walletIntegrationAvailableStateChanged_(
80 loadTimeData
.getBoolean('autofillWalletIntegrationAvailable'));
82 // TODO(jhawkins): What happens when Autofill is disabled whilst on the
83 // Autofill options page?
87 * Creates, decorates and initializes the address list.
90 createAddressList_: function() {
91 var addressList
= $('address-list');
92 options
.autofillOptions
.AutofillAddressList
.decorate(addressList
);
93 this.addressList_
= assertInstanceof(addressList
,
94 options
.DeletableItemList
);
95 this.addressList_
.autoExpands
= true;
99 * Creates, decorates and initializes the credit card list.
102 createCreditCardList_: function() {
103 var creditCardList
= $('creditcard-list');
104 options
.autofillOptions
.AutofillCreditCardList
.decorate(creditCardList
);
105 this.creditCardList_
= assertInstanceof(creditCardList
,
106 options
.DeletableItemList
);
107 this.creditCardList_
.autoExpands
= true;
111 * Shows the 'Add address' overlay, specifically by loading the
112 * 'Edit address' overlay and modifying the overlay title.
115 showAddAddressOverlay_: function() {
116 var title
= loadTimeData
.getString('addAddressTitle');
117 AutofillEditAddressOverlay
.setTitle(title
);
118 PageManager
.showPageByName('autofillEditAddress');
119 AutofillEditAddressOverlay
.prepForNewAddress();
123 * Shows the 'Add credit card' overlay, specifically by loading the
124 * 'Edit credit card' overlay and modifying the overlay title.
127 showAddCreditCardOverlay_: function() {
128 var title
= loadTimeData
.getString('addCreditCardTitle');
129 AutofillEditCreditCardOverlay
.setTitle(title
);
130 PageManager
.showPageByName('autofillEditCreditCard');
131 AutofillEditCreditCardOverlay
.prepForNewCard();
135 * Updates the data model for the address list with the values from
137 * @param {!Array} entries The list of addresses.
139 setAddressList_: function(entries
) {
140 this.addressList_
.dataModel
= new ArrayDataModel(entries
);
144 * Updates the data model for the credit card list with the values from
146 * @param {!Array} entries The list of credit cards.
148 setCreditCardList_: function(entries
) {
149 this.creditCardList_
.dataModel
= new ArrayDataModel(entries
);
153 * Removes the Autofill address or credit card represented by |guid|.
154 * @param {string} guid The GUID of the address to remove.
155 * @param {string=} metricsAction The name of the action to log for metrics.
158 removeData_: function(guid
, metricsAction
) {
159 chrome
.send('removeData', [guid
]);
161 chrome
.send('coreOptionsUserMetricsAction', [metricsAction
]);
165 * Shows the 'Edit address' overlay, using the data in |address| to fill the
166 * input fields. |address| is a list with one item, an associative array
167 * that contains the address data.
170 showEditAddressOverlay_: function(address
) {
171 var title
= loadTimeData
.getString('editAddressTitle');
172 AutofillEditAddressOverlay
.setTitle(title
);
173 AutofillEditAddressOverlay
.loadAddress(address
);
174 PageManager
.showPageByName('autofillEditAddress');
178 * Shows the 'Edit credit card' overlay, using the data in |credit_card| to
179 * fill the input fields. |creditCard| is a list with one item, an
180 * associative array that contains the credit card data.
181 * @param {CreditCardData} creditCard
184 showEditCreditCardOverlay_: function(creditCard
) {
185 var title
= loadTimeData
.getString('editCreditCardTitle');
186 AutofillEditCreditCardOverlay
.setTitle(title
);
187 AutofillEditCreditCardOverlay
.loadCreditCard(creditCard
);
188 PageManager
.showPageByName('autofillEditCreditCard');
192 * Toggles the visibility of the Wallet integration checkbox.
193 * @param {boolean} available Whether the user has the option of using
197 walletIntegrationAvailableStateChanged_: function(available
) {
198 $('autofill-wallet-setting-area').hidden
= !available
;
202 AutofillOptions
.setAddressList = function(entries
) {
203 AutofillOptions
.getInstance().setAddressList_(entries
);
206 AutofillOptions
.setCreditCardList = function(entries
) {
207 AutofillOptions
.getInstance().setCreditCardList_(entries
);
210 AutofillOptions
.removeData = function(guid
, metricsAction
) {
211 AutofillOptions
.getInstance().removeData_(guid
, metricsAction
);
214 AutofillOptions
.editAddress = function(address
) {
215 AutofillOptions
.getInstance().showEditAddressOverlay_(address
);
218 AutofillOptions
.walletIntegrationAvailableStateChanged = function(available
) {
219 AutofillOptions
.getInstance().
220 walletIntegrationAvailableStateChanged_(available
);
224 * @param {CreditCardData} creditCard
226 AutofillOptions
.editCreditCard = function(creditCard
) {
227 AutofillOptions
.getInstance().showEditCreditCardOverlay_(creditCard
);
232 AutofillOptions
: AutofillOptions