Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(644)

Side by Side Diff: chrome/browser/resources/settings/people_page/import_data_dialog.js

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

Powered by Google App Engine
This is Rietveld 408576698