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. |
11 * @class | 11 * @class |
12 */ | 12 */ |
13 function ImportDataOverlay() { | 13 function ImportDataOverlay() { |
14 OptionsPage.call(this, | 14 OptionsPage.call(this, |
15 'importData', | 15 'importData', |
16 templateData.importDataOverlayTabTitle, | 16 templateData.importDataOverlayTabTitle, |
17 'import-data-overlay'); | 17 'import-data-overlay'); |
18 } | 18 } |
19 | 19 |
20 cr.addSingletonGetter(ImportDataOverlay); | 20 cr.addSingletonGetter(ImportDataOverlay); |
21 | 21 |
22 ImportDataOverlay.prototype = { | 22 ImportDataOverlay.prototype = { |
23 // Inherit from OptionsPage. | 23 // Inherit from OptionsPage. |
24 __proto__: OptionsPage.prototype, | 24 __proto__: OptionsPage.prototype, |
25 | 25 |
26 import_history_pref: { | |
27 'name': 'import_history', | |
28 'value': true, | |
29 'managed': false | |
30 }, | |
31 | |
32 import_favorites_pref: { | |
33 'name': 'import_bookmarks', | |
34 'value': true, | |
35 'managed': false | |
36 }, | |
37 | |
38 import_passwords_pref: { | |
39 'name': 'import_saved_passwords', | |
40 'value': true, | |
41 'managed': false | |
42 }, | |
43 | |
44 import_search_pref: { | |
45 'name': 'import_search_engine', | |
46 'value': true, | |
47 'managed': false | |
48 }, | |
49 | |
26 /** | 50 /** |
27 * Initialize the page. | 51 * Initialize the page. |
28 */ | 52 */ |
29 initializePage: function() { | 53 initializePage: function() { |
30 // Call base class implementation to start preference initialization. | 54 // Call base class implementation to start preference initialization. |
31 OptionsPage.prototype.initializePage.call(this); | 55 OptionsPage.prototype.initializePage.call(this); |
32 | 56 |
33 var self = this; | 57 var self = this; |
34 var checkboxes = | 58 var checkboxes = |
35 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | 59 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); |
36 for (var i = 0; i < checkboxes.length; i++) { | 60 for (var i = 0; i < checkboxes.length; i++) { |
37 checkboxes[i].onchange = function() { | 61 checkboxes[i].onchange = function() { |
38 self.validateCommitButton_(); | 62 self.validateCommitButton_(); |
39 }; | 63 }; |
40 } | 64 } |
41 | 65 |
42 $('import-browsers').onchange = function() { | |
43 self.updateCheckboxes_(); | |
44 self.validateCommitButton_(); | |
45 }; | |
simo
2011/07/19 12:24:47
just noticed that I removed this by mistake so I'l
| |
46 | |
47 $('import-data-commit').onclick = function() { | 66 $('import-data-commit').onclick = function() { |
48 chrome.send('importData', [ | 67 chrome.send('importData', [ |
49 String($('import-browsers').selectedIndex), | 68 String($('import-browsers').selectedIndex), |
50 String($('import-history').checked), | 69 String($('import-history').checked), |
51 String($('import-favorites').checked), | 70 String($('import-favorites').checked), |
52 String($('import-passwords').checked), | 71 String($('import-passwords').checked), |
53 String($('import-search').checked)]); | 72 String($('import-search').checked)]); |
54 }; | 73 }; |
55 | 74 |
56 $('import-data-cancel').onclick = function() { | 75 $('import-data-cancel').onclick = function() { |
57 ImportDataOverlay.dismiss(); | 76 ImportDataOverlay.dismiss(); |
58 }; | 77 }; |
59 | 78 |
60 $('import-data-show-bookmarks-bar').onchange = function() { | 79 $('import-data-show-bookmarks-bar').onchange = function() { |
61 // Note: The callback 'toggleShowBookmarksBar' is handled within the | 80 // Note: The callback 'toggleShowBookmarksBar' is handled within the |
62 // browser options handler -- rather than the import data handler -- | 81 // browser options handler -- rather than the import data handler -- |
63 // as the implementation is shared by several clients. | 82 // as the implementation is shared by several clients. |
64 chrome.send('toggleShowBookmarksBar'); | 83 chrome.send('toggleShowBookmarksBar'); |
65 } | 84 } |
66 | 85 |
67 $('import-data-confirm').onclick = function() { | 86 $('import-data-confirm').onclick = function() { |
68 ImportDataOverlay.dismiss(); | 87 ImportDataOverlay.dismiss(); |
69 }; | 88 }; |
70 | 89 |
90 // Initialize control enabled states. | |
91 Preferences.getInstance().addEventListener( | |
92 self.import_history_pref.name, | |
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
Indentation should be +4 spaces after a line break
| |
93 function(event) { | |
94 self.handleImportPrefChange_( | |
95 self.import_history_pref, | |
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
same here, but it'll probably fit on the previous
| |
96 event); | |
97 if (this.browserProfiles != undefined) { | |
98 self.updateCheckboxes_(); | |
99 self.validateCommitButton_(); | |
100 } | |
101 }); | |
102 Preferences.getInstance().addEventListener( | |
103 self.import_favorites_pref.name, | |
104 function(event) { | |
105 self.handleImportPrefChange_( | |
106 self.import_favorites_pref, | |
107 event); | |
108 if (this.browserProfiles != undefined) { | |
109 self.updateCheckboxes_(); | |
110 self.validateCommitButton_(); | |
111 } | |
112 }); | |
113 Preferences.getInstance().addEventListener( | |
114 self.import_passwords_pref.name, | |
115 function(event) { | |
116 self.handleImportPrefChange_( | |
117 self.import_passwords_pref, | |
118 event); | |
119 if (this.browserProfiles != undefined) { | |
120 self.updateCheckboxes_(); | |
121 self.validateCommitButton_(); | |
122 } | |
123 }); | |
124 Preferences.getInstance().addEventListener( | |
125 self.import_search_pref.name, | |
126 function(event) { | |
127 self.handleImportPrefChange_( | |
128 self.import_search_pref, | |
129 event); | |
130 if (this.browserProfiles != undefined) { | |
131 self.updateCheckboxes_(); | |
132 self.validateCommitButton_(); | |
133 } | |
134 }); | |
135 | |
71 // Form controls are disabled until the profile list has been loaded. | 136 // Form controls are disabled until the profile list has been loaded. |
72 self.setControlsSensitive_(false); | 137 self.setControlsSensitive_(false); |
73 }, | 138 }, |
74 | 139 |
75 /** | 140 /** |
76 * Set enabled and checked state of the commit button. | 141 * Set enabled and checked state of the commit button. |
77 * @private | 142 * @private |
78 */ | 143 */ |
79 validateCommitButton_: function() { | 144 validateCommitButton_: function() { |
80 var somethingToImport = | 145 var somethingToImport = |
81 $('import-history').checked || $('import-favorites').checked || | 146 $('import-history').checked || $('import-favorites').checked || |
82 $('import-passwords').checked || $('import-search').checked; | 147 $('import-passwords').checked || $('import-search').checked; |
83 $('import-data-commit').disabled = !somethingToImport; | 148 $('import-data-commit').disabled = !somethingToImport; |
84 }, | 149 }, |
85 | 150 |
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
only one blank line
| |
151 | |
152 /** | |
153 * Returns true if the checkbox should be enabled. | |
154 * @returns {boolean} Whether the checkbox should be enabled. | |
155 * @private | |
156 */ | |
157 shouldEnableCheckbox_: function(checkbox) { | |
158 if (checkbox == $('import-history')) | |
159 return !this.import_history_pref.managed; | |
160 if (checkbox == $('import-favorites')) | |
161 return !this.import_favorites_pref.managed; | |
162 if (checkbox == $('import-passwords')) | |
163 return !this.import_passwords_pref.managed; | |
164 if (checkbox == $('import-search')) | |
165 return !this.import_search_pref.managed; | |
166 }, | |
167 | |
168 /** | |
169 * Returns true if the checkbox should be enabled. | |
170 * @returns {boolean} Whether the checkbox should be enabled. | |
171 * @private | |
172 */ | |
173 shouldCheckCheckbox_: function(checkbox) { | |
174 if (checkbox == $('import-history')) | |
175 return this.import_history_pref.value; | |
176 if (checkbox == $('import-favorites')) | |
177 return this.import_favorites_pref.value; | |
178 if (checkbox == $('import-passwords')) | |
179 return this.import_passwords_pref.value; | |
180 if (checkbox == $('import-search')) | |
181 return this.import_search_pref.value; | |
182 }, | |
183 | |
86 /** | 184 /** |
87 * Sets the sensitivity of all the checkboxes and the commit button. | 185 * Sets the sensitivity of all the checkboxes and the commit button. |
88 * @private | 186 * @private |
89 */ | 187 */ |
90 setControlsSensitive_: function(sensitive) { | 188 setControlsSensitive_: function(sensitive) { |
189 | |
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
don't need this blank line.
| |
91 var checkboxes = | 190 var checkboxes = |
92 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | 191 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); |
93 for (var i = 0; i < checkboxes.length; i++) | 192 for (var i = 0; i < checkboxes.length; i++) { |
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
In this block, it might be simpler to just grab th
| |
94 this.setUpCheckboxState_(checkboxes[i], sensitive); | 193 var enabled = this.shouldEnableCheckbox_(checkboxes[i]) && sensitive; |
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
+2 space indentation.
| |
194 this.setUpCheckboxState_(checkboxes[i], | |
195 enabled, | |
196 this.shouldCheckCheckbox_(checkboxes[i])); | |
197 } | |
95 $('import-data-commit').disabled = !sensitive; | 198 $('import-data-commit').disabled = !sensitive; |
96 }, | 199 }, |
97 | 200 |
98 /** | 201 /** |
99 * Set enabled and checked states a checkbox element. | 202 * Set enabled and checked states a checkbox element. |
100 * @param {Object} checkbox A checkbox element. | 203 * @param {Object} checkbox A checkbox element. |
101 * @param {boolean} enabled The enabled state of the chekbox. | 204 * @param {boolean} enabled The enabled state of the chekbox. |
102 * @private | 205 * @private |
103 */ | 206 */ |
104 setUpCheckboxState_: function(checkbox, enabled) { | 207 setUpCheckboxState_: function(checkbox, enabled, checked) { |
105 checkbox.disabled = !enabled; | 208 checkbox.disabled = !enabled; |
106 checkbox.checked = enabled; | 209 checkbox.checked = checked; |
107 }, | 210 }, |
108 | 211 |
109 /** | 212 /** |
110 * Update the enabled and checked states of all checkboxes. | 213 * Update the enabled and checked states of all checkboxes. |
111 * @private | 214 * @private |
112 */ | 215 */ |
113 updateCheckboxes_: function() { | 216 updateCheckboxes_: function() { |
114 var index = $('import-browsers').selectedIndex; | 217 var index = $('import-browsers').selectedIndex; |
115 var browserProfile; | 218 var browserProfile; |
116 if (this.browserProfiles.length > index) | 219 if (this.browserProfiles.length > index) |
117 browserProfile = this.browserProfiles[index]; | 220 browserProfile = this.browserProfiles[index]; |
118 var importOptions = ['history', 'favorites', 'passwords', 'search']; | 221 var importOptions = ['history', 'favorites', 'passwords', 'search']; |
222 var importPrefs = [this.import_history_pref, | |
223 this.import_favorites_pref, | |
224 this.import_passwords_pref, | |
225 this.import_search_pref]; | |
119 for (var i = 0; i < importOptions.length; i++) { | 226 for (var i = 0; i < importOptions.length; i++) { |
120 var checkbox = $('import-' + importOptions[i]); | 227 var checkbox = $('import-' + importOptions[i]); |
121 this.setUpCheckboxState_(checkbox, | 228 var enabled = !importPrefs[i].managed |
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
&& goes on this line
| |
122 browserProfile ? browserProfile[importOptions[i]] : false); | 229 && browserProfile[importOptions[i]]; |
230 var checked = importPrefs[i].value; | |
231 this.setUpCheckboxState_(checkbox, enabled, checked); | |
123 } | 232 } |
124 }, | 233 }, |
125 | 234 |
126 /** | 235 /** |
236 * Handles change event of the different import preferences | |
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
missing period, also 2 lines below.
| |
237 * @param {pref} preference object corresponding to the preference | |
238 * that changed | |
239 * @param {event} change event | |
240 * @private | |
241 */ | |
242 handleImportPrefChange_: function(pref, event) { | |
243 pref.value = event.value['value']; | |
244 pref.managed = event.value['managed']; | |
245 }, | |
246 | |
247 /** | |
127 * Update the supported browsers popup with given entries. | 248 * Update the supported browsers popup with given entries. |
128 * @param {array} browsers List of supported browsers name. | 249 * @param {array} browsers List of supported browsers name. |
129 * @private | 250 * @private |
130 */ | 251 */ |
131 updateSupportedBrowsers_: function(browsers) { | 252 updateSupportedBrowsers_: function(browsers) { |
132 this.browserProfiles = browsers; | 253 this.browserProfiles = browsers; |
133 var browserSelect = $('import-browsers'); | 254 var browserSelect = $('import-browsers'); |
134 browserSelect.remove(0); // Remove the 'Loading...' option. | 255 browserSelect.remove(0); // Remove the 'Loading...' option. |
135 browserSelect.textContent = ''; | 256 browserSelect.textContent = ''; |
136 var browserCount = browsers.length; | 257 var browserCount = browsers.length; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 } | 299 } |
179 $('import-browsers').disabled = state; | 300 $('import-browsers').disabled = state; |
180 $('import-throbber').style.visibility = state ? "visible" : "hidden"; | 301 $('import-throbber').style.visibility = state ? "visible" : "hidden"; |
181 ImportDataOverlay.getInstance().validateCommitButton_(); | 302 ImportDataOverlay.getInstance().validateCommitButton_(); |
182 }; | 303 }; |
183 | 304 |
184 /** | 305 /** |
185 * Remove the import overlay from display. | 306 * Remove the import overlay from display. |
186 */ | 307 */ |
187 ImportDataOverlay.dismiss = function() { | 308 ImportDataOverlay.dismiss = function() { |
309 ImportDataOverlay.setImportingState(false); | |
188 OptionsPage.closeOverlay(); | 310 OptionsPage.closeOverlay(); |
189 }; | 311 }; |
190 | 312 |
191 /** | 313 /** |
192 * Show a message confirming the success of the import operation. | 314 * Show a message confirming the success of the import operation. |
193 */ | 315 */ |
194 ImportDataOverlay.confirmSuccess = function() { | 316 ImportDataOverlay.confirmSuccess = function() { |
195 var showBookmarksMessage = $('import-favorites').checked; | 317 var showBookmarksMessage = $('import-favorites').checked; |
196 ImportDataOverlay.setImportingState(false); | 318 ImportDataOverlay.setImportingState(false); |
197 $('import-data-configure').hidden = true; | 319 $('import-data-configure').hidden = true; |
198 $('import-data-success').hidden = false; | 320 $('import-data-success').hidden = false; |
199 $('import-find-your-bookmarks').hidden = !showBookmarksMessage; | 321 $('import-find-your-bookmarks').hidden = !showBookmarksMessage; |
200 }; | 322 }; |
201 | 323 |
202 // Export | 324 // Export |
203 return { | 325 return { |
204 ImportDataOverlay: ImportDataOverlay | 326 ImportDataOverlay: ImportDataOverlay |
205 }; | 327 }; |
206 }); | 328 }); |
OLD | NEW |