Skip to content

Commit

Permalink
kitodo#3747 improvements for primeface datatable all selection and of…
Browse files Browse the repository at this point in the history
… codacy review
  • Loading branch information
markusweigelt committed Nov 22, 2021
1 parent 2eb01f2 commit 6bae317
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions Kitodo/src/main/webapp/WEB-INF/resources/js/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* GPL3-License.txt file that was distributed with this source code.
*/

/*global PF*/
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^PF" }]*/

function registerRowToggleEvents(event) {
// add listener to expanded rows
$(".ui-expanded-row").hover(function() {
Expand All @@ -28,12 +31,31 @@ function registerRowToggleEvents(event) {
);
}

$( 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" ) ) {
PrimeFaces.widget.DataTable.prototype.updateData = (function () {
let cachedFunction = PrimeFaces.widget.DataTable.prototype.updateData;
return function () {
let reselectAll = (typeof this.selection !== undefined && this.selection[0] === '@all');
let result = cachedFunction.apply(this, arguments);
if (reselectAll) {
this.selectAllRows();
}
return result;
};
})();

$(document).on("click", ".allSelectable .ui-chkbox-all .ui-chkbox-box", function () {
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 () {
let tableId = $(this).closest(".allSelectable").attr('id').split(":").at(-1);
let table = new PF(tableId);
if (typeof table.selection !== undefined && table.selection[0] === '@all') {
table.unselectAllRows();
}
});

0 comments on commit 6bae317

Please sign in to comment.