From cb0069ea6edc9545e570b1cdb3b3c8742366e6af Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Fri, 15 Oct 2021 17:03:05 +0200 Subject: [PATCH] #3747 improvements of codacy review --- .../main/webapp/WEB-INF/resources/js/lists.js | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Kitodo/src/main/webapp/WEB-INF/resources/js/lists.js b/Kitodo/src/main/webapp/WEB-INF/resources/js/lists.js index 2ce6d82fb8b..bf1622a8af4 100644 --- a/Kitodo/src/main/webapp/WEB-INF/resources/js/lists.js +++ b/Kitodo/src/main/webapp/WEB-INF/resources/js/lists.js @@ -28,12 +28,35 @@ function registerRowToggleEvents(event) { ); } -$( document ).on( "click", ".allSelectable .ui-chkbox-all .ui-chkbox-box", function() { +PrimeFaces.widget.DataTable.prototype.updateData = (function () { + let cached_function = PrimeFaces.widget.DataTable.prototype.updateData; + return function () { + let reselectAll = (this.selection != undefined && this.selection[0] === '@all'); + let result = cached_function.apply(this, arguments); + if (reselectAll) { + this.selectAllRows(); + } + return result; + }; +})(); + +$(document).on("click", ".allSelectable .ui-chkbox-all .ui-chkbox-box", function () { /*global PF*/ /*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^PF" }]*/ - if( $(this).hasClass( "ui-state-active" ) ) { + let tableId = $(this).closest(".allSelectable").attr('id').split(":").at(-1); + let table = new PF(tableId); + if ($(this).hasClass("ui-state-active")) { new PF('allSelectableOverlayPanel').show(); - } else { - new PF('processesTable').unselectAllRows(); + } + table.unselectAllRows(); +}); + +$(document).on("click", ".allSelectable .ui-chkbox .ui-chkbox-box", function () { + /*global PF*/ + /*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^PF" }]*/ + let tableId = $(this).closest(".allSelectable").attr('id').split(":").at(-1); + let table = new PF(tableId); + if (table.selection != undefined && table.selection[0] === '@all') { + table.unselectAllRows(); } }); \ No newline at end of file