Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / resources / options / import_data_overlay.js
blob600c9fa89b86771285d54a8b8d55779bd1d8caa0
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;
9 /**
10 * ImportDataOverlay class
11 * Encapsulated handling of the 'Import Data' overlay page.
12 * @class
14 function ImportDataOverlay() {
15 Page.call(this,
16 'importData',
17 loadTimeData.getString('importDataOverlayTabTitle'),
18 'import-data-overlay');
21 cr.addSingletonGetter(ImportDataOverlay);
23 ImportDataOverlay.prototype = {
24 // Inherit from Page.
25 __proto__: Page.prototype,
27 /** @override */
28 initializePage: function() {
29 Page.prototype.initializePage.call(this);
31 var self = this;
32 var checkboxes =
33 document.querySelectorAll('#import-checkboxes input[type=checkbox]');
34 for (var i = 0; i < checkboxes.length; i++) {
35 checkboxes[i].onchange = function() {
36 self.validateCommitButton_();
40 $('import-browsers').onchange = function() {
41 self.updateCheckboxes_();
42 self.validateCommitButton_();
43 self.updateBottomBar_();
46 $('import-data-commit').onclick = function() {
47 chrome.send('importData', [
48 String($('import-browsers').selectedIndex),
49 String($('import-history').checked),
50 String($('import-favorites').checked),
51 String($('import-passwords').checked),
52 String($('import-search').checked),
53 String($('import-autofill-form-data').checked)]);
56 $('import-data-cancel').onclick = function() {
57 ImportDataOverlay.dismiss();
60 $('import-choose-file').onclick = function() {
61 chrome.send('chooseBookmarksFile');
64 $('import-data-confirm').onclick = function() {
65 ImportDataOverlay.dismiss();
68 // Form controls are disabled until the profile list has been loaded.
69 self.setAllControlsEnabled_(false);
72 /**
73 * Sets the enabled and checked state of the commit button.
74 * @private
76 validateCommitButton_: function() {
77 var somethingToImport =
78 $('import-history').checked || $('import-favorites').checked ||
79 $('import-passwords').checked || $('import-search').checked ||
80 $('import-autofill-form-data').checked;
81 $('import-data-commit').disabled = !somethingToImport;
82 $('import-choose-file').disabled = !$('import-favorites').checked;
85 /**
86 * Sets the enabled state of all the checkboxes and the commit button.
87 * @private
89 setAllControlsEnabled_: function(enabled) {
90 var checkboxes =
91 document.querySelectorAll('#import-checkboxes input[type=checkbox]');
92 for (var i = 0; i < checkboxes.length; i++)
93 this.setUpCheckboxState_(checkboxes[i], enabled);
94 $('import-data-commit').disabled = !enabled;
95 $('import-choose-file').hidden = !enabled;
96 <if expr="is_macosx">
97 $('mac-password-keychain').hidden = !enabled;
98 </if>
102 * Sets the enabled state of a checkbox element.
103 * @param {Object} checkbox A checkbox element.
104 * @param {boolean} enabled The enabled state of the checkbox. If false,
105 * the checkbox is disabled. If true, the checkbox is enabled.
106 * @private
108 setUpCheckboxState_: function(checkbox, enabled) {
109 checkbox.setDisabled('noProfileData', !enabled);
113 * Update the enabled and visible states of all the checkboxes.
114 * @private
116 updateCheckboxes_: function() {
117 var index = $('import-browsers').selectedIndex;
118 var bookmarksFileSelected = index == this.browserProfiles.length - 1;
119 $('import-choose-file').hidden = !bookmarksFileSelected;
120 $('import-data-commit').hidden = bookmarksFileSelected;
122 var browserProfile;
123 if (this.browserProfiles.length > index)
124 browserProfile = this.browserProfiles[index];
125 var importOptions = ['history',
126 'favorites',
127 'passwords',
128 'search',
129 'autofill-form-data'];
130 for (var i = 0; i < importOptions.length; i++) {
131 var checkbox = $('import-' + importOptions[i]);
132 var enable = browserProfile && browserProfile[importOptions[i]];
133 this.setUpCheckboxState_(checkbox, enable);
134 var checkboxWithLabel = $('import-' + importOptions[i] + '-with-label');
135 checkboxWithLabel.style.display = enable ? '' : 'none';
140 * Show or hide gray message at the bottom.
141 * @private
143 updateBottomBar_: function() {
144 var index = $('import-browsers').selectedIndex;
145 var browserProfile;
146 if (this.browserProfiles.length > index)
147 browserProfile = this.browserProfiles[index];
148 var enable = browserProfile && browserProfile['show_bottom_bar'];
149 <if expr="is_macosx">
150 $('mac-password-keychain').hidden = !enable;
151 </if>
155 * Update the supported browsers popup with given entries.
156 * @param {Array} browsers List of supported browsers name.
157 * @private
159 updateSupportedBrowsers_: function(browsers) {
160 this.browserProfiles = browsers;
161 var browserSelect = $('import-browsers');
162 browserSelect.remove(0); // Remove the 'Loading...' option.
163 browserSelect.textContent = '';
164 var browserCount = browsers.length;
166 if (browserCount == 0) {
167 var option = new Option(loadTimeData.getString('noProfileFound'), 0);
168 browserSelect.appendChild(option);
170 this.setAllControlsEnabled_(false);
171 } else {
172 this.setAllControlsEnabled_(true);
173 for (var i = 0; i < browserCount; i++) {
174 var browser = browsers[i];
175 var option = new Option(browser.name, browser.index);
176 browserSelect.appendChild(option);
179 this.updateCheckboxes_();
180 this.validateCommitButton_();
181 this.updateBottomBar_();
186 * Clear import prefs set when user checks/unchecks a checkbox so that each
187 * checkbox goes back to the default "checked" state (or alternatively, to
188 * the state set by a recommended policy).
189 * @private
191 clearUserPrefs_: function() {
192 var importPrefs = ['import_history',
193 'import_bookmarks',
194 'import_saved_passwords',
195 'import_search_engine',
196 'import_autofill_form_data'];
197 for (var i = 0; i < importPrefs.length; i++)
198 Preferences.clearPref(importPrefs[i], true);
202 * Update the dialog layout to reflect success state.
203 * @param {boolean} success If true, show success dialog elements.
204 * @private
206 updateSuccessState_: function(success) {
207 var sections = document.querySelectorAll('.import-data-configure');
208 for (var i = 0; i < sections.length; i++)
209 sections[i].hidden = success;
211 sections = document.querySelectorAll('.import-data-success');
212 for (var i = 0; i < sections.length; i++)
213 sections[i].hidden = !success;
217 ImportDataOverlay.clearUserPrefs = function() {
218 ImportDataOverlay.getInstance().clearUserPrefs_();
222 * Update the supported browsers popup with given entries.
223 * @param {Array} browsers List of supported browsers name.
225 ImportDataOverlay.updateSupportedBrowsers = function(browsers) {
226 ImportDataOverlay.getInstance().updateSupportedBrowsers_(browsers);
230 * Update the UI to reflect whether an import operation is in progress.
231 * @param {boolean} importing True if an import operation is in progress.
233 ImportDataOverlay.setImportingState = function(importing) {
234 var checkboxes =
235 document.querySelectorAll('#import-checkboxes input[type=checkbox]');
236 for (var i = 0; i < checkboxes.length; i++)
237 checkboxes[i].setDisabled('Importing', importing);
238 if (!importing)
239 ImportDataOverlay.getInstance().updateCheckboxes_();
240 $('import-browsers').disabled = importing;
241 $('import-throbber').style.visibility = importing ? 'visible' : 'hidden';
242 ImportDataOverlay.getInstance().validateCommitButton_();
246 * Remove the import overlay from display.
248 ImportDataOverlay.dismiss = function() {
249 ImportDataOverlay.clearUserPrefs();
250 PageManager.closeOverlay();
254 * Show a message confirming the success of the import operation.
256 ImportDataOverlay.confirmSuccess = function() {
257 var showBookmarksMessage = $('import-favorites').checked;
258 ImportDataOverlay.setImportingState(false);
259 $('import-find-your-bookmarks').hidden = !showBookmarksMessage;
260 ImportDataOverlay.getInstance().updateSuccessState_(true);
264 * Show the import data overlay.
266 ImportDataOverlay.show = function() {
267 // Make sure that any previous import success message is hidden, and
268 // we're showing the UI to import further data.
269 ImportDataOverlay.getInstance().updateSuccessState_(false);
270 ImportDataOverlay.getInstance().validateCommitButton_();
272 PageManager.showPageByName('importData');
275 // Export
276 return {
277 ImportDataOverlay: ImportDataOverlay