| 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(this, |
| 16 'importData', | 16 'importData', |
| 17 loadTimeData.getString('importDataOverlayTabTitle'), | 17 loadTimeData.getString('importDataOverlayTabTitle'), |
| 18 'import-data-overlay'); | 18 'import-data-overlay'); |
| 19 } | 19 } |
| 20 | 20 |
| 21 cr.addSingletonGetter(ImportDataOverlay); | 21 cr.addSingletonGetter(ImportDataOverlay); |
| 22 | 22 |
| 23 /** |
| 24 * @param {string} type The type of data to import. Used in the element's ID. |
| 25 */ |
| 26 function importable(type) { |
| 27 var id = 'import-' + type; |
| 28 return $(id).checked && !$(id + '-with-label').hidden; |
| 29 } |
| 30 |
| 23 ImportDataOverlay.prototype = { | 31 ImportDataOverlay.prototype = { |
| 24 // Inherit from Page. | 32 // Inherit from Page. |
| 25 __proto__: Page.prototype, | 33 __proto__: Page.prototype, |
| 26 | 34 |
| 27 /** @override */ | 35 /** @override */ |
| 28 initializePage: function() { | 36 initializePage: function() { |
| 29 Page.prototype.initializePage.call(this); | 37 Page.prototype.initializePage.call(this); |
| 30 | 38 |
| 31 var self = this; | 39 var self = this; |
| 32 var checkboxes = | 40 var checkboxes = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // Form controls are disabled until the profile list has been loaded. | 76 // Form controls are disabled until the profile list has been loaded. |
| 69 self.setAllControlsEnabled_(false); | 77 self.setAllControlsEnabled_(false); |
| 70 }, | 78 }, |
| 71 | 79 |
| 72 /** | 80 /** |
| 73 * Sets the enabled and checked state of the commit button. | 81 * Sets the enabled and checked state of the commit button. |
| 74 * @private | 82 * @private |
| 75 */ | 83 */ |
| 76 validateCommitButton_: function() { | 84 validateCommitButton_: function() { |
| 77 var somethingToImport = | 85 var somethingToImport = |
| 78 $('import-history').checked || $('import-favorites').checked || | 86 importable('history') || importable('favorites') || |
| 79 $('import-passwords').checked || $('import-search').checked || | 87 importable('passwords') || importable('search') || |
| 80 $('import-autofill-form-data').checked; | 88 importable('autofill-form-data'); |
| 81 $('import-data-commit').disabled = !somethingToImport; | 89 $('import-data-commit').disabled = !somethingToImport; |
| 82 $('import-choose-file').disabled = !$('import-favorites').checked; | 90 $('import-choose-file').disabled = !$('import-favorites').checked; |
| 83 }, | 91 }, |
| 84 | 92 |
| 85 /** | 93 /** |
| 86 * 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. |
| 87 * @private | 95 * @private |
| 88 */ | 96 */ |
| 89 setAllControlsEnabled_: function(enabled) { | 97 setAllControlsEnabled_: function(enabled) { |
| 90 var checkboxes = | 98 var checkboxes = |
| (...skipping 30 matching lines...) Expand all Loading... |
| 121 | 129 |
| 122 var browserProfile; | 130 var browserProfile; |
| 123 if (this.browserProfiles.length > index) | 131 if (this.browserProfiles.length > index) |
| 124 browserProfile = this.browserProfiles[index]; | 132 browserProfile = this.browserProfiles[index]; |
| 125 var importOptions = ['history', | 133 var importOptions = ['history', |
| 126 'favorites', | 134 'favorites', |
| 127 'passwords', | 135 'passwords', |
| 128 'search', | 136 'search', |
| 129 'autofill-form-data']; | 137 'autofill-form-data']; |
| 130 for (var i = 0; i < importOptions.length; i++) { | 138 for (var i = 0; i < importOptions.length; i++) { |
| 131 var checkbox = $('import-' + importOptions[i]); | 139 var id = 'import-' + importOptions[i]; |
| 132 var enable = browserProfile && browserProfile[importOptions[i]]; | 140 var enable = browserProfile && browserProfile[importOptions[i]]; |
| 133 this.setUpCheckboxState_(checkbox, enable); | 141 this.setUpCheckboxState_($(id), enable); |
| 134 var checkboxWithLabel = $('import-' + importOptions[i] + '-with-label'); | 142 $(id + '-with-label').hidden = !enable; |
| 135 checkboxWithLabel.style.display = enable ? '' : 'none'; | |
| 136 } | 143 } |
| 137 }, | 144 }, |
| 138 | 145 |
| 139 /** | 146 /** |
| 140 * Show or hide gray message at the bottom. | 147 * Show or hide gray message at the bottom. |
| 141 * @private | 148 * @private |
| 142 */ | 149 */ |
| 143 updateBottomBar_: function() { | 150 updateBottomBar_: function() { |
| 144 var index = $('import-browsers').selectedIndex; | 151 var index = $('import-browsers').selectedIndex; |
| 145 var browserProfile; | 152 var browserProfile; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 ImportDataOverlay.getInstance().validateCommitButton_(); | 277 ImportDataOverlay.getInstance().validateCommitButton_(); |
| 271 | 278 |
| 272 PageManager.showPageByName('importData'); | 279 PageManager.showPageByName('importData'); |
| 273 }; | 280 }; |
| 274 | 281 |
| 275 // Export | 282 // Export |
| 276 return { | 283 return { |
| 277 ImportDataOverlay: ImportDataOverlay | 284 ImportDataOverlay: ImportDataOverlay |
| 278 }; | 285 }; |
| 279 }); | 286 }); |
| OLD | NEW |