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

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 disabling logic. 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],
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 noCategorySelected_: {
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
24 /** @private {?settings.ImportDataBrowserProxy} */ 48 /** @private {?settings.ImportDataBrowserProxy} */
25 browserProxy_: null, 49 browserProxy_: null,
26 50
27 /** @override */ 51 /** @override */
28 attached: function() { 52 attached: function() {
29 this.browserProxy_ = settings.ImportDataBrowserProxyImpl.getInstance(); 53 this.browserProxy_ = settings.ImportDataBrowserProxyImpl.getInstance();
30 this.browserProxy_.initializeImportDialog().then(function(data) { 54 this.browserProxy_.initializeImportDialog().then(
31 this.browserProfiles_ = data; 55 /** @param {!Array<!settings.BrowserProfile>} data */
32 this.selected_ = this.browserProfiles_[0]; 56 function(data) {
33 }.bind(this)); 57 this.browserProfiles_ = data;
58 this.selected_ = this.browserProfiles_[0];
59 }.bind(this));
34 60
35 this.addWebUIListener('import-data-status-changed', function(e) { 61 this.addWebUIListener(
36 // TODO(dpapad): Handle events to show spinner or success message. 62 'import-data-status-changed',
37 }); 63 /** @param {settings.ImportDataStatus} importStatus */
64 function(importStatus) {
65 this.importStatus_ = importStatus;
66 if (this.hasImportStatus_(settings.ImportDataStatus.FAILED))
67 this.closeDialog_();
dpapad 2016/11/16 00:34:38 FYI this is what the old Options UI did on error,
tommycli 2016/11/16 17:23:53 Okay seems fine.
68 }.bind(this));
38 69
39 this.$.dialog.showModal(); 70 this.$.dialog.showModal();
40 }, 71 },
41 72
73 /**
74 * Listener executing whenever the state of a checkbox changes.
75 * @private
76 */
77 onCheckboxChange_: function() {
tommycli 2016/11/16 17:23:53 onImportedDataTypeChange_?
dpapad 2016/11/16 21:33:02 No longer listening for iron-chage event, so this
78 var checkboxes = this.root.querySelectorAll(
tommycli 2016/11/16 17:23:53 Can we make the selector operate something like th
dpapad 2016/11/16 21:33:02 There are no other checkboxes on this dialog, so d
79 'settings-checkbox:not([hidden])[checked]');
80 this.noCategorySelected_ = checkboxes.length == 0;
tommycli 2016/11/16 17:23:53 I was initially confused. Maybe we should rename t
dpapad 2016/11/16 21:33:02 Done.
81 },
82
83 /**
84 * @param {!settings.ImportDataStatus} status
85 * @return {boolean} Whether |status| is the current status.
86 * @private
87 */
88 hasImportStatus_: function(status) {
89 return this.importStatus_ == status;
90 },
91
42 /** @private */ 92 /** @private */
43 isImportFromFileSelected_: function() { 93 isImportFromFileSelected_: function() {
44 // The last entry in |browserProfiles_| always refers to dummy profile for 94 // The last entry in |browserProfiles_| always refers to dummy profile for
45 // importing from a bookmarks file. 95 // importing from a bookmarks file.
46 return this.selected_.index == this.browserProfiles_.length - 1; 96 return this.selected_.index == this.browserProfiles_.length - 1;
47 }, 97 },
48 98
49 /** 99 /**
50 * @return {string} 100 * @return {string}
51 * @private 101 * @private
52 */ 102 */
53 getActionButtonText_: function() { 103 getActionButtonText_: function() {
54 return this.i18n(this.isImportFromFileSelected_() ? 104 return this.i18n(this.isImportFromFileSelected_() ?
55 'importChooseFile' : 'importCommit'); 105 'importChooseFile' : 'importCommit');
56 }, 106 },
57 107
58 /** @private */ 108 /** @private */
59 onChange_: function() { 109 onChange_: function() {
tommycli 2016/11/16 17:23:53 Since there is now a onCheckboxChange_ method, may
dpapad 2016/11/16 21:33:02 onCheckboxChange_ has been removed. I renamed anyw
60 this.selected_ = this.browserProfiles_[this.$.browserSelect.selectedIndex]; 110 this.selected_ = this.browserProfiles_[this.$.browserSelect.selectedIndex];
111 this.onCheckboxChange_();
61 }, 112 },
62 113
63 /** @private */ 114 /** @private */
64 onActionButtonTap_: function() { 115 onActionButtonTap_: function() {
65 if (this.isImportFromFileSelected_()) { 116 if (this.isImportFromFileSelected_())
66 this.browserProxy_.importFromBookmarksFile(); 117 this.browserProxy_.importFromBookmarksFile();
67 } else { 118 else
68 // TODO(dpapad): Implement this. 119 this.browserProxy_.importData(this.$.browserSelect.selectedIndex);
69 }
70 }, 120 },
71 121
72 /** @private */ 122 /** @private */
73 onCancelTap_: function() { 123 closeDialog_: function() {
74 this.$.dialog.close(); 124 this.$.dialog.close();
75 }, 125 },
126
127 /**
128 * @return {boolean} Whether the action button should be disabled.
129 * @private
130 */
131 disallowAction_: function() {
tommycli 2016/11/16 17:23:53 isImportButtonDisabled_?
dpapad 2016/11/16 21:33:02 Renamed to |shouldDisableImport_|. My issue with t
132 return this.hasImportStatus_(settings.ImportDataStatus.IN_PROGRESS) ||
133 this.noCategorySelected_;
134 },
76 }); 135 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698