Chromium Code Reviews| Index: chrome/browser/resources/options/import_data_overlay.js |
| diff --git a/chrome/browser/resources/options/import_data_overlay.js b/chrome/browser/resources/options/import_data_overlay.js |
| index 71c8b42ff2930f70d420fb6f7f320dd1e9c1c08b..d88c76a9d9ac5a253d0e5387dfafc6c91299a799 100644 |
| --- a/chrome/browser/resources/options/import_data_overlay.js |
| +++ b/chrome/browser/resources/options/import_data_overlay.js |
| @@ -23,6 +23,30 @@ cr.define('options', function() { |
| // Inherit from OptionsPage. |
| __proto__: OptionsPage.prototype, |
| + import_history_pref: { |
| + 'name': 'import_history', |
| + 'value': true, |
| + 'managed': false |
| + }, |
| + |
| + import_favorites_pref: { |
| + 'name': 'import_bookmarks', |
| + 'value': true, |
| + 'managed': false |
| + }, |
| + |
| + import_passwords_pref: { |
| + 'name': 'import_saved_passwords', |
| + 'value': true, |
| + 'managed': false |
| + }, |
| + |
| + import_search_pref: { |
| + 'name': 'import_search_engine', |
| + 'value': true, |
| + 'managed': false |
| + }, |
| + |
| /** |
| * Initialize the page. |
| */ |
| @@ -39,11 +63,6 @@ cr.define('options', function() { |
| }; |
| } |
| - $('import-browsers').onchange = function() { |
| - self.updateCheckboxes_(); |
| - self.validateCommitButton_(); |
| - }; |
|
simo
2011/07/19 12:24:47
just noticed that I removed this by mistake so I'l
|
| - |
| $('import-data-commit').onclick = function() { |
| chrome.send('importData', [ |
| String($('import-browsers').selectedIndex), |
| @@ -68,6 +87,52 @@ cr.define('options', function() { |
| ImportDataOverlay.dismiss(); |
| }; |
| + // Initialize control enabled states. |
| + Preferences.getInstance().addEventListener( |
| + 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
|
| + function(event) { |
| + self.handleImportPrefChange_( |
| + 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
|
| + event); |
| + if (this.browserProfiles != undefined) { |
| + self.updateCheckboxes_(); |
| + self.validateCommitButton_(); |
| + } |
| + }); |
| + Preferences.getInstance().addEventListener( |
| + self.import_favorites_pref.name, |
| + function(event) { |
| + self.handleImportPrefChange_( |
| + self.import_favorites_pref, |
| + event); |
| + if (this.browserProfiles != undefined) { |
| + self.updateCheckboxes_(); |
| + self.validateCommitButton_(); |
| + } |
| + }); |
| + Preferences.getInstance().addEventListener( |
| + self.import_passwords_pref.name, |
| + function(event) { |
| + self.handleImportPrefChange_( |
| + self.import_passwords_pref, |
| + event); |
| + if (this.browserProfiles != undefined) { |
| + self.updateCheckboxes_(); |
| + self.validateCommitButton_(); |
| + } |
| + }); |
| + Preferences.getInstance().addEventListener( |
| + self.import_search_pref.name, |
| + function(event) { |
| + self.handleImportPrefChange_( |
| + self.import_search_pref, |
| + event); |
| + if (this.browserProfiles != undefined) { |
| + self.updateCheckboxes_(); |
| + self.validateCommitButton_(); |
| + } |
| + }); |
| + |
| // Form controls are disabled until the profile list has been loaded. |
| self.setControlsSensitive_(false); |
| }, |
| @@ -83,15 +148,53 @@ cr.define('options', function() { |
| $('import-data-commit').disabled = !somethingToImport; |
| }, |
|
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
only one blank line
|
| + |
| + /** |
| + * Returns true if the checkbox should be enabled. |
| + * @returns {boolean} Whether the checkbox should be enabled. |
| + * @private |
| + */ |
| + shouldEnableCheckbox_: function(checkbox) { |
| + if (checkbox == $('import-history')) |
| + return !this.import_history_pref.managed; |
| + if (checkbox == $('import-favorites')) |
| + return !this.import_favorites_pref.managed; |
| + if (checkbox == $('import-passwords')) |
| + return !this.import_passwords_pref.managed; |
| + if (checkbox == $('import-search')) |
| + return !this.import_search_pref.managed; |
| + }, |
| + |
| + /** |
| + * Returns true if the checkbox should be enabled. |
| + * @returns {boolean} Whether the checkbox should be enabled. |
| + * @private |
| + */ |
| + shouldCheckCheckbox_: function(checkbox) { |
| + if (checkbox == $('import-history')) |
| + return this.import_history_pref.value; |
| + if (checkbox == $('import-favorites')) |
| + return this.import_favorites_pref.value; |
| + if (checkbox == $('import-passwords')) |
| + return this.import_passwords_pref.value; |
| + if (checkbox == $('import-search')) |
| + return this.import_search_pref.value; |
| + }, |
| + |
| /** |
| * Sets the sensitivity of all the checkboxes and the commit button. |
| * @private |
| */ |
| setControlsSensitive_: function(sensitive) { |
| + |
|
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
don't need this blank line.
|
| var checkboxes = |
| document.querySelectorAll('#import-checkboxes input[type=checkbox]'); |
| - for (var i = 0; i < checkboxes.length; i++) |
| - this.setUpCheckboxState_(checkboxes[i], sensitive); |
| + 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
|
| + var enabled = this.shouldEnableCheckbox_(checkboxes[i]) && sensitive; |
|
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
+2 space indentation.
|
| + this.setUpCheckboxState_(checkboxes[i], |
| + enabled, |
| + this.shouldCheckCheckbox_(checkboxes[i])); |
| + } |
| $('import-data-commit').disabled = !sensitive; |
| }, |
| @@ -101,9 +204,9 @@ cr.define('options', function() { |
| * @param {boolean} enabled The enabled state of the chekbox. |
| * @private |
| */ |
| - setUpCheckboxState_: function(checkbox, enabled) { |
| + setUpCheckboxState_: function(checkbox, enabled, checked) { |
| checkbox.disabled = !enabled; |
| - checkbox.checked = enabled; |
| + checkbox.checked = checked; |
| }, |
| /** |
| @@ -116,14 +219,32 @@ cr.define('options', function() { |
| if (this.browserProfiles.length > index) |
| browserProfile = this.browserProfiles[index]; |
| var importOptions = ['history', 'favorites', 'passwords', 'search']; |
| + var importPrefs = [this.import_history_pref, |
| + this.import_favorites_pref, |
| + this.import_passwords_pref, |
| + this.import_search_pref]; |
| for (var i = 0; i < importOptions.length; i++) { |
| var checkbox = $('import-' + importOptions[i]); |
| - this.setUpCheckboxState_(checkbox, |
| - browserProfile ? browserProfile[importOptions[i]] : false); |
| + var enabled = !importPrefs[i].managed |
|
Mattias Nissler (ping if slow)
2011/07/18 15:02:30
&& goes on this line
|
| + && browserProfile[importOptions[i]]; |
| + var checked = importPrefs[i].value; |
| + this.setUpCheckboxState_(checkbox, enabled, checked); |
| } |
| }, |
| /** |
| + * 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.
|
| + * @param {pref} preference object corresponding to the preference |
| + * that changed |
| + * @param {event} change event |
| + * @private |
| + */ |
| + handleImportPrefChange_: function(pref, event) { |
| + pref.value = event.value['value']; |
| + pref.managed = event.value['managed']; |
| + }, |
| + |
| + /** |
| * Update the supported browsers popup with given entries. |
| * @param {array} browsers List of supported browsers name. |
| * @private |
| @@ -185,6 +306,7 @@ cr.define('options', function() { |
| * Remove the import overlay from display. |
| */ |
| ImportDataOverlay.dismiss = function() { |
| + ImportDataOverlay.setImportingState(false); |
| OptionsPage.closeOverlay(); |
| }; |