OLD | NEW |
| (Empty) |
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. | |
4 | |
5 cr.define('options', function() { | |
6 var OptionsPage = options.OptionsPage; | |
7 var ArrayDataModel = cr.ui.ArrayDataModel; | |
8 | |
9 ///////////////////////////////////////////////////////////////////////////// | |
10 // AutofillOptions class: | |
11 | |
12 /** | |
13 * Encapsulated handling of Autofill options page. | |
14 * @constructor | |
15 */ | |
16 function AutofillOptions() { | |
17 OptionsPage.call(this, | |
18 'autofill', | |
19 loadTimeData.getString('autofillOptionsPageTabTitle'), | |
20 'autofill-options'); | |
21 } | |
22 | |
23 cr.addSingletonGetter(AutofillOptions); | |
24 | |
25 AutofillOptions.prototype = { | |
26 __proto__: OptionsPage.prototype, | |
27 | |
28 /** | |
29 * The address list. | |
30 * @type {DeletableItemList} | |
31 * @private | |
32 */ | |
33 addressList_: null, | |
34 | |
35 /** | |
36 * The credit card list. | |
37 * @type {DeletableItemList} | |
38 * @private | |
39 */ | |
40 creditCardList_: null, | |
41 | |
42 initializePage: function() { | |
43 OptionsPage.prototype.initializePage.call(this); | |
44 | |
45 this.createAddressList_(); | |
46 this.createCreditCardList_(); | |
47 | |
48 var self = this; | |
49 $('autofill-add-address').onclick = function(event) { | |
50 self.showAddAddressOverlay_(); | |
51 }; | |
52 $('autofill-add-creditcard').onclick = function(event) { | |
53 self.showAddCreditCardOverlay_(); | |
54 }; | |
55 $('autofill-options-confirm').onclick = function(event) { | |
56 OptionsPage.closeOverlay(); | |
57 }; | |
58 | |
59 // TODO(jhawkins): What happens when Autofill is disabled whilst on the | |
60 // Autofill options page? | |
61 }, | |
62 | |
63 /** | |
64 * Creates, decorates and initializes the address list. | |
65 * @private | |
66 */ | |
67 createAddressList_: function() { | |
68 this.addressList_ = $('address-list'); | |
69 options.autofillOptions.AutofillAddressList.decorate(this.addressList_); | |
70 this.addressList_.autoExpands = true; | |
71 }, | |
72 | |
73 /** | |
74 * Creates, decorates and initializes the credit card list. | |
75 * @private | |
76 */ | |
77 createCreditCardList_: function() { | |
78 this.creditCardList_ = $('creditcard-list'); | |
79 options.autofillOptions.AutofillCreditCardList.decorate( | |
80 this.creditCardList_); | |
81 this.creditCardList_.autoExpands = true; | |
82 }, | |
83 | |
84 /** | |
85 * Shows the 'Add address' overlay, specifically by loading the | |
86 * 'Edit address' overlay, emptying the input fields and modifying the | |
87 * overlay title. | |
88 * @private | |
89 */ | |
90 showAddAddressOverlay_: function() { | |
91 var title = loadTimeData.getString('addAddressTitle'); | |
92 AutofillEditAddressOverlay.setTitle(title); | |
93 AutofillEditAddressOverlay.clearInputFields(); | |
94 OptionsPage.navigateToPage('autofillEditAddress'); | |
95 }, | |
96 | |
97 /** | |
98 * Shows the 'Add credit card' overlay, specifically by loading the | |
99 * 'Edit credit card' overlay, emptying the input fields and modifying the | |
100 * overlay title. | |
101 * @private | |
102 */ | |
103 showAddCreditCardOverlay_: function() { | |
104 var title = loadTimeData.getString('addCreditCardTitle'); | |
105 AutofillEditCreditCardOverlay.setTitle(title); | |
106 AutofillEditCreditCardOverlay.clearInputFields(); | |
107 OptionsPage.navigateToPage('autofillEditCreditCard'); | |
108 }, | |
109 | |
110 /** | |
111 * Updates the data model for the address list with the values from | |
112 * |entries|. | |
113 * @param {Array} entries The list of addresses. | |
114 */ | |
115 setAddressList_: function(entries) { | |
116 this.addressList_.dataModel = new ArrayDataModel(entries); | |
117 }, | |
118 | |
119 /** | |
120 * Updates the data model for the credit card list with the values from | |
121 * |entries|. | |
122 * @param {Array} entries The list of credit cards. | |
123 */ | |
124 setCreditCardList_: function(entries) { | |
125 this.creditCardList_.dataModel = new ArrayDataModel(entries); | |
126 }, | |
127 | |
128 /** | |
129 * Removes the Autofill address represented by |guid|. | |
130 * @param {String} guid The GUID of the address to remove. | |
131 * @private | |
132 */ | |
133 removeAddress_: function(guid) { | |
134 chrome.send('removeAddress', [guid]); | |
135 }, | |
136 | |
137 /** | |
138 * Removes the Autofill credit card represented by |guid|. | |
139 * @param {String} guid The GUID of the credit card to remove. | |
140 * @private | |
141 */ | |
142 removeCreditCard_: function(guid) { | |
143 chrome.send('removeCreditCard', [guid]); | |
144 }, | |
145 | |
146 /** | |
147 * Requests profile data for the address represented by |guid| from the | |
148 * PersonalDataManager. Once the data is loaded, the AutofillOptionsHandler | |
149 * calls showEditAddressOverlay(). | |
150 * @param {String} guid The GUID of the address to edit. | |
151 * @private | |
152 */ | |
153 loadAddressEditor_: function(guid) { | |
154 chrome.send('loadAddressEditor', [guid]); | |
155 }, | |
156 | |
157 /** | |
158 * Requests profile data for the credit card represented by |guid| from the | |
159 * PersonalDataManager. Once the data is loaded, the AutofillOptionsHandler | |
160 * calls showEditCreditCardOverlay(). | |
161 * @param {String} guid The GUID of the credit card to edit. | |
162 * @private | |
163 */ | |
164 loadCreditCardEditor_: function(guid) { | |
165 chrome.send('loadCreditCardEditor', [guid]); | |
166 }, | |
167 | |
168 /** | |
169 * Shows the 'Edit address' overlay, using the data in |address| to fill the | |
170 * input fields. |address| is a list with one item, an associative array | |
171 * that contains the address data. | |
172 * @private | |
173 */ | |
174 showEditAddressOverlay_: function(address) { | |
175 var title = loadTimeData.getString('editAddressTitle'); | |
176 AutofillEditAddressOverlay.setTitle(title); | |
177 AutofillEditAddressOverlay.loadAddress(address); | |
178 OptionsPage.navigateToPage('autofillEditAddress'); | |
179 }, | |
180 | |
181 /** | |
182 * Shows the 'Edit credit card' overlay, using the data in |credit_card| to | |
183 * fill the input fields. |address| is a list with one item, an associative | |
184 * array that contains the credit card data. | |
185 * @private | |
186 */ | |
187 showEditCreditCardOverlay_: function(creditCard) { | |
188 var title = loadTimeData.getString('editCreditCardTitle'); | |
189 AutofillEditCreditCardOverlay.setTitle(title); | |
190 AutofillEditCreditCardOverlay.loadCreditCard(creditCard); | |
191 OptionsPage.navigateToPage('autofillEditCreditCard'); | |
192 }, | |
193 }; | |
194 | |
195 AutofillOptions.setAddressList = function(entries) { | |
196 AutofillOptions.getInstance().setAddressList_(entries); | |
197 }; | |
198 | |
199 AutofillOptions.setCreditCardList = function(entries) { | |
200 AutofillOptions.getInstance().setCreditCardList_(entries); | |
201 }; | |
202 | |
203 AutofillOptions.removeAddress = function(guid) { | |
204 AutofillOptions.getInstance().removeAddress_(guid); | |
205 }; | |
206 | |
207 AutofillOptions.removeCreditCard = function(guid) { | |
208 AutofillOptions.getInstance().removeCreditCard_(guid); | |
209 }; | |
210 | |
211 AutofillOptions.loadAddressEditor = function(guid) { | |
212 AutofillOptions.getInstance().loadAddressEditor_(guid); | |
213 }; | |
214 | |
215 AutofillOptions.loadCreditCardEditor = function(guid) { | |
216 AutofillOptions.getInstance().loadCreditCardEditor_(guid); | |
217 }; | |
218 | |
219 AutofillOptions.editAddress = function(address) { | |
220 AutofillOptions.getInstance().showEditAddressOverlay_(address); | |
221 }; | |
222 | |
223 AutofillOptions.editCreditCard = function(creditCard) { | |
224 AutofillOptions.getInstance().showEditCreditCardOverlay_(creditCard); | |
225 }; | |
226 | |
227 // Export | |
228 return { | |
229 AutofillOptions: AutofillOptions | |
230 }; | |
231 | |
232 }); | |
233 | |
OLD | NEW |