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 Polymer({ | 5 Polymer({ |
| 6 is: 'bookmarks-list', | 6 is: 'bookmarks-list', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 /** @type {BookmarkTreeNode} */ | 9 /** @type {BookmarkTreeNode} */ |
| 10 menuItem_: Object, | 10 menuItem_: Object, |
| 11 | 11 |
| 12 /** @type {Array<BookmarkTreeNode>} */ | 12 /** @type {Array<BookmarkTreeNode>} */ |
| 13 displayedList: Array, | 13 displayedList: Array, |
| 14 | 14 |
| 15 searchTerm: String, | 15 searchTerm: String, |
| 16 | |
| 17 hideUrlInput_: Boolean, | |
|
calamity
2017/02/02 04:40:53
Can we get rid of this property? Or at least chang
angelayang
2017/02/02 05:33:52
Done.
| |
| 16 }, | 18 }, |
| 17 | 19 |
| 18 listeners: { | 20 listeners: { |
| 19 'open-item-menu': 'onOpenItemMenu_', | 21 'open-item-menu': 'onOpenItemMenu_', |
| 20 }, | 22 }, |
| 21 | 23 |
| 22 /** | 24 /** |
| 23 * @param {Event} e | 25 * @param {Event} e |
| 24 * @private | 26 * @private |
| 25 */ | 27 */ |
| 26 onOpenItemMenu_: function(e) { | 28 onOpenItemMenu_: function(e) { |
| 27 this.menuItem_ = e.detail.item; | 29 this.menuItem_ = e.detail.item; |
| 28 var menu = /** @type {!CrActionMenuElement} */ ( | 30 var menu = /** @type {!CrActionMenuElement} */ ( |
| 29 this.$.dropdown); | 31 this.$.dropdown); |
| 32 this.hideUrlInput_ = !this.menuItem_.url; | |
| 30 menu.showAt(/** @type {!Element} */ (e.detail.target)); | 33 menu.showAt(/** @type {!Element} */ (e.detail.target)); |
| 31 }, | 34 }, |
| 32 | 35 |
| 33 // TODO(jiaxi): change these dummy click event handlers later. | |
| 34 /** @private */ | 36 /** @private */ |
| 35 onEditTap_: function() { | 37 onEditTap_: function() { |
| 36 this.closeDropdownMenu_(); | 38 this.closeDropdownMenu_(); |
| 37 if (this.menuItem_.url) | 39 this.$.editBookmark.showModal(); |
| 38 this.$.editBookmark.showModal(); | |
| 39 }, | 40 }, |
| 40 | 41 |
| 41 /** @private */ | 42 /** @private */ |
| 42 onCopyURLTap_: function() { | 43 onCopyURLTap_: function() { |
| 43 var idList = [this.menuItem_.id]; | 44 var idList = [this.menuItem_.id]; |
| 44 chrome.bookmarkManagerPrivate.copy(idList, function() { | 45 chrome.bookmarkManagerPrivate.copy(idList, function() { |
| 45 // TODO(jiaxi): Add toast later. | 46 // TODO(jiaxi): Add toast later. |
| 46 }); | 47 }); |
| 47 this.closeDropdownMenu_(); | 48 this.closeDropdownMenu_(); |
| 48 }, | 49 }, |
| 49 | 50 |
| 50 /** @private */ | 51 /** @private */ |
| 51 onDeleteTap_: function() { | 52 onDeleteTap_: function() { |
| 52 if (this.menuItem_.url) { | 53 if (this.menuItem_.url) { |
| 53 chrome.bookmarks.remove(this.menuItem_.id, function() { | 54 chrome.bookmarks.remove(this.menuItem_.id, function() { |
| 54 // TODO(jiaxi): Add toast later. | 55 // TODO(jiaxi): Add toast later. |
| 55 }.bind(this)); | 56 }.bind(this)); |
| 56 } else { | 57 } else { |
| 57 chrome.bookmarks.removeTree(this.menuItem_.id, function() { | 58 chrome.bookmarks.removeTree(this.menuItem_.id, function() { |
| 58 // TODO(jiaxi): Add toast later. | 59 // TODO(jiaxi): Add toast later. |
| 59 }.bind(this)); | 60 }.bind(this)); |
| 60 } | 61 } |
| 61 this.closeDropdownMenu_(); | 62 this.closeDropdownMenu_(); |
| 62 }, | 63 }, |
| 63 | 64 |
| 64 /** @private */ | 65 /** @private */ |
| 65 onSaveEditTap_: function() { | 66 onSaveEditTap_: function() { |
| 66 chrome.bookmarks.update(this.menuItem_.id, { | 67 var edit = {'title': this.menuItem_.title}; |
| 67 'title': this.menuItem_.title, | 68 if (this.menuItem_.url) |
| 68 'url': this.menuItem_.url, | 69 edit['url'] = this.menuItem_.url; |
| 69 }); | 70 |
| 71 chrome.bookmarks.update(this.menuItem_.id, edit); | |
| 70 this.$.editBookmark.close(); | 72 this.$.editBookmark.close(); |
| 71 }, | 73 }, |
| 72 | 74 |
| 73 /** @private */ | 75 /** @private */ |
| 74 onCancelEditTap_: function() { | 76 onCancelEditTap_: function() { |
| 75 this.$.editBookmark.cancel(); | 77 this.$.editBookmark.cancel(); |
| 76 }, | 78 }, |
| 77 | 79 |
| 78 /** @private */ | 80 /** @private */ |
| 79 closeDropdownMenu_: function() { | 81 closeDropdownMenu_: function() { |
| 80 var menu = /** @type {!CrActionMenuElement} */ ( | 82 var menu = /** @type {!CrActionMenuElement} */ ( |
| 81 this.$.dropdown); | 83 this.$.dropdown); |
| 82 menu.close(); | 84 menu.close(); |
| 83 }, | 85 }, |
| 84 | 86 |
| 85 /** @private */ | 87 /** @private */ |
| 88 getEditActionLabel_: function() { | |
| 89 var label = this.menuItem_.url ? 'menuEdit' : 'menuRename'; | |
| 90 return loadTimeData.getString(label); | |
| 91 }, | |
| 92 | |
| 93 /** @private */ | |
| 94 getEditorTitle_: function() { | |
| 95 var title = this.menuItem_.url ? 'editBookmarkTitle' : 'renameFolderTitle'; | |
| 96 return loadTimeData.getString(title); | |
| 97 }, | |
| 98 | |
| 99 /** @private */ | |
| 86 emptyListMessage_: function() { | 100 emptyListMessage_: function() { |
| 87 var emptyListMessage = this.searchTerm ? 'noSearchResults' : 'emptyList'; | 101 var emptyListMessage = this.searchTerm ? 'noSearchResults' : 'emptyList'; |
| 88 return loadTimeData.getString(emptyListMessage); | 102 return loadTimeData.getString(emptyListMessage); |
| 89 }, | 103 }, |
| 90 | 104 |
| 91 /** @private */ | 105 /** @private */ |
| 92 isEmptyList_: function() { | 106 isEmptyList_: function() { |
| 93 return this.displayedList.length == 0; | 107 return this.displayedList.length == 0; |
| 94 }, | 108 }, |
| 95 }); | 109 }); |
| OLD | NEW |