From 958c37c5c976449b91f1d8a46979aa1a2e5d79c3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 24 Jul 2023 11:14:31 +0100 Subject: [PATCH] Bug 34226: Use 'type' at the datatable config level Lets use 'type' definitions at the datatables settings level instead Signed-off-by: Lucas Gass Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- .../prog/en/includes/patron-search.inc | 2 + koha-tmpl/intranet-tmpl/prog/js/datatables.js | 50 +++++++++---------- 2 files changed, 27 insertions(+), 25 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 3c1ce6fe2c..8f13fa0374 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -430,6 +430,7 @@ [% CASE 'dateofbirth' %] { "data": "date_of_birth", + "type": "date", "searchable": true, "orderable": true, "render": function( data, type, row, meta ) { @@ -551,6 +552,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 9ee051d282..fe4fe8de97 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -562,13 +562,15 @@ function _dt_default_ajax (params){ } let built_value; - let is_date_field; + if ( col.type == 'date' ) { + let rfc3339 = $date_to_rfc3339(value); + if ( rfc3339 != 'Invalid Date' ) { + built_value = rfc3339; + } + } if ( col.datatype !== undefined ) { - if ( col.datatype == 'date' ) { - is_date_field = true; - } - else if (col.datatype == 'related-object') { + if (col.datatype == 'related-object') { let query_term = value; if (criteria != 'exact') { @@ -582,15 +584,6 @@ function _dt_default_ajax (params){ } else { console.log("datatype %s not supported yet".format(col.datatype)); } - } else if (col.data && ( col.data.endsWith('_on') || col.data.endsWith('_date') ) ) { - is_date_field = true; - } - - if ( is_date_field ) { - let rfc3339 = $date_to_rfc3339(value); - if ( rfc3339 != 'Invalid Date' ) { - built_value = rfc3339; - } } if (col.datatype != 'related-object') { @@ -671,8 +664,12 @@ function _dt_default_ajax (params){ if(query_parameters.length) { query_parameters = JSON.stringify(query_parameters.length === 1?query_parameters[0]:{"-and": query_parameters}); - dataSet.q = query_parameters; - delete options.query_parameters; + if(options.header_filter) { + options.query_parameters = query_parameters; + } else { + dataSet.q = query_parameters; + delete options.query_parameters; + } } else { delete options.query_parameters; } @@ -930,15 +927,18 @@ function _dt_add_filters(table_node, table_dt, filters_options = {}) { /** * 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; -- 2.39.5