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], | 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 /** | |
| 22 * Whether none of the import data categories is selected. | |
| 23 * @private | |
| 24 */ | |
| 25 noImportDataTypeSelected_: { | |
| 26 type: Boolean, | |
| 27 value: false, | |
| 28 }, | |
| 29 | |
| 21 prefs: Object, | 30 prefs: Object, |
| 31 | |
| 32 /** @private */ | |
| 33 importStatus_: { | |
| 34 type: String, | |
| 35 value: settings.ImportDataStatus.INITIAL, | |
| 36 }, | |
| 37 | |
| 38 /** | |
| 39 * Mirroring the enum so that it can be used from HTML bindings. | |
| 40 * @private | |
| 41 */ | |
| 42 importStatusEnum_: { | |
| 43 type: Object, | |
| 44 value: settings.ImportDataStatus, | |
| 45 }, | |
| 22 }, | 46 }, |
| 23 | 47 |
| 48 observers: [ | |
| 49 'prefsChanged_(selected_, prefs.*)', | |
| 50 ], | |
| 51 | |
| 24 /** @private {?settings.ImportDataBrowserProxy} */ | 52 /** @private {?settings.ImportDataBrowserProxy} */ |
| 25 browserProxy_: null, | 53 browserProxy_: null, |
| 26 | 54 |
| 27 /** @override */ | 55 /** @override */ |
| 28 attached: function() { | 56 attached: function() { |
| 29 this.browserProxy_ = settings.ImportDataBrowserProxyImpl.getInstance(); | 57 this.browserProxy_ = settings.ImportDataBrowserProxyImpl.getInstance(); |
| 30 this.browserProxy_.initializeImportDialog().then(function(data) { | 58 this.browserProxy_.initializeImportDialog().then( |
| 31 this.browserProfiles_ = data; | 59 /** @param {!Array<!settings.BrowserProfile>} data */ |
| 32 this.selected_ = this.browserProfiles_[0]; | 60 function(data) { |
| 33 }.bind(this)); | 61 this.browserProfiles_ = data; |
| 62 this.selected_ = this.browserProfiles_[0]; | |
| 63 }.bind(this)); | |
| 34 | 64 |
| 35 this.addWebUIListener('import-data-status-changed', function(e) { | 65 this.addWebUIListener( |
| 36 // TODO(dpapad): Handle events to show spinner or success message. | 66 'import-data-status-changed', |
| 37 }); | 67 /** @param {settings.ImportDataStatus} importStatus */ |
| 68 function(importStatus) { | |
| 69 this.importStatus_ = importStatus; | |
| 70 if (this.hasImportStatus_(settings.ImportDataStatus.FAILED)) | |
| 71 this.closeDialog_(); | |
| 72 }.bind(this)); | |
| 38 | 73 |
| 39 this.$.dialog.showModal(); | 74 this.$.dialog.showModal(); |
| 40 }, | 75 }, |
| 41 | 76 |
| 42 /** @private */ | 77 /** @private */ |
| 78 prefsChanged_() { | |
| 79 this.noImportDataTypeSelected_ = | |
| 80 !(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.
| |
| 81 !(this.prefs['import_bookmarks'].value && this.selected_.favorites) && | |
| 82 !(this.prefs['import_saved_passwords'].value && | |
| 83 this.selected_.passwords) && | |
| 84 !(this.prefs['import_search_engine'].value && this.selected_.search) && | |
| 85 !(this.prefs['import_autofill_form_data'].value && | |
| 86 this.selected_.autofillFormData); | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * @param {!settings.ImportDataStatus} status | |
| 91 * @return {boolean} Whether |status| is the current status. | |
| 92 * @private | |
| 93 */ | |
| 94 hasImportStatus_: function(status) { | |
| 95 return this.importStatus_ == status; | |
| 96 }, | |
| 97 | |
| 98 /** @private */ | |
| 43 isImportFromFileSelected_: function() { | 99 isImportFromFileSelected_: function() { |
| 44 // The last entry in |browserProfiles_| always refers to dummy profile for | 100 // The last entry in |browserProfiles_| always refers to dummy profile for |
| 45 // importing from a bookmarks file. | 101 // importing from a bookmarks file. |
| 46 return this.selected_.index == this.browserProfiles_.length - 1; | 102 return this.selected_.index == this.browserProfiles_.length - 1; |
| 47 }, | 103 }, |
| 48 | 104 |
| 49 /** | 105 /** |
| 50 * @return {string} | 106 * @return {string} |
| 51 * @private | 107 * @private |
| 52 */ | 108 */ |
| 53 getActionButtonText_: function() { | 109 getActionButtonText_: function() { |
| 54 return this.i18n(this.isImportFromFileSelected_() ? | 110 return this.i18n(this.isImportFromFileSelected_() ? |
| 55 'importChooseFile' : 'importCommit'); | 111 'importChooseFile' : 'importCommit'); |
| 56 }, | 112 }, |
| 57 | 113 |
| 58 /** @private */ | 114 /** @private */ |
| 59 onChange_: function() { | 115 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.
| |
| 60 this.selected_ = this.browserProfiles_[this.$.browserSelect.selectedIndex]; | 116 this.selected_ = this.browserProfiles_[this.$.browserSelect.selectedIndex]; |
| 61 }, | 117 }, |
| 62 | 118 |
| 63 /** @private */ | 119 /** @private */ |
| 64 onActionButtonTap_: function() { | 120 onActionButtonTap_: function() { |
| 65 if (this.isImportFromFileSelected_()) { | 121 if (this.isImportFromFileSelected_()) |
| 66 this.browserProxy_.importFromBookmarksFile(); | 122 this.browserProxy_.importFromBookmarksFile(); |
| 67 } else { | 123 else |
| 68 // TODO(dpapad): Implement this. | 124 this.browserProxy_.importData(this.$.browserSelect.selectedIndex); |
| 69 } | |
| 70 }, | 125 }, |
| 71 | 126 |
| 72 /** @private */ | 127 /** @private */ |
| 73 onCancelTap_: function() { | 128 closeDialog_: function() { |
| 74 this.$.dialog.close(); | 129 this.$.dialog.close(); |
| 75 }, | 130 }, |
| 131 | |
| 132 /** | |
| 133 * @return {boolean} Whether the import button should be disabled. | |
| 134 * @private | |
| 135 */ | |
| 136 shouldDisableImport_: function() { | |
| 137 return this.hasImportStatus_(settings.ImportDataStatus.IN_PROGRESS) || | |
| 138 this.noImportDataTypeSelected_; | |
| 139 }, | |
| 76 }); | 140 }); |
| OLD | NEW |