| 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-toolbar', | 6 is: 'bookmarks-toolbar', |
| 7 | 7 |
| 8 behaviors: [ | 8 behaviors: [ |
| 9 bookmarks.StoreClient, | 9 bookmarks.StoreClient, |
| 10 ], | 10 ], |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** @private */ | 13 /** @private */ |
| 14 searchTerm_: { | 14 searchTerm_: { |
| 15 type: String, | 15 type: String, |
| 16 observer: 'onSearchTermChanged_', | 16 observer: 'onSearchTermChanged_', |
| 17 }, | 17 }, |
| 18 | 18 |
| 19 sidebarWidth: { | 19 sidebarWidth: { |
| 20 type: String, | 20 type: String, |
| 21 observer: 'onSidebarWidthChanged_', | 21 observer: 'onSidebarWidthChanged_', |
| 22 }, | 22 }, |
| 23 | 23 |
| 24 showSelectionOverlay: { | 24 showSelectionOverlay: { |
| 25 type: Boolean, | 25 type: Boolean, |
| 26 computed: 'shouldShowSelectionOverlay_(selectedCount_)', | 26 computed: 'shouldShowSelectionOverlay_(selectedItems_, globalCanEdit_)', |
| 27 readOnly: true, | 27 readOnly: true, |
| 28 reflectToAttribute: true, | 28 reflectToAttribute: true, |
| 29 }, | 29 }, |
| 30 | 30 |
| 31 /** @private */ | 31 /** @private */ |
| 32 narrow_: { | 32 narrow_: { |
| 33 type: Boolean, | 33 type: Boolean, |
| 34 reflectToAttribute: true, | 34 reflectToAttribute: true, |
| 35 }, | 35 }, |
| 36 | 36 |
| 37 /** @private {!Set<string>} */ |
| 38 selectedItems_: Object, |
| 39 |
| 37 /** @private */ | 40 /** @private */ |
| 38 selectedCount_: Number, | 41 globalCanEdit_: Boolean, |
| 42 |
| 43 /** @private */ |
| 44 selectedFolder_: String, |
| 45 |
| 46 /** @private */ |
| 47 canChangeList_: { |
| 48 type: Boolean, |
| 49 computed: |
| 50 'computeCanChangeList_(selectedFolder_, searchTerm_, globalCanEdit_)', |
| 51 } |
| 39 }, | 52 }, |
| 40 | 53 |
| 41 attached: function() { | 54 attached: function() { |
| 42 this.watch('searchTerm_', function(state) { | 55 this.watch('searchTerm_', function(state) { |
| 43 return state.search.term; | 56 return state.search.term; |
| 44 }); | 57 }); |
| 45 this.watch('selectedCount_', function(state) { | 58 this.watch('selectedItems_', function(state) { |
| 46 return state.selection.items.size; | 59 return state.selection.items; |
| 60 }); |
| 61 this.watch('globalCanEdit_', function(state) { |
| 62 return state.prefs.canEdit; |
| 63 }); |
| 64 this.watch('selectedFolder_', function(state) { |
| 65 return state.selectedFolder; |
| 47 }); | 66 }); |
| 48 this.updateFromStore(); | 67 this.updateFromStore(); |
| 49 }, | 68 }, |
| 50 | 69 |
| 51 /** @return {CrToolbarSearchFieldElement} */ | 70 /** @return {CrToolbarSearchFieldElement} */ |
| 52 get searchField() { | 71 get searchField() { |
| 53 return /** @type {CrToolbarElement} */ (this.$$('cr-toolbar')) | 72 return /** @type {CrToolbarElement} */ (this.$$('cr-toolbar')) |
| 54 .getSearchField(); | 73 .getSearchField(); |
| 55 }, | 74 }, |
| 56 | 75 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 155 |
| 137 /** @private */ | 156 /** @private */ |
| 138 onSearchTermChanged_: function() { | 157 onSearchTermChanged_: function() { |
| 139 this.searchField.setValue(this.searchTerm_ || ''); | 158 this.searchField.setValue(this.searchTerm_ || ''); |
| 140 }, | 159 }, |
| 141 | 160 |
| 142 /** | 161 /** |
| 143 * @return {boolean} | 162 * @return {boolean} |
| 144 * @private | 163 * @private |
| 145 */ | 164 */ |
| 146 hasSearchTerm_: function() { | 165 computeCanChangeList_: function() { |
| 147 return !!this.searchTerm_; | 166 return !this.searchTerm_ && |
| 167 bookmarks.util.canReorderChildren( |
| 168 this.getState(), this.selectedFolder_); |
| 148 }, | 169 }, |
| 149 | 170 |
| 150 /** | 171 /** |
| 151 * @return {boolean} | 172 * @return {boolean} |
| 152 * @private | 173 * @private |
| 153 */ | 174 */ |
| 154 shouldShowSelectionOverlay_: function() { | 175 shouldShowSelectionOverlay_: function() { |
| 155 return this.selectedCount_ > 1; | 176 return this.selectedItems_.size > 1 && this.globalCanEdit_; |
| 177 }, |
| 178 |
| 179 canDeleteSelection_: function() { |
| 180 return bookmarks.CommandManager.getInstance().canExecute( |
| 181 Command.DELETE, this.selectedItems_); |
| 156 }, | 182 }, |
| 157 | 183 |
| 158 /** | 184 /** |
| 159 * @return {string} | 185 * @return {string} |
| 160 * @private | 186 * @private |
| 161 */ | 187 */ |
| 162 getItemsSelectedString_: function() { | 188 getItemsSelectedString_: function() { |
| 163 return loadTimeData.getStringF('itemsSelected', this.selectedCount_); | 189 return loadTimeData.getStringF('itemsSelected', this.selectedItems_.size); |
| 164 }, | 190 }, |
| 165 }); | 191 }); |
| OLD | NEW |