Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 Polymer({ | |
| 6 is: 'history-app', | |
| 7 | |
| 8 properties: { | |
| 9 // The id of the currently selected page. | |
| 10 selectedPage: { | |
| 11 type: String, | |
| 12 value: 'history-list' | |
| 13 } | |
| 14 }, | |
| 15 | |
| 16 // TODO(calamity): Replace these event listeners with data bound properties. | |
|
tsergeant
2016/05/02 16:19:20
Move these event listeners into their own function
calamity
2016/05/02 21:31:12
Done.
| |
| 17 attached: function() { | |
| 18 /** | |
| 19 * Listens for history-item being selected or deselected (through checkbox) | |
| 20 * and changes the view of the top toolbar. | |
| 21 * @param {{detail: {countAddition: number}}} e | |
| 22 */ | |
| 23 this.addEventListener('history-checkbox-select', function(e) { | |
| 24 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); | |
| 25 toolbar.count += e.detail.countAddition; | |
| 26 }); | |
| 27 | |
| 28 /** | |
| 29 * Listens for call to cancel selection and loops through all items to set | |
| 30 * checkbox to be unselected. | |
| 31 */ | |
| 32 this.addEventListener('unselect-all', function() { | |
| 33 var historyList = | |
| 34 /** @type {HistoryListElement} */(this.$['history-list']); | |
| 35 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); | |
| 36 historyList.unselectAllItems(toolbar.count); | |
| 37 toolbar.count = 0; | |
| 38 }); | |
| 39 | |
| 40 /** | |
| 41 * Listens for call to delete all selected items and loops through all items | |
| 42 * to determine which ones are selected and deletes these. | |
| 43 */ | |
| 44 this.addEventListener('delete-selected', function() { | |
| 45 if (!loadTimeData.getBoolean('allowDeletingHistory')) | |
| 46 return; | |
| 47 | |
| 48 // TODO(hsampson): add a popup to check whether the user definitely | |
| 49 // wants to delete the selected items. | |
| 50 | |
| 51 var historyList = | |
| 52 /** @type {HistoryListElement} */(this.$['history-list']); | |
| 53 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); | |
| 54 var toBeRemoved = historyList.getSelectedItems(toolbar.count); | |
| 55 chrome.send('removeVisits', toBeRemoved); | |
| 56 }); | |
| 57 | |
| 58 /** | |
| 59 * When the search is changed refresh the results from the backend. | |
| 60 * Ensures that the search bar is updated with the new search term. | |
| 61 * @param {{detail: {search: string}}} e | |
| 62 */ | |
| 63 this.addEventListener('search-changed', function(e) { | |
| 64 this.$.toolbar.setSearchTerm(e.detail.search); | |
| 65 /** @type {HistoryListElement} */(this.$['history-list']).setLoading(); | |
| 66 /** @type {HistoryToolbarElement} */(this.$.toolbar).searching = true; | |
| 67 chrome.send('queryHistory', [e.detail.search, 0, 0, 0, RESULTS_PER_PAGE]); | |
| 68 }); | |
| 69 }, | |
| 70 | |
| 71 historyResult: function(info, results) { | |
| 72 var list = /** @type {HistoryListElement} */(this.$['history-list']); | |
| 73 list.addNewResults(results, info.term); | |
| 74 /** @type {HistoryToolbarElement} */(this.$.toolbar).searching = false; | |
| 75 if (info.finished) | |
| 76 list.disableResultLoading(); | |
| 77 }, | |
| 78 | |
| 79 setForeignSessions: function(sessionList, isTabSyncEnabled) { | |
| 80 // TODO(calamity): Add a 'no synced devices' message when sessions are | |
| 81 // empty. | |
| 82 this.$['history-side-bar'].hidden = !isTabSyncEnabled; | |
| 83 var syncedDeviceElem = this.$['history-synced-device-manager']; | |
| 84 var syncedDeviceManager = | |
| 85 /** @type {HistorySyncedDeviceManagerElement} */(syncedDeviceElem); | |
| 86 if (isTabSyncEnabled) { | |
| 87 syncedDeviceManager.setSyncedHistory(sessionList); | |
| 88 /** @type {HistoryToolbarElement} */(this.$.toolbar).hasSidebar = true; | |
| 89 } | |
| 90 }, | |
| 91 | |
| 92 deleteComplete: function() { | |
| 93 var historyList = /** @type {HistoryListElement} */(this.$['history-list']); | |
| 94 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); | |
| 95 historyList.removeDeletedHistory(toolbar.count); | |
| 96 toolbar.count = 0; | |
| 97 } | |
| 98 }); | |
| OLD | NEW |