mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
WebUI: Use event delegation to handle common table events
Event delegation is now used to handle basic table events. 2 minor fixes were added to match GUI behavior: * Clicking on the table body deselects everything * Table rows are now scrolled into view when using up/down arrows PR #21829.
This commit is contained in:
parent
ea35aa45d6
commit
c9c85eeb95
8 changed files with 142 additions and 173 deletions
|
@ -109,7 +109,7 @@ window.qBittorrent.Search ??= (() => {
|
|||
// load "Search in" preference from local storage
|
||||
$("searchInTorrentName").value = (LocalPreferences.get("search_in_filter") === "names") ? "names" : "everywhere";
|
||||
const searchResultsTableContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
|
||||
targets: ".searchTableRow",
|
||||
targets: "#searchResultsTableDiv tr",
|
||||
menu: "searchResultsTableMenu",
|
||||
actions: {
|
||||
Download: downloadSearchTorrent,
|
||||
|
@ -124,6 +124,8 @@ window.qBittorrent.Search ??= (() => {
|
|||
searchResultsTable.setup("searchResultsTableDiv", "searchResultsTableFixedHeaderDiv", searchResultsTableContextMenu);
|
||||
getPlugins();
|
||||
|
||||
searchResultsTable.dynamicTableDiv.addEventListener("dblclick", (e) => { downloadSearchTorrent(); });
|
||||
|
||||
// listen for changes to searchInNameFilter
|
||||
let searchInNameFilterTimer = -1;
|
||||
$("searchInNameFilter").addEventListener("input", () => {
|
||||
|
@ -373,8 +375,6 @@ window.qBittorrent.Search ??= (() => {
|
|||
|
||||
$("numSearchResultsVisible").textContent = searchResultsTable.getFilteredAndSortedRows().length;
|
||||
$("numSearchResultsTotal").textContent = searchResultsTable.getRowSize();
|
||||
|
||||
setupSearchTableEvents(true);
|
||||
};
|
||||
|
||||
const getStatusIconElement = (text, image) => {
|
||||
|
@ -769,20 +769,6 @@ window.qBittorrent.Search ??= (() => {
|
|||
$("numSearchResultsVisible").textContent = searchResultsTable.getFilteredAndSortedRows().length;
|
||||
};
|
||||
|
||||
const setupSearchTableEvents = (enable) => {
|
||||
const clickHandler = (e) => { downloadSearchTorrent(); };
|
||||
if (enable) {
|
||||
$$(".searchTableRow").each((target) => {
|
||||
target.addEventListener("dblclick", clickHandler);
|
||||
});
|
||||
}
|
||||
else {
|
||||
$$(".searchTableRow").each((target) => {
|
||||
target.removeEventListener("dblclick", clickHandler);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const loadSearchResultsData = function(searchId) {
|
||||
const state = searchState.get(searchId);
|
||||
|
||||
|
@ -820,8 +806,6 @@ window.qBittorrent.Search ??= (() => {
|
|||
}
|
||||
|
||||
if (response) {
|
||||
setupSearchTableEvents(false);
|
||||
|
||||
const state = searchState.get(searchId);
|
||||
const newRows = [];
|
||||
|
||||
|
@ -859,8 +843,6 @@ window.qBittorrent.Search ??= (() => {
|
|||
searchResultsTable.updateTable();
|
||||
}
|
||||
|
||||
setupSearchTableEvents(true);
|
||||
|
||||
if ((response.status === "Stopped") && (state.rowId >= response.total)) {
|
||||
resetSearchState(searchId);
|
||||
updateStatusIconElement(searchId, "QBT_TR(Search has finished)QBT_TR[CONTEXT=SearchJobWidget]", "images/task-complete.svg");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue