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 Page = cr.ui.pageManager.Page;
7 var PageManager = cr.ui.pageManager.PageManager;
8 var ArrayDataModel = cr.ui.ArrayDataModel;
10 /////////////////////////////////////////////////////////////////////////////
11 // AutofillOptions class:
14 * Encapsulated handling of Autofill options page.
17 function AutofillOptions() {
18 Page.call(this, 'autofill',
19 loadTimeData.getString('autofillOptionsPageTabTitle'),
23 cr.addSingletonGetter(AutofillOptions);
25 AutofillOptions.prototype = {
26 __proto__: Page.prototype,
30 * @type {DeletableItemList}
36 * The credit card list.
37 * @type {DeletableItemList}
40 creditCardList_: null,
43 initializePage: function() {
44 Page.prototype.initializePage.call(this);
46 this.createAddressList_();
47 this.createCreditCardList_();
50 $('autofill-add-address').onclick = function(event) {
51 self.showAddAddressOverlay_();
53 $('autofill-add-creditcard').onclick = function(event) {
54 self.showAddCreditCardOverlay_();
56 $('autofill-options-confirm').onclick = function(event) {
57 PageManager.closeOverlay();
60 $('autofill-use-mac-address-book-checkbox').onchange = function(event) {
62 setTimeout(function() {
63 // Prompt the user to give Chrome access to the user's Address
64 // Book, if the user was not previously prompted. The dialog that
65 // appears blocks the Chrome process, so wait for a small period of
66 // time to allow the checkbox to appear filled in.
67 chrome.send('accessAddressBook');
73 // TODO(jhawkins): What happens when Autofill is disabled whilst on the
74 // Autofill options page?
78 * Creates, decorates and initializes the address list.
81 createAddressList_: function() {
82 this.addressList_ = $('address-list');
83 options.autofillOptions.AutofillAddressList.decorate(this.addressList_);
84 this.addressList_.autoExpands = true;
88 * Creates, decorates and initializes the credit card list.
91 createCreditCardList_: function() {
92 this.creditCardList_ = $('creditcard-list');
93 options.autofillOptions.AutofillCreditCardList.decorate(
94 this.creditCardList_);
95 this.creditCardList_.autoExpands = true;
99 * Shows the 'Add address' overlay, specifically by loading the
100 * 'Edit address' overlay and modifying the overlay title.
103 showAddAddressOverlay_: function() {
104 var title = loadTimeData.getString('addAddressTitle');
105 AutofillEditAddressOverlay.setTitle(title);
106 PageManager.showPageByName('autofillEditAddress');
110 * Shows the 'Add credit card' overlay, specifically by loading the
111 * 'Edit credit card' overlay and modifying the overlay title.
114 showAddCreditCardOverlay_: function() {
115 var title = loadTimeData.getString('addCreditCardTitle');
116 AutofillEditCreditCardOverlay.setTitle(title);
117 PageManager.showPageByName('autofillEditCreditCard');
121 * Updates the data model for the address list with the values from
123 * @param {Array} entries The list of addresses.
125 setAddressList_: function(entries) {
126 this.addressList_.dataModel = new ArrayDataModel(entries);
130 * Updates the data model for the credit card list with the values from
132 * @param {Array} entries The list of credit cards.
134 setCreditCardList_: function(entries) {
135 this.creditCardList_.dataModel = new ArrayDataModel(entries);
139 * Removes the Autofill address or credit card represented by |guid|.
140 * @param {string} guid The GUID of the address to remove.
143 removeData_: function(guid) {
144 chrome.send('removeData', [guid]);
148 * Requests profile data for the address represented by |guid| from the
149 * PersonalDataManager. Once the data is loaded, the AutofillOptionsHandler
150 * calls showEditAddressOverlay().
151 * @param {string} guid The GUID of the address to edit.
154 loadAddressEditor_: function(guid) {
155 chrome.send('loadAddressEditor', [guid]);
159 * Requests profile data for the credit card represented by |guid| from the
160 * PersonalDataManager. Once the data is loaded, the AutofillOptionsHandler
161 * calls showEditCreditCardOverlay().
162 * @param {string} guid The GUID of the credit card to edit.
165 loadCreditCardEditor_: function(guid) {
166 chrome.send('loadCreditCardEditor', [guid]);
170 * Shows the 'Edit address' overlay, using the data in |address| to fill the
171 * input fields. |address| is a list with one item, an associative array
172 * that contains the address data.
175 showEditAddressOverlay_: function(address) {
176 var title = loadTimeData.getString('editAddressTitle');
177 AutofillEditAddressOverlay.setTitle(title);
178 AutofillEditAddressOverlay.loadAddress(address);
179 PageManager.showPageByName('autofillEditAddress');
183 * Shows the 'Edit credit card' overlay, using the data in |credit_card| to
184 * fill the input fields. |address| is a list with one item, an associative
185 * array that contains the credit card data.
188 showEditCreditCardOverlay_: function(creditCard) {
189 var title = loadTimeData.getString('editCreditCardTitle');
190 AutofillEditCreditCardOverlay.setTitle(title);
191 AutofillEditCreditCardOverlay.loadCreditCard(creditCard);
192 PageManager.showPageByName('autofillEditCreditCard');
196 AutofillOptions.setAddressList = function(entries) {
197 AutofillOptions.getInstance().setAddressList_(entries);
200 AutofillOptions.setCreditCardList = function(entries) {
201 AutofillOptions.getInstance().setCreditCardList_(entries);
204 AutofillOptions.removeData = function(guid) {
205 AutofillOptions.getInstance().removeData_(guid);
208 AutofillOptions.loadAddressEditor = function(guid) {
209 AutofillOptions.getInstance().loadAddressEditor_(guid);
212 AutofillOptions.loadCreditCardEditor = function(guid) {
213 AutofillOptions.getInstance().loadCreditCardEditor_(guid);
216 AutofillOptions.editAddress = function(address) {
217 AutofillOptions.getInstance().showEditAddressOverlay_(address);
220 AutofillOptions.editCreditCard = function(creditCard) {
221 AutofillOptions.getInstance().showEditCreditCardOverlay_(creditCard);
226 AutofillOptions: AutofillOptions