| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 | |
| 8 /** | |
| 9 * ImportDataOverlay class | |
| 10 * Encapsulated handling of the 'Import Data' overlay page. | |
| 11 * @class | |
| 12 */ | |
| 13 function ImportDataOverlay() { | |
| 14 OptionsPage.call(this, | |
| 15 'importData', | |
| 16 templateData.importDataOverlayTabTitle, | |
| 17 'import-data-overlay'); | |
| 18 } | |
| 19 | |
| 20 cr.addSingletonGetter(ImportDataOverlay); | |
| 21 | |
| 22 ImportDataOverlay.prototype = { | |
| 23 // Inherit from OptionsPage. | |
| 24 __proto__: OptionsPage.prototype, | |
| 25 | |
| 26 /** | |
| 27 * Initialize the page. | |
| 28 */ | |
| 29 initializePage: function() { | |
| 30 // Call base class implementation to start preference initialization. | |
| 31 OptionsPage.prototype.initializePage.call(this); | |
| 32 | |
| 33 var self = this; | |
| 34 var checkboxes = | |
| 35 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | |
| 36 for (var i = 0; i < checkboxes.length; i++) { | |
| 37 checkboxes[i].onchange = function() { | |
| 38 self.validateCommitButton_(); | |
| 39 }; | |
| 40 } | |
| 41 | |
| 42 $('import-browsers').onchange = function() { | |
| 43 self.updateCheckboxes_(); | |
| 44 self.validateCommitButton_(); | |
| 45 }; | |
| 46 | |
| 47 $('import-data-commit').onclick = function() { | |
| 48 chrome.send('importData', [ | |
| 49 String($('import-browsers').selectedIndex), | |
| 50 String($('import-history').checked), | |
| 51 String($('import-favorites').checked), | |
| 52 String($('import-passwords').checked), | |
| 53 String($('import-search').checked)]); | |
| 54 }; | |
| 55 | |
| 56 $('import-data-cancel').onclick = function() { | |
| 57 ImportDataOverlay.dismiss(); | |
| 58 }; | |
| 59 | |
| 60 $('import-data-show-bookmarks-bar').onchange = function() { | |
| 61 // Note: The callback 'toggleShowBookmarksBar' is handled within the | |
| 62 // browser options handler -- rather than the import data handler -- | |
| 63 // as the implementation is shared by several clients. | |
| 64 chrome.send('toggleShowBookmarksBar'); | |
| 65 } | |
| 66 | |
| 67 $('import-data-confirm').onclick = function() { | |
| 68 ImportDataOverlay.dismiss(); | |
| 69 }; | |
| 70 | |
| 71 // Form controls are disabled until the profile list has been loaded. | |
| 72 self.setControlsSensitive_(false); | |
| 73 }, | |
| 74 | |
| 75 /** | |
| 76 * Set enabled and checked state of the commit button. | |
| 77 * @private | |
| 78 */ | |
| 79 validateCommitButton_: function() { | |
| 80 var somethingToImport = | |
| 81 $('import-history').checked || $('import-favorites').checked || | |
| 82 $('import-passwords').checked || $('import-search').checked; | |
| 83 $('import-data-commit').disabled = !somethingToImport; | |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * Sets the sensitivity of all the checkboxes and the commit button. | |
| 88 * @private | |
| 89 */ | |
| 90 setControlsSensitive_: function(sensitive) { | |
| 91 var checkboxes = | |
| 92 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | |
| 93 for (var i = 0; i < checkboxes.length; i++) | |
| 94 this.setUpCheckboxState_(checkboxes[i], sensitive); | |
| 95 $('import-data-commit').disabled = !sensitive; | |
| 96 }, | |
| 97 | |
| 98 /** | |
| 99 * Set enabled and checked states a checkbox element. | |
| 100 * @param {Object} checkbox A checkbox element. | |
| 101 * @param {boolean} enabled The enabled state of the chekbox. | |
| 102 * @private | |
| 103 */ | |
| 104 setUpCheckboxState_: function(checkbox, enabled) { | |
| 105 checkbox.setDisabled("noProfileData", !enabled); | |
| 106 }, | |
| 107 | |
| 108 /** | |
| 109 * Update the enabled and checked states of all checkboxes. | |
| 110 * @private | |
| 111 */ | |
| 112 updateCheckboxes_: function() { | |
| 113 var index = $('import-browsers').selectedIndex; | |
| 114 var browserProfile; | |
| 115 if (this.browserProfiles.length > index) | |
| 116 browserProfile = this.browserProfiles[index]; | |
| 117 var importOptions = ['history', 'favorites', 'passwords', 'search']; | |
| 118 for (var i = 0; i < importOptions.length; i++) { | |
| 119 var checkbox = $('import-' + importOptions[i]); | |
| 120 var enable = browserProfile && browserProfile[importOptions[i]]; | |
| 121 this.setUpCheckboxState_(checkbox, enable); | |
| 122 } | |
| 123 }, | |
| 124 | |
| 125 /** | |
| 126 * Update the supported browsers popup with given entries. | |
| 127 * @param {array} browsers List of supported browsers name. | |
| 128 * @private | |
| 129 */ | |
| 130 updateSupportedBrowsers_: function(browsers) { | |
| 131 this.browserProfiles = browsers; | |
| 132 var browserSelect = $('import-browsers'); | |
| 133 browserSelect.remove(0); // Remove the 'Loading...' option. | |
| 134 browserSelect.textContent = ''; | |
| 135 var browserCount = browsers.length; | |
| 136 | |
| 137 if (browserCount == 0) { | |
| 138 var option = new Option(templateData.noProfileFound, 0); | |
| 139 browserSelect.appendChild(option); | |
| 140 | |
| 141 this.setControlsSensitive_(false); | |
| 142 } else { | |
| 143 this.setControlsSensitive_(true); | |
| 144 for (var i = 0; i < browserCount; i++) { | |
| 145 var browser = browsers[i] | |
| 146 var option = new Option(browser['name'], browser['index']); | |
| 147 browserSelect.appendChild(option); | |
| 148 } | |
| 149 | |
| 150 this.updateCheckboxes_(); | |
| 151 this.validateCommitButton_(); | |
| 152 } | |
| 153 }, | |
| 154 | |
| 155 /** | |
| 156 * Clear import prefs set when user checks/unchecks a checkbox so that each | |
| 157 * checkbox goes back to the default "checked" state (or alternatively, to | |
| 158 * the state set by a recommended policy). | |
| 159 * @private | |
| 160 */ | |
| 161 clearUserPrefs_: function() { | |
| 162 var importPrefs = ['import_history', | |
| 163 'import_bookmarks', | |
| 164 'import_saved_passwords', | |
| 165 'import_search_engine']; | |
| 166 for (var i = 0; i < importPrefs.length; i++) | |
| 167 Preferences.clearPref(importPrefs[i], undefined); | |
| 168 }, | |
| 169 }; | |
| 170 | |
| 171 ImportDataOverlay.clearUserPrefs = function() { | |
| 172 ImportDataOverlay.getInstance().clearUserPrefs_(); | |
| 173 }; | |
| 174 | |
| 175 /** | |
| 176 * Update the supported browsers popup with given entries. | |
| 177 * @param {array} list of supported browsers name. | |
| 178 */ | |
| 179 ImportDataOverlay.updateSupportedBrowsers = function(browsers) { | |
| 180 ImportDataOverlay.getInstance().updateSupportedBrowsers_(browsers); | |
| 181 }; | |
| 182 | |
| 183 /** | |
| 184 * Update the UI to reflect whether an import operation is in progress. | |
| 185 * @param {boolean} state True if an import operation is in progress. | |
| 186 */ | |
| 187 ImportDataOverlay.setImportingState = function(state) { | |
| 188 var checkboxes = | |
| 189 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | |
| 190 for (var i = 0; i < checkboxes.length; i++) | |
| 191 checkboxes[i].setDisabled("Importing", state); | |
| 192 if (!state) | |
| 193 ImportDataOverlay.getInstance().updateCheckboxes_(); | |
| 194 $('import-browsers').disabled = state; | |
| 195 $('import-throbber').style.visibility = state ? "visible" : "hidden"; | |
| 196 ImportDataOverlay.getInstance().validateCommitButton_(); | |
| 197 }; | |
| 198 | |
| 199 /** | |
| 200 * Remove the import overlay from display. | |
| 201 */ | |
| 202 ImportDataOverlay.dismiss = function() { | |
| 203 ImportDataOverlay.clearUserPrefs(); | |
| 204 OptionsPage.closeOverlay(); | |
| 205 }; | |
| 206 | |
| 207 /** | |
| 208 * Show a message confirming the success of the import operation. | |
| 209 */ | |
| 210 ImportDataOverlay.confirmSuccess = function() { | |
| 211 var showBookmarksMessage = $('import-favorites').checked; | |
| 212 ImportDataOverlay.setImportingState(false); | |
| 213 $('import-data-configure').hidden = true; | |
| 214 $('import-data-success').hidden = false; | |
| 215 $('import-find-your-bookmarks').hidden = !showBookmarksMessage; | |
| 216 }; | |
| 217 | |
| 218 // Export | |
| 219 return { | |
| 220 ImportDataOverlay: ImportDataOverlay | |
| 221 }; | |
| 222 }); | |
| OLD | NEW |