| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 6 |
| 7 var OptionsPage = options.OptionsPage; | 7 var OptionsPage = options.OptionsPage; |
| 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 OptionsPage.call(this, 'importDataOverlay', | 15 OptionsPage.call(this, |
| 16 'importDataOverlay', |
| 16 templateData.import_data_title, | 17 templateData.import_data_title, |
| 17 'importDataOverlay'); | 18 'import-data-overlay'); |
| 18 } | 19 } |
| 19 | 20 |
| 20 ImportDataOverlay.throbIntervalId = 0; | 21 ImportDataOverlay.throbIntervalId = 0; |
| 21 | 22 |
| 22 cr.addSingletonGetter(ImportDataOverlay); | 23 cr.addSingletonGetter(ImportDataOverlay); |
| 23 | 24 |
| 24 ImportDataOverlay.prototype = { | 25 ImportDataOverlay.prototype = { |
| 25 // Inherit from OptionsPage. | 26 // Inherit from OptionsPage. |
| 26 __proto__: OptionsPage.prototype, | 27 __proto__: OptionsPage.prototype, |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * Initialize the page. | 30 * Initialize the page. |
| 30 */ | 31 */ |
| 31 initializePage: function() { | 32 initializePage: function() { |
| 32 // Call base class implementation to starts preference initialization. | 33 // Call base class implementation to start preference initialization. |
| 33 OptionsPage.prototype.initializePage.call(this); | 34 OptionsPage.prototype.initializePage.call(this); |
| 34 | 35 |
| 35 var self = this; | 36 var self = this; |
| 36 var checkboxes = | 37 var checkboxes = |
| 37 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); | 38 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); |
| 38 for (var i = 0; i < checkboxes.length; i++) { | 39 for (var i = 0; i < checkboxes.length; i++) { |
| 39 checkboxes[i].onchange = function() { | 40 checkboxes[i].onchange = function() { |
| 40 self.validateCommitButton_(); | 41 self.validateCommitButton_(); |
| 41 }; | 42 }; |
| 42 } | 43 } |
| 43 | 44 |
| 44 $('import-browsers').onchange = function() { | 45 $('import-browsers').onchange = function() { |
| 45 self.updateCheckboxes_(); | 46 self.updateCheckboxes_(); |
| 46 self.validateCommitButton_(); | 47 self.validateCommitButton_(); |
| 47 } | 48 }; |
| 48 | 49 |
| 49 $('import-data-commit').onclick = function() { | 50 $('import-data-commit').onclick = function() { |
| 50 chrome.send('importData', [ | 51 chrome.send('importData', [ |
| 51 String($('import-browsers').selectedIndex), | 52 String($('import-browsers').selectedIndex), |
| 52 String($('import-history').checked), | 53 String($('import-history').checked), |
| 53 String($('import-favorites').checked), | 54 String($('import-favorites').checked), |
| 54 String($('import-passwords').checked), | 55 String($('import-passwords').checked), |
| 55 String($('import-search').checked)]); | 56 String($('import-search').checked)]); |
| 56 } | 57 }; |
| 57 | 58 |
| 58 $('import-data-cancel').onclick = function() { | 59 $('import-data-cancel').onclick = function() { |
| 59 ImportDataOverlay.dismiss(); | 60 ImportDataOverlay.dismiss(); |
| 60 } | 61 }; |
| 62 |
| 63 // Form controls are disabled until the profile list has been loaded. |
| 64 self.setControlsSensitive_(false); |
| 61 }, | 65 }, |
| 62 | 66 |
| 63 /** | 67 /** |
| 64 * Set enabled and checked state of the commit button. | 68 * Set enabled and checked state of the commit button. |
| 65 * @private | 69 * @private |
| 66 */ | 70 */ |
| 67 validateCommitButton_: function() { | 71 validateCommitButton_: function() { |
| 68 var somethingToImport = | 72 var somethingToImport = |
| 69 $('import-history').checked || $('import-favorites').checked || | 73 $('import-history').checked || $('import-favorites').checked || |
| 70 $('import-passwords').checked || $('import-search').checked; | 74 $('import-passwords').checked || $('import-search').checked; |
| 71 $('import-data-commit').disabled = !somethingToImport; | 75 $('import-data-commit').disabled = !somethingToImport; |
| 72 }, | 76 }, |
| 73 | 77 |
| 74 /** | 78 /** |
| 79 * Sets the sensitivity of all the checkboxes and the commit button. |
| 80 * @private |
| 81 */ |
| 82 setControlsSensitive_: function(sensitive) { |
| 83 var checkboxes = |
| 84 document.querySelectorAll('#import-checkboxes input[type=checkbox]'); |
| 85 for (var i = 0; i < checkboxes.length; i++) |
| 86 this.setUpCheckboxState_(checkboxes[i], sensitive); |
| 87 $('import-data-commit').disabled = !sensitive; |
| 88 }, |
| 89 |
| 90 /** |
| 75 * Set enabled and checked states a checkbox element. | 91 * Set enabled and checked states a checkbox element. |
| 76 * @param {Object} checkbox A checkbox element. | 92 * @param {Object} checkbox A checkbox element. |
| 77 * @param {boolean} enabled The enabled state of the chekbox. | 93 * @param {boolean} enabled The enabled state of the chekbox. |
| 78 * @private | 94 * @private |
| 79 */ | 95 */ |
| 80 setUpCheckboxState_: function(checkbox, enabled) { | 96 setUpCheckboxState_: function(checkbox, enabled) { |
| 81 checkbox.disabled = !enabled; | 97 checkbox.disabled = !enabled; |
| 82 checkbox.checked = enabled; | 98 checkbox.checked = enabled; |
| 83 }, | 99 }, |
| 84 | 100 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 101 * @param {array} browsers List of supported browsers name. | 117 * @param {array} browsers List of supported browsers name. |
| 102 * @private | 118 * @private |
| 103 */ | 119 */ |
| 104 updateSupportedBrowsers_: function(browsers) { | 120 updateSupportedBrowsers_: function(browsers) { |
| 105 ImportDataOverlay.browserProfiles = browsers; | 121 ImportDataOverlay.browserProfiles = browsers; |
| 106 var browserSelect = $('import-browsers'); | 122 var browserSelect = $('import-browsers'); |
| 107 browserSelect.textContent = ''; | 123 browserSelect.textContent = ''; |
| 108 var browserCount = browsers.length; | 124 var browserCount = browsers.length; |
| 109 | 125 |
| 110 if (browserCount == 0) { | 126 if (browserCount == 0) { |
| 111 var option = new Option(templateData.no_profile_found, 0); | 127 var option = new Option(templateData.noProfileFound, 0); |
| 112 browserSelect.appendChild(option); | 128 browserSelect.appendChild(option); |
| 113 | 129 |
| 114 var checkboxes = | 130 this.setControlsSensitive_(false); |
| 115 document.querySelectorAll( | |
| 116 '#import-checkboxes input[type=checkbox]'); | |
| 117 for (var i = 0; i < checkboxes.length; i++) { | |
| 118 this.setUpCheckboxState_(checkboxes[i], false); | |
| 119 } | |
| 120 } else { | 131 } else { |
| 132 this.setControlsSensitive_(true); |
| 121 for (var i = 0; i < browserCount; i++) { | 133 for (var i = 0; i < browserCount; i++) { |
| 122 var browser = browsers[i] | 134 var browser = browsers[i] |
| 123 var option = new Option(browser['name'], browser['index']); | 135 var option = new Option(browser['name'], browser['index']); |
| 124 browserSelect.appendChild(option); | 136 browserSelect.appendChild(option); |
| 125 } | 137 } |
| 126 | 138 |
| 127 this.updateCheckboxes_(); | 139 this.updateCheckboxes_(); |
| 128 this.validateCommitButton_(); | 140 this.validateCommitButton_(); |
| 129 } | 141 } |
| 130 }, | 142 }, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 ImportDataOverlay.setImportingState(false); | 188 ImportDataOverlay.setImportingState(false); |
| 177 OptionsPage.clearOverlays(); | 189 OptionsPage.clearOverlays(); |
| 178 } | 190 } |
| 179 | 191 |
| 180 // Export | 192 // Export |
| 181 return { | 193 return { |
| 182 ImportDataOverlay: ImportDataOverlay | 194 ImportDataOverlay: ImportDataOverlay |
| 183 }; | 195 }; |
| 184 | 196 |
| 185 }); | 197 }); |
| OLD | NEW |