OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 Page = cr.ui.pageManager.Page; | 6 var Page = cr.ui.pageManager.Page; |
7 var PageManager = cr.ui.pageManager.PageManager; | 7 var PageManager = cr.ui.pageManager.PageManager; |
8 | 8 |
9 /** | 9 /** |
10 * ImportDataOverlay class | 10 * ImportDataOverlay class |
11 * Encapsulated handling of the 'Import Data' overlay page. | 11 * Encapsulated handling of the 'Import Data' overlay page. |
12 * @class | 12 * @class |
13 */ | 13 */ |
14 function ImportDataOverlay() { | 14 function ImportDataOverlay() { |
15 Page.call(this, | 15 Page.call( |
16 'importData', | 16 this, 'importData', loadTimeData.getString('importDataOverlayTabTitle'), |
17 loadTimeData.getString('importDataOverlayTabTitle'), | 17 'import-data-overlay'); |
18 'import-data-overlay'); | |
19 } | 18 } |
20 | 19 |
21 cr.addSingletonGetter(ImportDataOverlay); | 20 cr.addSingletonGetter(ImportDataOverlay); |
22 | 21 |
23 /** | 22 /** |
24 * @param {string} type The type of data to import. Used in the element's ID. | 23 * @param {string} type The type of data to import. Used in the element's ID. |
25 */ | 24 */ |
26 function importable(type) { | 25 function importable(type) { |
27 var id = 'import-' + type; | 26 var id = 'import-' + type; |
28 return $(id).checked && !$(id + '-with-label').hidden; | 27 return $(id).checked && !$(id + '-with-label').hidden; |
29 } | 28 } |
30 | 29 |
31 ImportDataOverlay.prototype = { | 30 ImportDataOverlay.prototype = { |
32 // Inherit from Page. | 31 // Inherit from Page. |
33 __proto__: Page.prototype, | 32 __proto__: Page.prototype, |
34 | 33 |
35 /** @override */ | 34 /** @override */ |
(...skipping 11 matching lines...) Expand all Loading... |
47 }; | 46 }; |
48 } | 47 } |
49 | 48 |
50 $('import-browsers').onchange = function() { | 49 $('import-browsers').onchange = function() { |
51 self.updateCheckboxes_(); | 50 self.updateCheckboxes_(); |
52 self.validateCommitButton_(); | 51 self.validateCommitButton_(); |
53 }; | 52 }; |
54 | 53 |
55 $('import-data-commit').onclick = function() { | 54 $('import-data-commit').onclick = function() { |
56 chrome.send('importData', [ | 55 chrome.send('importData', [ |
57 String($('import-browsers').selectedIndex), | 56 String($('import-browsers').selectedIndex), |
58 String($('import-history').checked), | 57 String($('import-history').checked), |
59 String($('import-favorites').checked), | 58 String($('import-favorites').checked), |
60 String($('import-passwords').checked), | 59 String($('import-passwords').checked), |
61 String($('import-search').checked), | 60 String($('import-search').checked), |
62 String($('import-autofill-form-data').checked)]); | 61 String($('import-autofill-form-data').checked) |
| 62 ]); |
63 }; | 63 }; |
64 | 64 |
65 $('import-data-cancel').onclick = function() { | 65 $('import-data-cancel').onclick = function() { |
66 ImportDataOverlay.dismiss(); | 66 ImportDataOverlay.dismiss(); |
67 }; | 67 }; |
68 | 68 |
69 $('import-choose-file').onclick = function() { | 69 $('import-choose-file').onclick = function() { |
70 chrome.send('chooseBookmarksFile'); | 70 chrome.send('chooseBookmarksFile'); |
71 }; | 71 }; |
72 | 72 |
73 $('import-data-confirm').onclick = function() { | 73 $('import-data-confirm').onclick = function() { |
74 ImportDataOverlay.dismiss(); | 74 ImportDataOverlay.dismiss(); |
75 }; | 75 }; |
76 | 76 |
77 // Form controls are disabled until the profile list has been loaded. | 77 // Form controls are disabled until the profile list has been loaded. |
78 self.setAllControlsEnabled_(false); | 78 self.setAllControlsEnabled_(false); |
79 }, | 79 }, |
80 | 80 |
81 /** | 81 /** |
82 * Sets the enabled and checked state of the commit button. | 82 * Sets the enabled and checked state of the commit button. |
83 * @private | 83 * @private |
84 */ | 84 */ |
85 validateCommitButton_: function() { | 85 validateCommitButton_: function() { |
86 var somethingToImport = | 86 var somethingToImport = importable('history') || |
87 importable('history') || importable('favorites') || | 87 importable('favorites') || importable('passwords') || |
88 importable('passwords') || importable('search') || | 88 importable('search') || importable('autofill-form-data'); |
89 importable('autofill-form-data'); | |
90 $('import-data-commit').disabled = !somethingToImport; | 89 $('import-data-commit').disabled = !somethingToImport; |
91 $('import-choose-file').disabled = !$('import-favorites').checked; | 90 $('import-choose-file').disabled = !$('import-favorites').checked; |
92 }, | 91 }, |
93 | 92 |
94 /** | 93 /** |
95 * Sets the enabled state of all the checkboxes and the commit button. | 94 * Sets the enabled state of all the checkboxes and the commit button. |
96 * @private | 95 * @private |
97 */ | 96 */ |
98 setAllControlsEnabled_: function(enabled) { | 97 setAllControlsEnabled_: function(enabled) { |
99 var checkboxes = | 98 var checkboxes = |
(...skipping 21 matching lines...) Expand all Loading... |
121 */ | 120 */ |
122 updateCheckboxes_: function() { | 121 updateCheckboxes_: function() { |
123 var index = $('import-browsers').selectedIndex; | 122 var index = $('import-browsers').selectedIndex; |
124 var bookmarksFileSelected = index == this.browserProfiles.length - 1; | 123 var bookmarksFileSelected = index == this.browserProfiles.length - 1; |
125 $('import-choose-file').hidden = !bookmarksFileSelected; | 124 $('import-choose-file').hidden = !bookmarksFileSelected; |
126 $('import-data-commit').hidden = bookmarksFileSelected; | 125 $('import-data-commit').hidden = bookmarksFileSelected; |
127 | 126 |
128 var browserProfile; | 127 var browserProfile; |
129 if (this.browserProfiles.length > index) | 128 if (this.browserProfiles.length > index) |
130 browserProfile = this.browserProfiles[index]; | 129 browserProfile = this.browserProfiles[index]; |
131 var importOptions = ['history', | 130 var importOptions = |
132 'favorites', | 131 ['history', 'favorites', 'passwords', 'search', 'autofill-form-data']; |
133 'passwords', | |
134 'search', | |
135 'autofill-form-data']; | |
136 for (var i = 0; i < importOptions.length; i++) { | 132 for (var i = 0; i < importOptions.length; i++) { |
137 var id = 'import-' + importOptions[i]; | 133 var id = 'import-' + importOptions[i]; |
138 var enable = browserProfile && browserProfile[importOptions[i]]; | 134 var enable = browserProfile && browserProfile[importOptions[i]]; |
139 this.setUpCheckboxState_($(id), enable); | 135 this.setUpCheckboxState_($(id), enable); |
140 $(id + '-with-label').hidden = !enable; | 136 $(id + '-with-label').hidden = !enable; |
141 } | 137 } |
142 }, | 138 }, |
143 | 139 |
144 /** | 140 /** |
145 * Update the supported browsers popup with given entries. | 141 * Update the supported browsers popup with given entries. |
146 * @param {Array} browsers List of supported browsers name. | 142 * @param {Array} browsers List of supported browsers name. |
147 * @private | 143 * @private |
148 */ | 144 */ |
149 updateSupportedBrowsers_: function(browsers) { | 145 updateSupportedBrowsers_: function(browsers) { |
150 this.browserProfiles = browsers; | 146 this.browserProfiles = browsers; |
151 var browserSelect = /** @type {HTMLSelectElement} */( | 147 var browserSelect = |
152 $('import-browsers')); | 148 /** @type {HTMLSelectElement} */ ($('import-browsers')); |
153 browserSelect.remove(0); // Remove the 'Loading...' option. | 149 browserSelect.remove(0); // Remove the 'Loading...' option. |
154 browserSelect.textContent = ''; | 150 browserSelect.textContent = ''; |
155 var browserCount = browsers.length; | 151 var browserCount = browsers.length; |
156 | 152 |
157 if (browserCount == 0) { | 153 if (browserCount == 0) { |
158 var option = new Option(loadTimeData.getString('noProfileFound'), 0); | 154 var option = new Option(loadTimeData.getString('noProfileFound'), 0); |
159 browserSelect.appendChild(option); | 155 browserSelect.appendChild(option); |
160 | 156 |
161 this.setAllControlsEnabled_(false); | 157 this.setAllControlsEnabled_(false); |
162 } else { | 158 } else { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 }; | 213 }; |
218 | 214 |
219 /** | 215 /** |
220 * Update the UI to reflect whether an import operation is in progress. | 216 * Update the UI to reflect whether an import operation is in progress. |
221 * @param {boolean} importing True if an import operation is in progress. | 217 * @param {boolean} importing True if an import operation is in progress. |
222 */ | 218 */ |
223 ImportDataOverlay.setImportingState = function(importing) { | 219 ImportDataOverlay.setImportingState = function(importing) { |
224 var checkboxes = | 220 var checkboxes = |
225 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | 221 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); |
226 for (var i = 0; i < checkboxes.length; i++) | 222 for (var i = 0; i < checkboxes.length; i++) |
227 checkboxes[i].setDisabled('Importing', importing); | 223 checkboxes[i].setDisabled('Importing', importing); |
228 if (!importing) | 224 if (!importing) |
229 ImportDataOverlay.getInstance().updateCheckboxes_(); | 225 ImportDataOverlay.getInstance().updateCheckboxes_(); |
230 $('import-browsers').disabled = importing; | 226 $('import-browsers').disabled = importing; |
231 $('import-throbber').style.visibility = importing ? 'visible' : 'hidden'; | 227 $('import-throbber').style.visibility = importing ? 'visible' : 'hidden'; |
232 ImportDataOverlay.getInstance().validateCommitButton_(); | 228 ImportDataOverlay.getInstance().validateCommitButton_(); |
233 }; | 229 }; |
234 | 230 |
235 /** | 231 /** |
236 * Remove the import overlay from display. | 232 * Remove the import overlay from display. |
237 */ | 233 */ |
(...skipping 18 matching lines...) Expand all Loading... |
256 ImportDataOverlay.show = function() { | 252 ImportDataOverlay.show = function() { |
257 // Make sure that any previous import success message is hidden, and | 253 // Make sure that any previous import success message is hidden, and |
258 // we're showing the UI to import further data. | 254 // we're showing the UI to import further data. |
259 ImportDataOverlay.getInstance().updateSuccessState_(false); | 255 ImportDataOverlay.getInstance().updateSuccessState_(false); |
260 ImportDataOverlay.getInstance().validateCommitButton_(); | 256 ImportDataOverlay.getInstance().validateCommitButton_(); |
261 | 257 |
262 PageManager.showPageByName('importData'); | 258 PageManager.showPageByName('importData'); |
263 }; | 259 }; |
264 | 260 |
265 // Export | 261 // Export |
266 return { | 262 return {ImportDataOverlay: ImportDataOverlay}; |
267 ImportDataOverlay: ImportDataOverlay | |
268 }; | |
269 }); | 263 }); |
OLD | NEW |