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.
5 cr.define('options', function() {
6 var OptionsPage = options.OptionsPage;
7 var ArrayDataModel = cr.ui.ArrayDataModel;
9 /////////////////////////////////////////////////////////////////////////////
10 // AutofillOptions class:
13 * Encapsulated handling of Autofill options page.
16 function AutofillOptions() {
17 OptionsPage.call(this,
19 loadTimeData.getString('autofillOptionsPageTabTitle'),
23 cr.addSingletonGetter(AutofillOptions);
25 AutofillOptions.prototype = {
26 __proto__: OptionsPage.prototype,
30 * @type {DeletableItemList}
36 * The credit card list.
37 * @type {DeletableItemList}
40 creditCardList_: null,
42 initializePage: function() {
43 OptionsPage.prototype.initializePage.call(this);
45 this.createAddressList_();
46 this.createCreditCardList_();
49 $('autofill-add-address').onclick = function(event) {
50 self.showAddAddressOverlay_();
52 $('autofill-add-creditcard').onclick = function(event) {
53 self.showAddCreditCardOverlay_();
55 $('autofill-options-confirm').onclick = function(event) {
56 OptionsPage.closeOverlay();
59 // TODO(jhawkins): What happens when Autofill is disabled whilst on the
60 // Autofill options page?
64 * Creates, decorates and initializes the address list.
67 createAddressList_: function() {
68 this.addressList_ = $('address-list');
69 options.autofillOptions.AutofillAddressList.decorate(this.addressList_);
70 this.addressList_.autoExpands = true;
74 * Creates, decorates and initializes the credit card list.
77 createCreditCardList_: function() {
78 this.creditCardList_ = $('creditcard-list');
79 options.autofillOptions.AutofillCreditCardList.decorate(
80 this.creditCardList_);
81 this.creditCardList_.autoExpands = true;
85 * Shows the 'Add address' overlay, specifically by loading the
86 * 'Edit address' overlay and modifying the overlay title.
89 showAddAddressOverlay_: function() {
90 var title = loadTimeData.getString('addAddressTitle');
91 AutofillEditAddressOverlay.setTitle(title);
92 OptionsPage.navigateToPage('autofillEditAddress');
96 * Shows the 'Add credit card' overlay, specifically by loading the
97 * 'Edit credit card' overlay and modifying the overlay title.
100 showAddCreditCardOverlay_: function() {
101 var title = loadTimeData.getString('addCreditCardTitle');
102 AutofillEditCreditCardOverlay.setTitle(title);
103 OptionsPage.navigateToPage('autofillEditCreditCard');
107 * Updates the data model for the address list with the values from
109 * @param {Array} entries The list of addresses.
111 setAddressList_: function(entries) {
112 this.addressList_.dataModel = new ArrayDataModel(entries);
116 * Updates the data model for the credit card list with the values from
118 * @param {Array} entries The list of credit cards.
120 setCreditCardList_: function(entries) {
121 this.creditCardList_.dataModel = new ArrayDataModel(entries);
125 * Removes the Autofill address or credit card represented by |guid|.
126 * @param {string} guid The GUID of the address to remove.
129 removeData_: function(guid) {
130 chrome.send('removeData', [guid]);
134 * Requests profile data for the address represented by |guid| from the
135 * PersonalDataManager. Once the data is loaded, the AutofillOptionsHandler
136 * calls showEditAddressOverlay().
137 * @param {string} guid The GUID of the address to edit.
140 loadAddressEditor_: function(guid) {
141 chrome.send('loadAddressEditor', [guid]);
145 * Requests profile data for the credit card represented by |guid| from the
146 * PersonalDataManager. Once the data is loaded, the AutofillOptionsHandler
147 * calls showEditCreditCardOverlay().
148 * @param {string} guid The GUID of the credit card to edit.
151 loadCreditCardEditor_: function(guid) {
152 chrome.send('loadCreditCardEditor', [guid]);
156 * Shows the 'Edit address' overlay, using the data in |address| to fill the
157 * input fields. |address| is a list with one item, an associative array
158 * that contains the address data.
161 showEditAddressOverlay_: function(address) {
162 var title = loadTimeData.getString('editAddressTitle');
163 AutofillEditAddressOverlay.setTitle(title);
164 AutofillEditAddressOverlay.loadAddress(address);
165 OptionsPage.navigateToPage('autofillEditAddress');
169 * Shows the 'Edit credit card' overlay, using the data in |credit_card| to
170 * fill the input fields. |address| is a list with one item, an associative
171 * array that contains the credit card data.
174 showEditCreditCardOverlay_: function(creditCard) {
175 var title = loadTimeData.getString('editCreditCardTitle');
176 AutofillEditCreditCardOverlay.setTitle(title);
177 AutofillEditCreditCardOverlay.loadCreditCard(creditCard);
178 OptionsPage.navigateToPage('autofillEditCreditCard');
182 AutofillOptions.setAddressList = function(entries) {
183 AutofillOptions.getInstance().setAddressList_(entries);
186 AutofillOptions.setCreditCardList = function(entries) {
187 AutofillOptions.getInstance().setCreditCardList_(entries);
190 AutofillOptions.removeData = function(guid) {
191 AutofillOptions.getInstance().removeData_(guid);
194 AutofillOptions.loadAddressEditor = function(guid) {
195 AutofillOptions.getInstance().loadAddressEditor_(guid);
198 AutofillOptions.loadCreditCardEditor = function(guid) {
199 AutofillOptions.getInstance().loadCreditCardEditor_(guid);
202 AutofillOptions.editAddress = function(address) {
203 AutofillOptions.getInstance().showEditAddressOverlay_(address);
206 AutofillOptions.editCreditCard = function(creditCard) {
207 AutofillOptions.getInstance().showEditCreditCardOverlay_(creditCard);
212 AutofillOptions: AutofillOptions