From 30c1c321b4a387d8b468ea045f09630cc2d1da4f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 28 Apr 2022 14:36:18 +0200 Subject: [PATCH] Bug 30643: Remove useless OR part from query generated by DT REST API wrapper To test: Don't apply this patch Search for patrons on the main patron search Notice the {"me.firstname":{"like":"%%"}}, etc. Apply this patch and confirm that the query is now correctly formed --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 2c05bd4a464..8f4f65b7f9b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -583,7 +583,6 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { return parts; } - var filter = data.search.value; // Build query for each column filter var and_query_parameters = settings.aoColumns .filter(function(col) { @@ -598,17 +597,19 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { }); // Build query for the global search filter - var or_query_parameters = settings.aoColumns - .filter(function(col) { - return col.bSearchable - }) - .map(function(col) { - var value = filter; - return build_query(col, value) - }) - .map(function r(e){ - return ($.isArray(e) ? $.map(e, r) : e); - }); + var global_filter = data.search.value; + var or_query_parameters = global_filter.length + ? settings.aoColumns + .filter(function(col) { + return col.bSearchable + }) + .map(function(col) { + return build_query(col, global_filter) + }) + .map(function r(e){ + return ($.isArray(e) ? $.map(e, r) : e); + }) + : []; if ( default_filters ) { let additional_filters = {}; -- 2.25.1