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