From 96f5f80bdd567a306ec342ceee42cfac928144cb Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 7 Mar 2023 14:36:18 +0000 Subject: [PATCH] Bug 31028: (follow-up) Remove special:undefined There's a cleaner way to achieve this now using `additional_filters` and passing a function. This patch removes the `special:undefined` handling, replacing it with a single field filter passed as a function via additional_filters. Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- .../prog/en/modules/catalogue/detail.tt | 25 ++++++++++++++----- .../prog/en/modules/cataloguing/concerns.tt | 20 ++++++++++++--- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 16 ++++-------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index 6aa948a4d0..707a5d7cf3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -1353,6 +1353,18 @@ Note that permanent location is a code, and location may be an authval. $(document).ready(function() { var table_settings = [% TablesSettings.GetTableSettings( 'cataloguing', 'concerns', 'table_concerns', 'json' ) | $raw %]; + var filtered = false; + let additional_filters = { + resolved_date: function(){ + if ( filtered ) { + return { "=": null }; + } else { + return; + } + }, + biblio_id: [% biblionumber | uri %] + }; + var tickets_url = '/api/v1/tickets'; var tickets = $("#table_concerns").kohaTable({ "ajax": { @@ -1434,15 +1446,16 @@ Note that permanent location is a code, and location may be an authval. "orderable": false }, ] - }, table_settings, 0, { biblio_id: [% biblionumber | uri %]}); + }, table_settings, 0, additional_filters); - $('#hideResolved').on( "click", function() { - // It would be great if we could pass null here but it gets stringified - concerns.DataTable().columns('3').search('special:undefined').draw(); + $('#hideResolved').on("click", function() { + filtered = true; + tickets.DataTable().draw(); }); - $('#showAll').on( "click", function() { - concerns.DataTable().columns('3').search('').draw(); + $('#showAll').on("click", function() { + filtered = false; + tickets.DataTable().draw(); }); }); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt index 0da66460fa..21231d6a93 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt @@ -78,6 +78,17 @@ var table_settings = [% TablesSettings.GetTableSettings('cataloguing', 'concerns', 'table_concerns', 'json') | $raw %]; + var filtered = false; + let additional_filters = { + resolved_date: function(){ + if ( filtered ) { + return { "=": null }; + } else { + return; + } + } + }; + var tickets_url = '/api/v1/tickets'; var tickets = $("#table_concerns").kohaTable({ "ajax": { @@ -168,15 +179,16 @@ "orderable": false }, ] - }, table_settings, 1); + }, table_settings, 1, additional_filters); $('#hideResolved').on("click", function() { - // It would be great if we could pass null here but it gets stringified - tickets.DataTable().columns('3').search('special:undefined').draw(); + filtered = true; + tickets.DataTable().draw(); }); $('#showAll').on("click", function() { - tickets.DataTable().columns('3').search('').draw(); + filtered = false; + tickets.DataTable().draw(); }); }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index d2fa6c9ff2..9b32ab2460 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -586,18 +586,12 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { var part = {}; var attr = attributes[i]; let criteria = options.criteria; - if ( value === 'special:undefined' ) { - value = null; + if ( value.match(/^\^(.*)\$$/) ) { + value = value.replace(/^\^/, '').replace(/\$$/, ''); criteria = "exact"; - } - if ( value !== null ) { - if ( value.match(/^\^(.*)\$$/) ) { - value = value.replace(/^\^/, '').replace(/\$$/, ''); - criteria = "exact"; - } else { - // escape SQL LIKE special characters % - value = value.replace(/(\%|\\)/g, "\\$1"); - } + } else { + // escape SQL LIKE special characters % + value = value.replace(/(\%|\\)/g, "\\$1"); } part[!attr.includes('.')?'me.'+attr:attr] = criteria === 'exact' ? value -- 2.39.5