Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @fileoverview 'settings-import-data-dialog' is a component for importing | 6 * @fileoverview 'settings-import-data-dialog' is a component for importing |
| 7 * bookmarks and other data from other sources. | 7 * bookmarks and other data from other sources. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'settings-import-data-dialog', | 10 is: 'settings-import-data-dialog', |
| 11 | 11 |
| 12 behaviors: [I18nBehavior, WebUIListenerBehavior, PrefsBehavior], | 12 behaviors: [I18nBehavior, WebUIListenerBehavior], |
| 13 | 13 |
| 14 properties: { | 14 properties: { |
| 15 /** @private {!Array<!settings.BrowserProfile>} */ | 15 /** @private {!Array<!settings.BrowserProfile>} */ |
| 16 browserProfiles_: Array, | 16 browserProfiles_: Array, |
| 17 | 17 |
| 18 /** @private {!settings.BrowserProfile} */ | 18 /** @private {!settings.BrowserProfile} */ |
| 19 selected_: Object, | 19 selected_: Object, |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Whether none of the import data categories is selected. | 22 * Whether none of the import data categories is selected. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 34 }, | 34 }, |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Mirroring the enum so that it can be used from HTML bindings. | 37 * Mirroring the enum so that it can be used from HTML bindings. |
| 38 * @private | 38 * @private |
| 39 */ | 39 */ |
| 40 importStatusEnum_: { | 40 importStatusEnum_: { |
| 41 type: Object, | 41 type: Object, |
| 42 value: settings.ImportDataStatus, | 42 value: settings.ImportDataStatus, |
| 43 }, | 43 }, |
| 44 | |
| 45 /** @private */ | |
| 46 showBookmarkSuccess_: Boolean, | |
| 44 }, | 47 }, |
| 45 | 48 |
| 46 observers: [ | |
| 47 'prefsChanged_(selected_, prefs.*)', | |
| 48 ], | |
| 49 | |
| 50 /** @private {?settings.ImportDataBrowserProxy} */ | 49 /** @private {?settings.ImportDataBrowserProxy} */ |
| 51 browserProxy_: null, | 50 browserProxy_: null, |
| 52 | 51 |
| 53 /** @override */ | 52 /** @override */ |
| 54 attached: function() { | 53 attached: function() { |
| 55 this.browserProxy_ = settings.ImportDataBrowserProxyImpl.getInstance(); | 54 this.browserProxy_ = settings.ImportDataBrowserProxyImpl.getInstance(); |
| 56 this.browserProxy_.initializeImportDialog().then( | 55 this.browserProxy_.initializeImportDialog().then( |
| 57 /** @param {!Array<!settings.BrowserProfile>} data */ | 56 /** @param {!Array<!settings.BrowserProfile>} data */ |
| 58 function(data) { | 57 function(data) { |
| 59 this.browserProfiles_ = data; | 58 this.browserProfiles_ = data; |
| 60 this.selected_ = this.browserProfiles_[0]; | 59 this.selected_ = this.browserProfiles_[0]; |
| 61 | 60 |
| 62 // Show the dialog only after the browser profiles data is populated | 61 // Show the dialog only after the browser profiles data is populated |
| 63 // to avoid UI flicker. | 62 // to avoid UI flicker. |
| 64 this.$.dialog.showModal(); | 63 this.$.dialog.showModal(); |
| 65 }.bind(this)); | 64 }.bind(this)); |
| 66 | 65 |
| 67 this.addWebUIListener( | 66 this.addWebUIListener( |
| 68 'import-data-status-changed', | 67 'import-data-status-changed', |
| 69 /** @param {settings.ImportDataStatus} importStatus */ | 68 /** @param {settings.ImportDataStatus} importStatus */ |
| 70 function(importStatus) { | 69 function(importStatus) { |
| 71 this.importStatus_ = importStatus; | 70 this.importStatus_ = importStatus; |
| 71 if (this.hasImportStatus_(settings.ImportDataStatus.SUCCEEDED)) { | |
| 72 this.showBookmarkSuccess_ = | |
| 73 this.$.favorites.checked && this.selected_.favorites; | |
| 74 } | |
| 75 | |
| 72 if (this.hasImportStatus_(settings.ImportDataStatus.FAILED)) | 76 if (this.hasImportStatus_(settings.ImportDataStatus.FAILED)) |
| 73 this.closeDialog_(); | 77 this.closeDialog_(); |
| 74 }.bind(this)); | 78 }.bind(this)); |
| 75 }, | 79 }, |
| 76 | 80 |
| 77 /** @private */ | 81 /** @private */ |
| 78 prefsChanged_: function() { | 82 onCheckboxChange_: function() { |
| 79 this.noImportDataTypeSelected_ = | 83 this.noImportDataTypeSelected_ = |
| 80 !(this.getPref('import_history').value && this.selected_.history) && | 84 !(this.$.history.checked && this.selected_.history) && |
|
Dan Beam
2017/02/27 18:39:24
arguable nit: we should reverse these conditionals
dpapad
2017/02/27 19:55:00
Done.
| |
| 81 !(this.getPref('import_bookmarks').value && this.selected_.favorites) && | 85 !(this.$.favorites.checked && this.selected_.favorites) && |
| 82 !(this.getPref('import_saved_passwords').value && | 86 !(this.$.passwords.checked && this.selected_.passwords) && |
| 83 this.selected_.passwords) && | 87 !(this.$.search.checked && this.selected_.search) && |
| 84 !(this.getPref('import_search_engine').value && | 88 !(this.$.autofillFormData.checked && this.selected_.autofillFormData); |
| 85 this.selected_.search) && | |
| 86 !(this.getPref('import_autofill_form_data').value && | |
| 87 this.selected_.autofillFormData); | |
| 88 }, | 89 }, |
| 89 | 90 |
| 90 /** | 91 /** |
| 91 * @param {!settings.ImportDataStatus} status | 92 * @param {!settings.ImportDataStatus} status |
| 92 * @return {boolean} Whether |status| is the current status. | 93 * @return {boolean} Whether |status| is the current status. |
| 93 * @private | 94 * @private |
| 94 */ | 95 */ |
| 95 hasImportStatus_: function(status) { | 96 hasImportStatus_: function(status) { |
| 96 return this.importStatus_ == status; | 97 return this.importStatus_ == status; |
| 97 }, | 98 }, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 108 * @private | 109 * @private |
| 109 */ | 110 */ |
| 110 getActionButtonText_: function() { | 111 getActionButtonText_: function() { |
| 111 return this.i18n(this.isImportFromFileSelected_() ? | 112 return this.i18n(this.isImportFromFileSelected_() ? |
| 112 'importChooseFile' : 'importCommit'); | 113 'importChooseFile' : 'importCommit'); |
| 113 }, | 114 }, |
| 114 | 115 |
| 115 /** @private */ | 116 /** @private */ |
| 116 onBrowserProfileSelectionChange_: function() { | 117 onBrowserProfileSelectionChange_: function() { |
| 117 this.selected_ = this.browserProfiles_[this.$.browserSelect.selectedIndex]; | 118 this.selected_ = this.browserProfiles_[this.$.browserSelect.selectedIndex]; |
| 119 this.onCheckboxChange_(); | |
| 118 }, | 120 }, |
| 119 | 121 |
| 120 /** @private */ | 122 /** @private */ |
| 121 onActionButtonTap_: function() { | 123 onActionButtonTap_: function() { |
| 122 if (this.isImportFromFileSelected_()) | 124 if (this.isImportFromFileSelected_()) |
| 123 this.browserProxy_.importFromBookmarksFile(); | 125 this.browserProxy_.importFromBookmarksFile(); |
| 124 else | 126 else |
| 125 this.browserProxy_.importData(this.$.browserSelect.selectedIndex); | 127 this.browserProxy_.importData(this.$.browserSelect.selectedIndex); |
| 126 }, | 128 }, |
| 127 | 129 |
| 128 /** @private */ | 130 /** @private */ |
| 129 closeDialog_: function() { | 131 closeDialog_: function() { |
| 130 this.$.dialog.close(); | 132 this.$.dialog.close(); |
| 131 }, | 133 }, |
| 132 | 134 |
| 133 /** | 135 /** |
| 134 * @return {boolean} Whether the import button should be disabled. | 136 * @return {boolean} Whether the import button should be disabled. |
| 135 * @private | 137 * @private |
| 136 */ | 138 */ |
| 137 shouldDisableImport_: function() { | 139 shouldDisableImport_: function() { |
| 138 return this.hasImportStatus_(settings.ImportDataStatus.IN_PROGRESS) || | 140 return this.hasImportStatus_(settings.ImportDataStatus.IN_PROGRESS) || |
| 139 this.noImportDataTypeSelected_; | 141 this.noImportDataTypeSelected_; |
| 140 }, | 142 }, |
| 141 }); | 143 }); |
| OLD | NEW |