From ff0cd9b24bd5fcc34a2045235868b4c23f831140 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 21 Oct 2021 18:00:57 +0100 Subject: [PATCH] Bug 32559: [ALT] Use column 'type' to pre-process search patterns This patch adds the option to pass 'type' at the 'column' definition level and then binds on that type to add date parsing to queries. --- .../prog/en/includes/patron-search.inc | 2 ++ koha-tmpl/intranet-tmpl/prog/js/datatables.js | 33 ++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index de4ba90c0de..fc587121cea 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -431,6 +431,7 @@ [% CASE 'dateofbirth' %] { "data": "date_of_birth", + "type": "date", "searchable": true, "orderable": true, "render": function( data, type, row, meta ) { @@ -552,6 +553,7 @@ [% CASE 'dateexpiry' %] { "data": "expiry_date", + "type": "date", "searchable": true, "orderable": true, "render": function( data, type, row, meta ) { diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 0fbb9b625cb..9d328484795 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -508,15 +508,18 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { /** * Create a new dataTables instance that uses the Koha RESTful API's as a data source - * @param {Object} options Please see the dataTables documentation for further details - * We extend the options set with the `criteria` key which allows - * the developer to select the match type to be applied during searches - * Valid keys are: `contains`, `starts_with`, `ends_with` and `exact` - * @param {Object} table_settings The arrayref as returned by TableSettings.GetTableSettings function available - * from the columns_settings template toolkit include - * @param {Boolean} add_filters Add a filters row as the top row of the table - * @param {Object} default_filters Add a set of default search filters to apply at table initialisation - * @return {Object} The dataTables instance + * @param {Object} options Please see the dataTables settings documentation for further + * details + * @param {string} [options.criteria=contains] A koha specific extension to the dataTables settings block that + * allows setting the 'comparison operator' used in searches + * Supports `contains`, `starts_with`, `ends_with` and `exact` match + * @param {string} [options.columns.*.type Data type the field is stored in so we may impose some additional + * manipulation to search strings. Supported types are currenlty 'date' + * @param {Object} table_settings The arrayref as returned by TableSettings.GetTableSettings function + * available from the columns_settings template toolkit include + * @param {Boolean} add_filters Add a filters row as the top row of the table + * @param {Object} default_filters Add a set of default search filters to apply at table initialisation + * @return {Object} The dataTables instance */ $.fn.kohaTable = function(options, table_settings, add_filters, default_filters) { var settings = null; @@ -601,6 +604,18 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { ? value : {like: (['contains', 'ends_with'].indexOf(criteria) !== -1?'%':'') + value + (['contains', 'starts_with'].indexOf(criteria) !== -1?'%':'')}; parts.push(part); + + // Alternate manipulated query based on type + let type = col.type; + if ( type === 'date' ) { + try { + let d = $date_to_rfc3339(value); + parts.push({[!attr.includes('.')?'me.'+attr:attr]:d}); + } + catch { + // Hide the warning if the date is not correct + }; + } } return parts; } -- 2.39.0