| 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: 'history-list-container', | 6 is: 'history-list-container', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 // The path of the currently selected page. | 9 // The path of the currently selected page. |
| 10 selectedPage_: String, | 10 selectedPage_: String, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // Disable querying until the first set of results have been returned. If | 59 // Disable querying until the first set of results have been returned. If |
| 60 // there is a search, query immediately to support search query params from | 60 // there is a search, query immediately to support search query params from |
| 61 // the URL. | 61 // the URL. |
| 62 var noResults = !this.queryResult || this.queryResult.results == null; | 62 var noResults = !this.queryResult || this.queryResult.results == null; |
| 63 if (queryState.queryingDisabled || | 63 if (queryState.queryingDisabled || |
| 64 (!this.queryState.searchTerm && noResults)) { | 64 (!this.queryState.searchTerm && noResults)) { |
| 65 return; | 65 return; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Close any open dialog if a new query is initiated. | 68 // Close any open dialog if a new query is initiated. |
| 69 if (!incremental && this.$.dialog.open) | 69 var dialog = this.$.dialog.getIfExists(); |
| 70 this.$.dialog.close(); | 70 if (!incremental && dialog && dialog.open) |
| 71 dialog.close(); |
| 71 | 72 |
| 72 this.set('queryState.querying', true); | 73 this.set('queryState.querying', true); |
| 73 this.set('queryState.incremental', incremental); | 74 this.set('queryState.incremental', incremental); |
| 74 | 75 |
| 75 var lastVisitTime = 0; | 76 var lastVisitTime = 0; |
| 76 if (incremental) { | 77 if (incremental) { |
| 77 var lastVisit = this.queryResult.results.slice(-1)[0]; | 78 var lastVisit = this.queryResult.results.slice(-1)[0]; |
| 78 lastVisitTime = lastVisit ? lastVisit.time : 0; | 79 lastVisitTime = lastVisit ? lastVisit.time : 0; |
| 79 } | 80 } |
| 80 | 81 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 91 .unselectAllItems(count); | 92 .unselectAllItems(count); |
| 92 }, | 93 }, |
| 93 | 94 |
| 94 /** | 95 /** |
| 95 * Delete all the currently selected history items. Will prompt the user with | 96 * Delete all the currently selected history items. Will prompt the user with |
| 96 * a dialog to confirm that the deletion should be performed. | 97 * a dialog to confirm that the deletion should be performed. |
| 97 */ | 98 */ |
| 98 deleteSelectedWithPrompt: function() { | 99 deleteSelectedWithPrompt: function() { |
| 99 if (!loadTimeData.getBoolean('allowDeletingHistory')) | 100 if (!loadTimeData.getBoolean('allowDeletingHistory')) |
| 100 return; | 101 return; |
| 101 | 102 this.$.dialog.get().then(function(dialog) { |
| 102 this.$.dialog.showModal(); | 103 dialog.showModal(); |
| 104 }); |
| 103 }, | 105 }, |
| 104 | 106 |
| 105 /** | 107 /** |
| 106 * @param {HistoryRange} range | 108 * @param {HistoryRange} range |
| 107 * @private | 109 * @private |
| 108 */ | 110 */ |
| 109 groupedRangeChanged_: function(range) { | 111 groupedRangeChanged_: function(range) { |
| 110 this.selectedPage_ = this.queryState.range == HistoryRange.ALL_TIME ? | 112 this.selectedPage_ = this.queryState.range == HistoryRange.ALL_TIME ? |
| 111 'infinite-list' : 'grouped-list'; | 113 'infinite-list' : 'grouped-list'; |
| 112 | 114 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 135 | 137 |
| 136 if (results[i].dateRelativeDay != currentDate) { | 138 if (results[i].dateRelativeDay != currentDate) { |
| 137 currentDate = results[i].dateRelativeDay; | 139 currentDate = results[i].dateRelativeDay; |
| 138 } | 140 } |
| 139 } | 141 } |
| 140 }, | 142 }, |
| 141 | 143 |
| 142 /** @private */ | 144 /** @private */ |
| 143 onDialogConfirmTap_: function() { | 145 onDialogConfirmTap_: function() { |
| 144 this.$['infinite-list'].deleteSelected(); | 146 this.$['infinite-list'].deleteSelected(); |
| 145 this.$.dialog.close(); | 147 var dialog = assert(this.$.dialog.getIfExists()); |
| 148 dialog.close(); |
| 146 }, | 149 }, |
| 147 | 150 |
| 148 /** @private */ | 151 /** @private */ |
| 149 onDialogCancelTap_: function() { | 152 onDialogCancelTap_: function() { |
| 150 this.$.dialog.close(); | 153 var dialog = assert(this.$.dialog.getIfExists()); |
| 154 dialog.close(); |
| 151 }, | 155 }, |
| 152 | 156 |
| 153 /** | 157 /** |
| 154 * Closes the overflow menu. | 158 * Closes the overflow menu. |
| 155 * @private | 159 * @private |
| 156 */ | 160 */ |
| 157 closeMenu_: function() { | 161 closeMenu_: function() { |
| 158 /** @type {CrSharedMenuElement} */(this.$.sharedMenu).closeMenu(); | 162 var menu = this.$.sharedMenu.getIfExists(); |
| 163 if (menu) |
| 164 menu.closeMenu(); |
| 159 }, | 165 }, |
| 160 | 166 |
| 161 /** | 167 /** |
| 162 * Opens the overflow menu unless the menu is already open and the same button | 168 * Opens the overflow menu unless the menu is already open and the same button |
| 163 * is pressed. | 169 * is pressed. |
| 164 * @param {{detail: {item: !HistoryEntry, target: !HTMLElement}}} e | 170 * @param {{detail: {item: !HistoryEntry, target: !HTMLElement}}} e |
| 171 * @return {Promise<Element>} |
| 165 * @private | 172 * @private |
| 166 */ | 173 */ |
| 167 toggleMenu_: function(e) { | 174 toggleMenu_: function(e) { |
| 168 var target = e.detail.target; | 175 var target = e.detail.target; |
| 169 /** @type {CrSharedMenuElement} */(this.$.sharedMenu).toggleMenu( | 176 return this.$.sharedMenu.get().then(function(menu) { |
| 170 target, e.detail.item); | 177 /** @type {CrSharedMenuElement} */(menu).toggleMenu( |
| 178 target, e.detail.item); |
| 179 }); |
| 171 }, | 180 }, |
| 172 | 181 |
| 173 /** @private */ | 182 /** @private */ |
| 174 onMoreFromSiteTap_: function() { | 183 onMoreFromSiteTap_: function() { |
| 175 var menu = /** @type {CrSharedMenuElement} */(this.$.sharedMenu); | 184 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 176 this.fire('search-domain', {domain: menu.itemData.domain}); | 185 this.fire('search-domain', {domain: menu.itemData.domain}); |
| 177 menu.closeMenu(); | 186 menu.closeMenu(); |
| 178 }, | 187 }, |
| 179 | 188 |
| 180 /** @private */ | 189 /** @private */ |
| 181 onRemoveFromHistoryTap_: function() { | 190 onRemoveFromHistoryTap_: function() { |
| 182 var menu = /** @type {CrSharedMenuElement} */(this.$.sharedMenu); | 191 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 183 md_history.BrowserService.getInstance() | 192 md_history.BrowserService.getInstance() |
| 184 .deleteItems([menu.itemData]) | 193 .deleteItems([menu.itemData]) |
| 185 .then(function(items) { | 194 .then(function(items) { |
| 186 this.$['infinite-list'].removeDeletedHistory_(items); | 195 this.$['infinite-list'].removeDeletedHistory_(items); |
| 187 // This unselect-all is to reset the toolbar when deleting a selected | 196 // This unselect-all is to reset the toolbar when deleting a selected |
| 188 // item. TODO(tsergeant): Make this automatic based on observing list | 197 // item. TODO(tsergeant): Make this automatic based on observing list |
| 189 // modifications. | 198 // modifications. |
| 190 this.fire('unselect-all'); | 199 this.fire('unselect-all'); |
| 191 }.bind(this)); | 200 }.bind(this)); |
| 192 menu.closeMenu(); | 201 menu.closeMenu(); |
| 193 }, | 202 }, |
| 194 }); | 203 }); |
| OLD | NEW |