| 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 |
| 81 var maxResults = | 82 var maxResults = |
| 82 queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; | 83 queryState.range == HistoryRange.ALL_TIME ? RESULTS_PER_PAGE : 0; |
| 83 chrome.send('queryHistory', [ | 84 chrome.send('queryHistory', [ |
| 84 queryState.searchTerm, queryState.groupedOffset, queryState.range, | 85 queryState.searchTerm, queryState.groupedOffset, queryState.range, |
| 85 lastVisitTime, maxResults | 86 lastVisitTime, maxResults |
| 86 ]); | 87 ]); |
| 87 }, | 88 }, |
| 88 | 89 |
| 89 unselectAllItems: function(count) { | 90 unselectAllItems: function(count) { |
| 90 this.getSelectedList_().unselectAllItems(count); | 91 this.getSelectedList_().unselectAllItems(count); |
| 91 }, | 92 }, |
| 92 | 93 |
| 93 /** | 94 /** |
| 94 * Delete all the currently selected history items. Will prompt the user with | 95 * Delete all the currently selected history items. Will prompt the user with |
| 95 * a dialog to confirm that the deletion should be performed. | 96 * a dialog to confirm that the deletion should be performed. |
| 96 */ | 97 */ |
| 97 deleteSelectedWithPrompt: function() { | 98 deleteSelectedWithPrompt: function() { |
| 98 if (!loadTimeData.getBoolean('allowDeletingHistory')) | 99 if (!loadTimeData.getBoolean('allowDeletingHistory')) |
| 99 return; | 100 return; |
| 100 | 101 this.$.dialog.get().then(function(dialog) { |
| 101 this.$.dialog.showModal(); | 102 dialog.showModal(); |
| 103 }); |
| 102 }, | 104 }, |
| 103 | 105 |
| 104 /** | 106 /** |
| 105 * @param {HistoryRange} range | 107 * @param {HistoryRange} range |
| 106 * @private | 108 * @private |
| 107 */ | 109 */ |
| 108 groupedRangeChanged_: function(range) { | 110 groupedRangeChanged_: function(range) { |
| 109 this.selectedPage_ = this.queryState.range == HistoryRange.ALL_TIME ? | 111 this.selectedPage_ = this.queryState.range == HistoryRange.ALL_TIME ? |
| 110 'infinite-list' : 'grouped-list'; | 112 'infinite-list' : 'grouped-list'; |
| 111 | 113 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 134 | 136 |
| 135 if (results[i].dateRelativeDay != currentDate) { | 137 if (results[i].dateRelativeDay != currentDate) { |
| 136 currentDate = results[i].dateRelativeDay; | 138 currentDate = results[i].dateRelativeDay; |
| 137 } | 139 } |
| 138 } | 140 } |
| 139 }, | 141 }, |
| 140 | 142 |
| 141 /** @private */ | 143 /** @private */ |
| 142 onDialogConfirmTap_: function() { | 144 onDialogConfirmTap_: function() { |
| 143 this.getSelectedList_().deleteSelected(); | 145 this.getSelectedList_().deleteSelected(); |
| 144 this.$.dialog.close(); | 146 var dialog = assert(this.$.dialog.getIfExists()); |
| 147 dialog.close(); |
| 145 }, | 148 }, |
| 146 | 149 |
| 147 /** @private */ | 150 /** @private */ |
| 148 onDialogCancelTap_: function() { | 151 onDialogCancelTap_: function() { |
| 149 this.$.dialog.close(); | 152 var dialog = assert(this.$.dialog.getIfExists()); |
| 153 dialog.close(); |
| 150 }, | 154 }, |
| 151 | 155 |
| 152 /** | 156 /** |
| 153 * Closes the overflow menu. | 157 * Closes the overflow menu. |
| 154 * @private | 158 * @private |
| 155 */ | 159 */ |
| 156 closeMenu_: function() { | 160 closeMenu_: function() { |
| 157 /** @type {CrSharedMenuElement} */(this.$.sharedMenu).closeMenu(); | 161 var menu = this.$.sharedMenu.getIfExists(); |
| 162 if (menu) |
| 163 menu.closeMenu(); |
| 158 }, | 164 }, |
| 159 | 165 |
| 160 /** | 166 /** |
| 161 * Opens the overflow menu unless the menu is already open and the same button | 167 * Opens the overflow menu unless the menu is already open and the same button |
| 162 * is pressed. | 168 * is pressed. |
| 163 * @param {{detail: {item: !HistoryEntry, target: !HTMLElement}}} e | 169 * @param {{detail: {item: !HistoryEntry, target: !HTMLElement}}} e |
| 170 * @return {Promise<Element>} |
| 164 * @private | 171 * @private |
| 165 */ | 172 */ |
| 166 toggleMenu_: function(e) { | 173 toggleMenu_: function(e) { |
| 167 var target = e.detail.target; | 174 var target = e.detail.target; |
| 168 /** @type {CrSharedMenuElement} */(this.$.sharedMenu).toggleMenu( | 175 return this.$.sharedMenu.get().then(function(menu) { |
| 176 /** @type {CrSharedMenuElement} */(menu).toggleMenu( |
| 169 target, e.detail); | 177 target, e.detail); |
| 178 }); |
| 170 }, | 179 }, |
| 171 | 180 |
| 172 /** @private */ | 181 /** @private */ |
| 173 onMoreFromSiteTap_: function() { | 182 onMoreFromSiteTap_: function() { |
| 174 var menu = /** @type {CrSharedMenuElement} */(this.$.sharedMenu); | 183 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 175 this.fire('search-domain', {domain: menu.itemData.item.domain}); | 184 this.fire('search-domain', {domain: menu.itemData.item.domain}); |
| 176 menu.closeMenu(); | 185 menu.closeMenu(); |
| 177 }, | 186 }, |
| 178 | 187 |
| 179 /** @private */ | 188 /** @private */ |
| 180 onRemoveFromHistoryTap_: function() { | 189 onRemoveFromHistoryTap_: function() { |
| 181 var menu = /** @type {CrSharedMenuElement} */(this.$.sharedMenu); | 190 var menu = assert(this.$.sharedMenu.getIfExists()); |
| 182 var itemData = menu.itemData; | 191 var itemData = menu.itemData; |
| 183 md_history.BrowserService.getInstance() | 192 md_history.BrowserService.getInstance() |
| 184 .deleteItems([itemData.item]) | 193 .deleteItems([itemData.item]) |
| 185 .then(function(items) { | 194 .then(function(items) { |
| 186 this.getSelectedList_().removeItemsByPath([itemData.path]); | 195 this.getSelectedList_().removeItemsByPath([itemData.path]); |
| 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 |
| 195 /** | 204 /** |
| 196 * @return {HTMLElement} | 205 * @return {HTMLElement} |
| 197 * @private | 206 * @private |
| 198 */ | 207 */ |
| 199 getSelectedList_: function() { | 208 getSelectedList_: function() { |
| 200 return this.$.content.selectedItem; | 209 return this.$.content.selectedItem; |
| 201 }, | 210 }, |
| 202 }); | 211 }); |
| OLD | NEW |