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. |
| 17 listeners: { |
| 18 'history-checkbox-select': 'checkboxSelected', |
| 19 'unselect-all': 'unselectAll', |
| 20 'delete-selected': 'deleteSelected', |
| 21 'search-changed': 'searchChanged', |
| 22 }, |
| 23 |
| 24 /** |
| 25 * Listens for history-item being selected or deselected (through checkbox) |
| 26 * and changes the view of the top toolbar. |
| 27 * @param {{detail: {countAddition: number}}} e |
| 28 */ |
| 29 checkboxSelected: function(e) { |
| 30 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); |
| 31 toolbar.count += e.detail.countAddition; |
| 32 }, |
| 33 |
| 34 /** |
| 35 * Listens for call to cancel selection and loops through all items to set |
| 36 * checkbox to be unselected. |
| 37 */ |
| 38 unselectAll: function() { |
| 39 var historyList = |
| 40 /** @type {HistoryListElement} */(this.$['history-list']); |
| 41 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); |
| 42 historyList.unselectAllItems(toolbar.count); |
| 43 toolbar.count = 0; |
| 44 }, |
| 45 |
| 46 /** |
| 47 * Listens for call to delete all selected items and loops through all items |
| 48 * to determine which ones are selected and deletes these. |
| 49 */ |
| 50 deleteSelected: function() { |
| 51 if (!loadTimeData.getBoolean('allowDeletingHistory')) |
| 52 return; |
| 53 |
| 54 // TODO(hsampson): add a popup to check whether the user definitely |
| 55 // wants to delete the selected items. |
| 56 |
| 57 var historyList = |
| 58 /** @type {HistoryListElement} */(this.$['history-list']); |
| 59 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); |
| 60 var toBeRemoved = historyList.getSelectedItems(toolbar.count); |
| 61 chrome.send('removeVisits', toBeRemoved); |
| 62 }, |
| 63 |
| 64 /** |
| 65 * When the search is changed refresh the results from the backend. |
| 66 * Ensures that the search bar is updated with the new search term. |
| 67 * @param {{detail: {search: string}}} e |
| 68 */ |
| 69 searchChanged: function(e) { |
| 70 this.$.toolbar.setSearchTerm(e.detail.search); |
| 71 /** @type {HistoryListElement} */(this.$['history-list']).setLoading(); |
| 72 /** @type {HistoryToolbarElement} */(this.$.toolbar).searching = true; |
| 73 chrome.send('queryHistory', [e.detail.search, 0, 0, 0, RESULTS_PER_PAGE]); |
| 74 }, |
| 75 |
| 76 /** |
| 77 * @param {HistoryQuery} info An object containing information about the |
| 78 * query. |
| 79 * @param {!Array<HistoryEntry>} results A list of results. |
| 80 */ |
| 81 historyResult: function(info, results) { |
| 82 var list = /** @type {HistoryListElement} */(this.$['history-list']); |
| 83 list.addNewResults(results, info.term); |
| 84 /** @type {HistoryToolbarElement} */(this.$.toolbar).searching = false; |
| 85 if (info.finished) |
| 86 list.disableResultLoading(); |
| 87 }, |
| 88 |
| 89 /** |
| 90 * @param {!Array<!ForeignSession>} sessionList Array of objects describing |
| 91 * the sessions from other devices. |
| 92 * @param {boolean} isTabSyncEnabled Is tab sync enabled for this profile? |
| 93 */ |
| 94 setForeignSessions: function(sessionList, isTabSyncEnabled) { |
| 95 // TODO(calamity): Add a 'no synced devices' message when sessions are |
| 96 // empty. |
| 97 this.$['history-side-bar'].hidden = !isTabSyncEnabled; |
| 98 var syncedDeviceElem = this.$['history-synced-device-manager']; |
| 99 var syncedDeviceManager = |
| 100 /** @type {HistorySyncedDeviceManagerElement} */(syncedDeviceElem); |
| 101 if (isTabSyncEnabled) { |
| 102 syncedDeviceManager.setSyncedHistory(sessionList); |
| 103 /** @type {HistoryToolbarElement} */(this.$.toolbar).hasSidebar = true; |
| 104 } |
| 105 }, |
| 106 |
| 107 deleteComplete: function() { |
| 108 var historyList = /** @type {HistoryListElement} */(this.$['history-list']); |
| 109 var toolbar = /** @type {HistoryToolbarElement} */(this.$.toolbar); |
| 110 historyList.removeDeletedHistory(toolbar.count); |
| 111 toolbar.count = 0; |
| 112 } |
| 113 }); |
OLD | NEW |