| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * ImportDataOverlay class | 9 * ImportDataOverlay class |
| 10 * Encapsulated handling of the 'Import Data' overlay page. | 10 * Encapsulated handling of the 'Import Data' overlay page. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 $('import-data-commit').disabled = !sensitive; | 95 $('import-data-commit').disabled = !sensitive; |
| 96 }, | 96 }, |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * Set enabled and checked states a checkbox element. | 99 * Set enabled and checked states a checkbox element. |
| 100 * @param {Object} checkbox A checkbox element. | 100 * @param {Object} checkbox A checkbox element. |
| 101 * @param {boolean} enabled The enabled state of the chekbox. | 101 * @param {boolean} enabled The enabled state of the chekbox. |
| 102 * @private | 102 * @private |
| 103 */ | 103 */ |
| 104 setUpCheckboxState_: function(checkbox, enabled) { | 104 setUpCheckboxState_: function(checkbox, enabled) { |
| 105 checkbox.disabled = !enabled; | 105 checkbox.setDisabled("noProfileData", !enabled); |
| 106 checkbox.checked = enabled; | |
| 107 }, | 106 }, |
| 108 | 107 |
| 109 /** | 108 /** |
| 110 * Update the enabled and checked states of all checkboxes. | 109 * Update the enabled and checked states of all checkboxes. |
| 111 * @private | 110 * @private |
| 112 */ | 111 */ |
| 113 updateCheckboxes_: function() { | 112 updateCheckboxes_: function() { |
| 114 var index = $('import-browsers').selectedIndex; | 113 var index = $('import-browsers').selectedIndex; |
| 115 var browserProfile; | 114 var browserProfile; |
| 116 if (this.browserProfiles.length > index) | 115 if (this.browserProfiles.length > index) |
| 117 browserProfile = this.browserProfiles[index]; | 116 browserProfile = this.browserProfiles[index]; |
| 118 var importOptions = ['history', 'favorites', 'passwords', 'search']; | 117 var importOptions = ['history', 'favorites', 'passwords', 'search']; |
| 119 for (var i = 0; i < importOptions.length; i++) { | 118 for (var i = 0; i < importOptions.length; i++) { |
| 120 var checkbox = $('import-' + importOptions[i]); | 119 var checkbox = $('import-' + importOptions[i]); |
| 121 this.setUpCheckboxState_(checkbox, | 120 var enable = browserProfile && browserProfile[importOptions[i]]; |
| 122 browserProfile ? browserProfile[importOptions[i]] : false); | 121 this.setUpCheckboxState_(checkbox, enable); |
| 123 } | 122 } |
| 124 }, | 123 }, |
| 125 | 124 |
| 126 /** | 125 /** |
| 127 * Update the supported browsers popup with given entries. | 126 * Update the supported browsers popup with given entries. |
| 128 * @param {array} browsers List of supported browsers name. | 127 * @param {array} browsers List of supported browsers name. |
| 129 * @private | 128 * @private |
| 130 */ | 129 */ |
| 131 updateSupportedBrowsers_: function(browsers) { | 130 updateSupportedBrowsers_: function(browsers) { |
| 132 this.browserProfiles = browsers; | 131 this.browserProfiles = browsers; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 145 for (var i = 0; i < browserCount; i++) { | 144 for (var i = 0; i < browserCount; i++) { |
| 146 var browser = browsers[i] | 145 var browser = browsers[i] |
| 147 var option = new Option(browser['name'], browser['index']); | 146 var option = new Option(browser['name'], browser['index']); |
| 148 browserSelect.appendChild(option); | 147 browserSelect.appendChild(option); |
| 149 } | 148 } |
| 150 | 149 |
| 151 this.updateCheckboxes_(); | 150 this.updateCheckboxes_(); |
| 152 this.validateCommitButton_(); | 151 this.validateCommitButton_(); |
| 153 } | 152 } |
| 154 }, | 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_(); |
| 155 }; | 173 }; |
| 156 | 174 |
| 157 /** | 175 /** |
| 158 * Update the supported browsers popup with given entries. | 176 * Update the supported browsers popup with given entries. |
| 159 * @param {array} list of supported browsers name. | 177 * @param {array} list of supported browsers name. |
| 160 */ | 178 */ |
| 161 ImportDataOverlay.updateSupportedBrowsers = function(browsers) { | 179 ImportDataOverlay.updateSupportedBrowsers = function(browsers) { |
| 162 ImportDataOverlay.getInstance().updateSupportedBrowsers_(browsers); | 180 ImportDataOverlay.getInstance().updateSupportedBrowsers_(browsers); |
| 163 }; | 181 }; |
| 164 | 182 |
| 165 /** | 183 /** |
| 166 * Update the UI to reflect whether an import operation is in progress. | 184 * Update the UI to reflect whether an import operation is in progress. |
| 167 * @param {boolean} state True if an import operation is in progress. | 185 * @param {boolean} state True if an import operation is in progress. |
| 168 */ | 186 */ |
| 169 ImportDataOverlay.setImportingState = function(state) { | 187 ImportDataOverlay.setImportingState = function(state) { |
| 170 if (state) { | 188 var checkboxes = |
| 171 var checkboxes = | 189 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); |
| 172 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | 190 for (var i = 0; i < checkboxes.length; i++) |
| 173 for (var i = 0; i < checkboxes.length; i++) { | 191 checkboxes[i].setDisabled("Importing", state); |
| 174 checkboxes[i].disabled = true; | 192 if (!state) |
| 175 } | |
| 176 } else { | |
| 177 ImportDataOverlay.getInstance().updateCheckboxes_(); | 193 ImportDataOverlay.getInstance().updateCheckboxes_(); |
| 178 } | |
| 179 $('import-browsers').disabled = state; | 194 $('import-browsers').disabled = state; |
| 180 $('import-throbber').style.visibility = state ? "visible" : "hidden"; | 195 $('import-throbber').style.visibility = state ? "visible" : "hidden"; |
| 181 ImportDataOverlay.getInstance().validateCommitButton_(); | 196 ImportDataOverlay.getInstance().validateCommitButton_(); |
| 182 }; | 197 }; |
| 183 | 198 |
| 184 /** | 199 /** |
| 185 * Remove the import overlay from display. | 200 * Remove the import overlay from display. |
| 186 */ | 201 */ |
| 187 ImportDataOverlay.dismiss = function() { | 202 ImportDataOverlay.dismiss = function() { |
| 203 ImportDataOverlay.clearUserPrefs(); |
| 188 OptionsPage.closeOverlay(); | 204 OptionsPage.closeOverlay(); |
| 189 }; | 205 }; |
| 190 | 206 |
| 191 /** | 207 /** |
| 192 * Show a message confirming the success of the import operation. | 208 * Show a message confirming the success of the import operation. |
| 193 */ | 209 */ |
| 194 ImportDataOverlay.confirmSuccess = function() { | 210 ImportDataOverlay.confirmSuccess = function() { |
| 195 var showBookmarksMessage = $('import-favorites').checked; | 211 var showBookmarksMessage = $('import-favorites').checked; |
| 196 ImportDataOverlay.setImportingState(false); | 212 ImportDataOverlay.setImportingState(false); |
| 197 $('import-data-configure').hidden = true; | 213 $('import-data-configure').hidden = true; |
| 198 $('import-data-success').hidden = false; | 214 $('import-data-success').hidden = false; |
| 199 $('import-find-your-bookmarks').hidden = !showBookmarksMessage; | 215 $('import-find-your-bookmarks').hidden = !showBookmarksMessage; |
| 200 }; | 216 }; |
| 201 | 217 |
| 202 // Export | 218 // Export |
| 203 return { | 219 return { |
| 204 ImportDataOverlay: ImportDataOverlay | 220 ImportDataOverlay: ImportDataOverlay |
| 205 }; | 221 }; |
| 206 }); | 222 }); |
| OLD | NEW |