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-item', | 6 is: 'bookmarks-item', |
7 | 7 |
| 8 behaviors: [ |
| 9 bookmarks.StoreClient, |
| 10 ], |
| 11 |
8 properties: { | 12 properties: { |
9 /** @type {BookmarkTreeNode} */ | 13 itemId: { |
10 item: { | 14 type: String, |
| 15 observer: 'updateFromStore', |
| 16 }, |
| 17 |
| 18 /** @private {BookmarkNode} */ |
| 19 item_: { |
11 type: Object, | 20 type: Object, |
12 observer: 'onItemChanged_', | 21 observer: 'onItemChanged_', |
13 }, | 22 }, |
14 | 23 |
15 isFolder_: Boolean, | 24 /** @private */ |
16 | 25 isSelectedItem_: { |
17 isSelectedItem: { | |
18 type: Boolean, | 26 type: Boolean, |
19 reflectToAttribute: true, | 27 reflectToAttribute: true, |
20 }, | 28 }, |
| 29 |
| 30 /** @private */ |
| 31 isFolder_: Boolean, |
21 }, | 32 }, |
22 | 33 |
23 observers: [ | 34 observers: [ |
24 'updateFavicon_(item.url)', | 35 'updateFavicon_(item_.url)', |
25 ], | 36 ], |
26 | 37 |
27 listeners: { | 38 listeners: { |
28 'click': 'onClick_', | 39 'click': 'onClick_', |
29 'dblclick': 'onDblClick_', | 40 'dblclick': 'onDblClick_', |
30 }, | 41 }, |
31 | 42 |
| 43 attached: function() { |
| 44 this.watch('item_', function(store) { |
| 45 return store.nodes[this.itemId]; |
| 46 }.bind(this)); |
| 47 |
| 48 this.updateFromStore(); |
| 49 }, |
| 50 |
32 /** | 51 /** |
33 * @param {Event} e | 52 * @param {Event} e |
34 * @private | 53 * @private |
35 */ | 54 */ |
36 onMenuButtonOpenClick_: function(e) { | 55 onMenuButtonOpenClick_: function(e) { |
37 e.stopPropagation(); | 56 e.stopPropagation(); |
38 this.fire('open-item-menu', { | 57 this.fire('open-item-menu', { |
39 target: e.target, | 58 target: e.target, |
40 item: this.item, | 59 item: this.item_, |
41 }); | 60 }); |
42 }, | 61 }, |
43 | 62 |
44 /** @private */ | 63 /** @private */ |
45 onItemChanged_: function() { | 64 onItemChanged_: function() { |
46 this.isFolder_ = !(this.item.url); | 65 this.isFolder_ = !(this.item_.url); |
47 }, | 66 }, |
48 | 67 |
49 /** | 68 /** |
50 * @param {Event} e | 69 * @param {Event} e |
51 * @private | 70 * @private |
52 */ | 71 */ |
53 onClick_: function(e) { | 72 onClick_: function(e) { |
54 this.fire('select-item', { | 73 this.fire('select-item', { |
55 item: this.item, | 74 item: this.item_, |
56 range: e.shiftKey, | 75 range: e.shiftKey, |
57 add: e.ctrlKey, | 76 add: e.ctrlKey, |
58 }); | 77 }); |
59 }, | 78 }, |
60 | 79 |
61 /** | 80 /** |
62 * @param {Event} e | 81 * @param {Event} e |
63 * @private | 82 * @private |
64 */ | 83 */ |
65 onDblClick_: function(e) { | 84 onDblClick_: function(e) { |
66 if (!this.item.url) | 85 if (!this.item_.url) |
67 this.fire('selected-folder-changed', this.item.id); | 86 this.dispatch(bookmarks.actions.selectFolder(this.item_.id)); |
68 else | 87 else |
69 chrome.tabs.create({url: this.item.url}); | 88 chrome.tabs.create({url: this.item_.url}); |
70 }, | 89 }, |
71 | 90 |
72 /** | 91 /** |
73 * @param {string} url | 92 * @param {string} url |
74 * @private | 93 * @private |
75 */ | 94 */ |
76 updateFavicon_: function(url) { | 95 updateFavicon_: function(url) { |
77 this.$.icon.style.backgroundImage = cr.icon.getFavicon(url); | 96 this.$.icon.style.backgroundImage = cr.icon.getFavicon(url); |
78 }, | 97 }, |
79 }); | 98 }); |
OLD | NEW |