Chromium Code Reviews| Index: chrome/browser/resources/settings/people_page/import_data_dialog.js |
| diff --git a/chrome/browser/resources/settings/people_page/import_data_dialog.js b/chrome/browser/resources/settings/people_page/import_data_dialog.js |
| index d58a5c568987f8ba53dfb45cbb2528dd3e2e0de3..f38bcca56ad1f92b497a2ff3e446268d92ba0938 100644 |
| --- a/chrome/browser/resources/settings/people_page/import_data_dialog.js |
| +++ b/chrome/browser/resources/settings/people_page/import_data_dialog.js |
| @@ -18,28 +18,84 @@ Polymer({ |
| /** @private {!settings.BrowserProfile} */ |
| selected_: Object, |
| + /** |
| + * Whether none of the import data categories is selected. |
| + * @private |
| + */ |
| + noImportDataTypeSelected_: { |
| + type: Boolean, |
| + value: false, |
| + }, |
| + |
| prefs: Object, |
| + |
| + /** @private */ |
| + importStatus_: { |
| + type: String, |
| + value: settings.ImportDataStatus.INITIAL, |
| + }, |
| + |
| + /** |
| + * Mirroring the enum so that it can be used from HTML bindings. |
| + * @private |
| + */ |
| + importStatusEnum_: { |
| + type: Object, |
| + value: settings.ImportDataStatus, |
| + }, |
| }, |
| + observers: [ |
| + 'prefsChanged_(selected_, prefs.*)', |
| + ], |
| + |
| /** @private {?settings.ImportDataBrowserProxy} */ |
| browserProxy_: null, |
| /** @override */ |
| attached: function() { |
| this.browserProxy_ = settings.ImportDataBrowserProxyImpl.getInstance(); |
| - this.browserProxy_.initializeImportDialog().then(function(data) { |
| - this.browserProfiles_ = data; |
| - this.selected_ = this.browserProfiles_[0]; |
| - }.bind(this)); |
| + this.browserProxy_.initializeImportDialog().then( |
| + /** @param {!Array<!settings.BrowserProfile>} data */ |
| + function(data) { |
| + this.browserProfiles_ = data; |
| + this.selected_ = this.browserProfiles_[0]; |
| + }.bind(this)); |
| - this.addWebUIListener('import-data-status-changed', function(e) { |
| - // TODO(dpapad): Handle events to show spinner or success message. |
| - }); |
| + this.addWebUIListener( |
| + 'import-data-status-changed', |
| + /** @param {settings.ImportDataStatus} importStatus */ |
| + function(importStatus) { |
| + this.importStatus_ = importStatus; |
| + if (this.hasImportStatus_(settings.ImportDataStatus.FAILED)) |
| + this.closeDialog_(); |
| + }.bind(this)); |
| this.$.dialog.showModal(); |
| }, |
| /** @private */ |
| + prefsChanged_() { |
| + this.noImportDataTypeSelected_ = |
| + !(this.prefs['import_history'].value && this.selected_.history) && |
|
dpapad
2016/11/16 21:33:02
Is it OK to access prefs this way? Or should I be
tommycli
2016/11/16 21:43:40
I bet it's harmless to do it this way, but I'd sti
Dan Beam
2016/11/16 21:45:15
wont compile, .get('prefs.import_history.value') w
dpapad
2016/11/16 21:47:10
Tried this locally and compiled. If I remove the q
dpapad
2016/11/16 21:54:08
Using PrefsBehavior in latest patch.
|
| + !(this.prefs['import_bookmarks'].value && this.selected_.favorites) && |
| + !(this.prefs['import_saved_passwords'].value && |
| + this.selected_.passwords) && |
| + !(this.prefs['import_search_engine'].value && this.selected_.search) && |
| + !(this.prefs['import_autofill_form_data'].value && |
| + this.selected_.autofillFormData); |
| + }, |
| + |
| + /** |
| + * @param {!settings.ImportDataStatus} status |
| + * @return {boolean} Whether |status| is the current status. |
| + * @private |
| + */ |
| + hasImportStatus_: function(status) { |
| + return this.importStatus_ == status; |
| + }, |
| + |
| + /** @private */ |
| isImportFromFileSelected_: function() { |
| // The last entry in |browserProfiles_| always refers to dummy profile for |
| // importing from a bookmarks file. |
| @@ -56,21 +112,29 @@ Polymer({ |
| }, |
| /** @private */ |
| - onChange_: function() { |
| + onBrowserProfileSelectiChange_: function() { |
|
tommycli
2016/11/16 21:43:40
Same typo here, so I guess that's why it works?
dpapad
2016/11/16 21:47:10
Already fixed.
|
| this.selected_ = this.browserProfiles_[this.$.browserSelect.selectedIndex]; |
| }, |
| /** @private */ |
| onActionButtonTap_: function() { |
| - if (this.isImportFromFileSelected_()) { |
| + if (this.isImportFromFileSelected_()) |
| this.browserProxy_.importFromBookmarksFile(); |
| - } else { |
| - // TODO(dpapad): Implement this. |
| - } |
| + else |
| + this.browserProxy_.importData(this.$.browserSelect.selectedIndex); |
| }, |
| /** @private */ |
| - onCancelTap_: function() { |
| + closeDialog_: function() { |
| this.$.dialog.close(); |
| }, |
| + |
| + /** |
| + * @return {boolean} Whether the import button should be disabled. |
| + * @private |
| + */ |
| + shouldDisableImport_: function() { |
| + return this.hasImportStatus_(settings.ImportDataStatus.IN_PROGRESS) || |
| + this.noImportDataTypeSelected_; |
| + }, |
| }); |