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 Polymer({ | 5 Polymer({ |
6 is: 'bookmarks-list', | 6 is: 'bookmarks-list', |
7 | 7 |
8 behaviors: [ | 8 behaviors: [ |
9 bookmarks.StoreClient, | 9 bookmarks.StoreClient, |
10 ], | 10 ], |
11 | 11 |
12 properties: { | 12 properties: { |
13 /** @type {BookmarkNode} */ | |
14 menuItem_: Object, | |
15 | |
16 /** @private {Array<string>} */ | 13 /** @private {Array<string>} */ |
17 displayedList_: { | 14 displayedList_: { |
18 type: Array, | 15 type: Array, |
19 value: function() { | 16 value: function() { |
20 // Use an empty list during initialization so that the databinding to | 17 // Use an empty list during initialization so that the databinding to |
21 // hide #bookmarksCard takes effect. | 18 // hide #bookmarksCard takes effect. |
22 return []; | 19 return []; |
23 }, | 20 }, |
24 }, | 21 }, |
25 | 22 |
26 /** @private */ | 23 /** @private */ |
27 searchTerm_: String, | 24 searchTerm_: String, |
28 }, | 25 }, |
29 | 26 |
30 listeners: { | 27 listeners: { |
31 'click': 'deselectItems_', | 28 'click': 'deselectItems_', |
32 'open-item-menu': 'onOpenItemMenu_', | |
33 }, | 29 }, |
34 | 30 |
35 attached: function() { | 31 attached: function() { |
36 this.watch('displayedList_', function(state) { | 32 this.watch('displayedList_', function(state) { |
37 return bookmarks.util.getDisplayedList(state); | 33 return bookmarks.util.getDisplayedList(state); |
38 }); | 34 }); |
39 this.watch('searchTerm_', function(state) { | 35 this.watch('searchTerm_', function(state) { |
40 return state.search.term; | 36 return state.search.term; |
41 }); | 37 }); |
42 this.updateFromStore(); | 38 this.updateFromStore(); |
43 }, | 39 }, |
44 | 40 |
45 getDropTarget: function() { | 41 getDropTarget: function() { |
46 return this.$.message; | 42 return this.$.message; |
47 }, | 43 }, |
48 | 44 |
49 /** | |
50 * @param {Event} e | |
51 * @private | |
52 */ | |
53 onOpenItemMenu_: function(e) { | |
54 this.menuItem_ = e.detail.item; | |
55 var menu = /** @type {!CrActionMenuElement} */ ( | |
56 this.$.dropdown); | |
57 if (e.detail.targetElement) { | |
58 menu.showAt(/** @type {!Element} */ (e.detail.targetElement)); | |
59 } else { | |
60 menu.showAtPosition({ | |
61 top: e.detail.y, | |
62 left: e.detail.x, | |
63 }); | |
64 } | |
65 }, | |
66 | |
67 /** @private */ | |
68 onEditTap_: function() { | |
69 this.closeDropdownMenu_(); | |
70 /** @type {BookmarksEditDialogElement} */ (this.$.editDialog.get()) | |
71 .showEditDialog(this.menuItem_); | |
72 }, | |
73 | |
74 /** @private */ | |
75 onCopyURLTap_: function() { | |
76 var idList = [this.menuItem_.id]; | |
77 chrome.bookmarkManagerPrivate.copy(idList, function() { | |
78 // TODO(jiaxi): Add toast later. | |
79 }); | |
80 this.closeDropdownMenu_(); | |
81 }, | |
82 | |
83 /** @private */ | |
84 onDeleteTap_: function() { | |
85 if (this.menuItem_.url) { | |
86 chrome.bookmarks.remove(this.menuItem_.id, function() { | |
87 // TODO(jiaxi): Add toast later. | |
88 }.bind(this)); | |
89 } else { | |
90 chrome.bookmarks.removeTree(this.menuItem_.id, function() { | |
91 // TODO(jiaxi): Add toast later. | |
92 }.bind(this)); | |
93 } | |
94 this.closeDropdownMenu_(); | |
95 }, | |
96 | |
97 /** | |
98 * Close the menu on mousedown so clicks can propagate to the underlying UI. | |
99 * This allows the user to right click the list while a context menu is | |
100 * showing and get another context menu. | |
101 * @param {Event} e | |
102 * @private | |
103 */ | |
104 onMenuMousedown_: function(e) { | |
105 if (e.path[0] != this.$.dropdown) | |
106 return; | |
107 | |
108 this.$.dropdown.close(); | |
109 }, | |
110 | |
111 /** @private */ | |
112 closeDropdownMenu_: function() { | |
113 var menu = /** @type {!CrActionMenuElement} */ ( | |
114 this.$.dropdown); | |
115 menu.close(); | |
116 }, | |
117 | |
118 /** @private */ | |
119 getEditActionLabel_: function() { | |
120 var label = this.menuItem_.url ? 'menuEdit' : 'menuRename'; | |
121 return loadTimeData.getString(label); | |
122 }, | |
123 | |
124 /** @private */ | 45 /** @private */ |
125 emptyListMessage_: function() { | 46 emptyListMessage_: function() { |
126 var emptyListMessage = this.searchTerm_ ? 'noSearchResults' : 'emptyList'; | 47 var emptyListMessage = this.searchTerm_ ? 'noSearchResults' : 'emptyList'; |
127 return loadTimeData.getString(emptyListMessage); | 48 return loadTimeData.getString(emptyListMessage); |
128 }, | 49 }, |
129 | 50 |
130 /** @private */ | 51 /** @private */ |
131 isEmptyList_: function() { | 52 isEmptyList_: function() { |
132 return this.displayedList_.length == 0; | 53 return this.displayedList_.length == 0; |
133 }, | 54 }, |
134 | 55 |
135 /** @private */ | 56 /** @private */ |
136 deselectItems_: function() { | 57 deselectItems_: function() { |
137 this.dispatch(bookmarks.actions.deselectItems()); | 58 this.dispatch(bookmarks.actions.deselectItems()); |
138 }, | 59 }, |
139 }); | 60 }); |
OLD | NEW |