From fb9edc80f4dcfdea47be067958d80e475d81c0a1 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 --- .../prog/en/modules/catalogue/detail.tt | 4 ++-- .../prog/en/modules/cataloguing/concerns.tt | 20 +++++++++++++++---- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 16 +++++---------- 3 files changed, 23 insertions(+), 17 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..6b6b9ead5f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -1438,11 +1438,11 @@ Note that permanent location is a code, and location may be an authval. $('#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(); + tickets.DataTable().columns('3').search('special:undefined').draw(); }); $('#showAll').on( "click", function() { - concerns.DataTable().columns('3').search('').draw(); + tickets.DataTable().columns('3').search('').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.2