From 69af2050946835539c13521e87bea89aff290370 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Sat, 6 Jan 2018 21:04:03 -0500 Subject: [PATCH 1/2] Use .each(). Refactor conditionals. --- src/webui/www/private/scripts/dynamicTable.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index b9589971e..b7e1e79a4 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -489,19 +489,14 @@ var DynamicTable = new Class({ }, selectRow : function (rowId) { - this.selectedRows.empty(); + this.deselectAll(); this.selectedRows.push(rowId); - var trs = this.tableBody.getElements('tr'); - for (var i = 0; i < trs.length; i++) { - var tr = trs[i]; - if (tr.rowId == rowId) { - if (!tr.hasClass('selected')) - tr.addClass('selected'); - } + this.tableBody.getElements('tr').each(function(tr) { + if (tr.rowId == rowId) + tr.addClass('selected'); else - if (tr.hasClass('selected')) tr.removeClass('selected'); - } + }); this.onSelectedRowChanged(); }, From 2227c3afc111c389b2021f379afbc2868722c934 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Sat, 6 Jan 2018 21:04:26 -0500 Subject: [PATCH 2/2] Reselect torrents in WebUI after full update Temp fix for #8209. --- src/webui/www/private/scripts/client.js | 6 ++++++ src/webui/www/private/scripts/dynamicTable.js | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index edd0db80a..f0807b51e 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -289,9 +289,11 @@ window.addEvent('load', function () { onSuccess : function (response) { $('error_div').set('html', ''); if (response) { + var torrentsTableSelectedRows; var update_categories = false; var full_update = (response['full_update'] === true); if (full_update) { + torrentsTableSelectedRows = torrentsTable.selectedRowsIds(); torrentsTable.clear(); category_list = {}; } @@ -348,6 +350,10 @@ window.addEvent('load', function () { updateCategoryList(); torrentsTableContextMenu.updateCategoriesSubMenu(category_list); } + + if (full_update) + // re-select previously selected rows + torrentsTable.reselectRows(torrentsTableSelectedRows); } clearTimeout(syncMainDataTimer); syncMainDataTimer = syncMainData.delay(syncMainDataTimerPeriod); diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index b7e1e79a4..7798c00b9 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -500,6 +500,15 @@ var DynamicTable = new Class({ this.onSelectedRowChanged(); }, + reselectRows : function(rowIds) { + this.deselectAll(); + this.selectedRows = rowIds.slice(); + this.tableBody.getElements('tr').each(function(tr) { + if (rowIds.indexOf(tr.rowId) > -1) + tr.addClass('selected'); + }); + }, + onSelectedRowChanged : function () {}, updateRowData : function (data) {