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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 $('import-history').checked || $('import-favorites').checked || | 81 $('import-history').checked || $('import-favorites').checked || |
82 $('import-passwords').checked || $('import-search').checked; | 82 $('import-passwords').checked || $('import-search').checked; |
83 $('import-data-commit').disabled = !somethingToImport; | 83 $('import-data-commit').disabled = !somethingToImport; |
84 }, | 84 }, |
85 | 85 |
86 /** | 86 /** |
87 * Sets the sensitivity of all the checkboxes and the commit button. | 87 * Sets the sensitivity of all the checkboxes and the commit button. |
88 * @private | 88 * @private |
89 */ | 89 */ |
90 setControlsSensitive_: function(sensitive) { | 90 setControlsSensitive_: function(sensitive) { |
91 var checkboxes = | 91 var importOptions = ['history', 'favorites', 'passwords', 'search']; |
92 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | 92 for (var i = 0; i < importOptions.length; i++) { |
93 for (var i = 0; i < checkboxes.length; i++) | 93 var checkbox = $('import-' + importOptions[i]); |
94 this.setUpCheckboxState_(checkboxes[i], sensitive); | 94 this.setUpCheckboxState_(checkbox, sensitive); |
95 } | |
95 $('import-data-commit').disabled = !sensitive; | 96 $('import-data-commit').disabled = !sensitive; |
96 }, | 97 }, |
97 | 98 |
98 /** | 99 /** |
99 * Set enabled and checked states a checkbox element. | 100 * Set enabled and checked states a checkbox element. |
100 * @param {Object} checkbox A checkbox element. | 101 * @param {Object} checkbox A checkbox element. |
101 * @param {boolean} enabled The enabled state of the chekbox. | 102 * @param {boolean} enabled The enabled state of the chekbox. |
102 * @private | 103 * @private |
103 */ | 104 */ |
104 setUpCheckboxState_: function(checkbox, enabled) { | 105 setUpCheckboxState_: function(checkbox, enabled) { |
105 checkbox.disabled = !enabled; | 106 checkbox.setDisabled("noProfileData", !enabled); |
106 checkbox.checked = enabled; | |
107 }, | 107 }, |
108 | 108 |
109 /** | 109 /** |
110 * Update the enabled and checked states of all checkboxes. | 110 * Update the enabled and checked states of all checkboxes. |
111 * @private | 111 * @private |
112 */ | 112 */ |
113 updateCheckboxes_: function() { | 113 updateCheckboxes_: function() { |
114 var index = $('import-browsers').selectedIndex; | 114 var index = $('import-browsers').selectedIndex; |
115 var browserProfile; | 115 var browserProfile; |
116 if (this.browserProfiles.length > index) | 116 if (this.browserProfiles.length > index) |
117 browserProfile = this.browserProfiles[index]; | 117 browserProfile = this.browserProfiles[index]; |
118 var importOptions = ['history', 'favorites', 'passwords', 'search']; | 118 var importOptions = ['history', 'favorites', 'passwords', 'search']; |
119 for (var i = 0; i < importOptions.length; i++) { | 119 for (var i = 0; i < importOptions.length; i++) { |
120 var checkbox = $('import-' + importOptions[i]); | 120 var checkbox = $('import-' + importOptions[i]); |
121 this.setUpCheckboxState_(checkbox, | 121 var enable = browserProfile && browserProfile[importOptions[i]]; |
122 browserProfile ? browserProfile[importOptions[i]] : false); | 122 this.setUpCheckboxState_(checkbox, enable); |
123 } | 123 } |
124 }, | 124 }, |
125 | 125 |
126 /** | 126 /** |
127 * Update the supported browsers popup with given entries. | 127 * Update the supported browsers popup with given entries. |
128 * @param {array} browsers List of supported browsers name. | 128 * @param {array} browsers List of supported browsers name. |
129 * @private | 129 * @private |
130 */ | 130 */ |
131 updateSupportedBrowsers_: function(browsers) { | 131 updateSupportedBrowsers_: function(browsers) { |
132 this.browserProfiles = browsers; | 132 this.browserProfiles = browsers; |
(...skipping 12 matching lines...) Expand all Loading... | |
145 for (var i = 0; i < browserCount; i++) { | 145 for (var i = 0; i < browserCount; i++) { |
146 var browser = browsers[i] | 146 var browser = browsers[i] |
147 var option = new Option(browser['name'], browser['index']); | 147 var option = new Option(browser['name'], browser['index']); |
148 browserSelect.appendChild(option); | 148 browserSelect.appendChild(option); |
149 } | 149 } |
150 | 150 |
151 this.updateCheckboxes_(); | 151 this.updateCheckboxes_(); |
152 this.validateCommitButton_(); | 152 this.validateCommitButton_(); |
153 } | 153 } |
154 }, | 154 }, |
155 | |
156 /** | |
157 * Clear import prefs set when user checks/unchecks a checkbox so that each | |
158 * checkbox goes back to the default "checked" state (or alternatively, to | |
159 * the state set by a recommended policy). | |
160 * @private | |
161 */ | |
162 clearUserPrefs_: function() { | |
163 var importPrefs = ['import_history', | |
164 'import_bookmarks', | |
165 'import_saved_passwords', | |
166 'import_search_engine']; | |
167 for (var i = 0; i < importPrefs.length; i++) | |
168 Preferences.clearPref(importPrefs[i], undefined); | |
Mattias Nissler (ping if slow)
2011/07/25 11:12:36
indentation
| |
169 }, | |
170 }; | |
171 | |
172 ImportDataOverlay.clearUserPrefs = function() { | |
173 ImportDataOverlay.getInstance().clearUserPrefs_(); | |
155 }; | 174 }; |
156 | 175 |
157 /** | 176 /** |
158 * Update the supported browsers popup with given entries. | 177 * Update the supported browsers popup with given entries. |
159 * @param {array} list of supported browsers name. | 178 * @param {array} list of supported browsers name. |
160 */ | 179 */ |
161 ImportDataOverlay.updateSupportedBrowsers = function(browsers) { | 180 ImportDataOverlay.updateSupportedBrowsers = function(browsers) { |
162 ImportDataOverlay.getInstance().updateSupportedBrowsers_(browsers); | 181 ImportDataOverlay.getInstance().updateSupportedBrowsers_(browsers); |
163 }; | 182 }; |
164 | 183 |
165 /** | 184 /** |
166 * Update the UI to reflect whether an import operation is in progress. | 185 * Update the UI to reflect whether an import operation is in progress. |
167 * @param {boolean} state True if an import operation is in progress. | 186 * @param {boolean} state True if an import operation is in progress. |
168 */ | 187 */ |
169 ImportDataOverlay.setImportingState = function(state) { | 188 ImportDataOverlay.setImportingState = function(state) { |
189 var checkboxes = | |
190 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | |
170 if (state) { | 191 if (state) { |
171 var checkboxes = | |
172 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | |
173 for (var i = 0; i < checkboxes.length; i++) { | 192 for (var i = 0; i < checkboxes.length; i++) { |
174 checkboxes[i].disabled = true; | 193 checkboxes[i].setDisabled("Importing", true); |
175 } | 194 } |
176 } else { | 195 } else { |
196 for (var i = 0; i < checkboxes.length; i++) | |
197 checkboxes[i].setDisabled("Importing", false); | |
177 ImportDataOverlay.getInstance().updateCheckboxes_(); | 198 ImportDataOverlay.getInstance().updateCheckboxes_(); |
178 } | 199 } |
179 $('import-browsers').disabled = state; | 200 $('import-browsers').disabled = state; |
180 $('import-throbber').style.visibility = state ? "visible" : "hidden"; | 201 $('import-throbber').style.visibility = state ? "visible" : "hidden"; |
181 ImportDataOverlay.getInstance().validateCommitButton_(); | 202 ImportDataOverlay.getInstance().validateCommitButton_(); |
182 }; | 203 }; |
183 | 204 |
184 /** | 205 /** |
185 * Remove the import overlay from display. | 206 * Remove the import overlay from display. |
186 */ | 207 */ |
187 ImportDataOverlay.dismiss = function() { | 208 ImportDataOverlay.dismiss = function() { |
209 ImportDataOverlay.clearUserPrefs(); | |
188 OptionsPage.closeOverlay(); | 210 OptionsPage.closeOverlay(); |
189 }; | 211 }; |
190 | 212 |
191 /** | 213 /** |
192 * Show a message confirming the success of the import operation. | 214 * Show a message confirming the success of the import operation. |
193 */ | 215 */ |
194 ImportDataOverlay.confirmSuccess = function() { | 216 ImportDataOverlay.confirmSuccess = function() { |
195 var showBookmarksMessage = $('import-favorites').checked; | 217 var showBookmarksMessage = $('import-favorites').checked; |
196 ImportDataOverlay.setImportingState(false); | 218 ImportDataOverlay.setImportingState(false); |
197 $('import-data-configure').hidden = true; | 219 $('import-data-configure').hidden = true; |
198 $('import-data-success').hidden = false; | 220 $('import-data-success').hidden = false; |
199 $('import-find-your-bookmarks').hidden = !showBookmarksMessage; | 221 $('import-find-your-bookmarks').hidden = !showBookmarksMessage; |
200 }; | 222 }; |
201 | 223 |
202 // Export | 224 // Export |
203 return { | 225 return { |
204 ImportDataOverlay: ImportDataOverlay | 226 ImportDataOverlay: ImportDataOverlay |
205 }; | 227 }; |
206 }); | 228 }); |
OLD | NEW |