From fa491bcbc781729aba65dcf749d02fde9559696a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 Dec 2024 10:48:28 +0100 Subject: [PATCH] Bug 38255: Allow instantiation without parameters `$(node).kohaTable()` should work. Without this patch we got `Uncaught TypeError: settings is null` Signed-off-by: Lucas Gass Signed-off-by: Martin Renvoize --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 34 +++++++++---------- .../opac-tmpl/bootstrap/js/datatables.js | 34 +++++++++---------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 0becbb4ef12..f094bae8d3d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -1300,7 +1300,7 @@ function update_search_description( * @return {Object} The dataTables instance */ $.fn.kohaTable = function ( - options, + options = {}, table_settings, add_filters, default_filters, @@ -1309,8 +1309,6 @@ function update_search_description( show_search_descriptions, additional_search_descriptions ) { - var settings = null; - // Early return if the node does not exist if (!this.length) return; @@ -1334,23 +1332,23 @@ function update_search_description( options.processing = true; options.pagingType = "full_numbers"; } + } - settings = $.extend( - true, - {}, - dataTablesDefaults, - { - paging: true, - searching: true, - language: { - emptyTable: options.emptyTable - ? options.emptyTable - : __("No data available in table"), - }, + var settings = $.extend( + true, + {}, + dataTablesDefaults, + { + paging: true, + searching: true, + language: { + emptyTable: options.emptyTable + ? options.emptyTable + : __("No data available in table"), }, - options - ); - } + }, + options + ); settings["buttons"] = _dt_buttons({ settings, table_settings }); diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js index d16b428263b..5abae7494d6 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js @@ -295,9 +295,7 @@ function _dt_visibility(table_settings, table_dt) { * available from the columns_settings template toolkit include * @return {Object} The dataTables instance */ - $.fn.kohaTable = function (options, table_settings) { - var settings = null; - + $.fn.kohaTable = function (options = {}, table_settings = undefined) { // Early return if the node does not exist if (!this.length) return; @@ -310,23 +308,23 @@ function _dt_visibility(table_settings, table_dt) { dataTablesDefaults.initComplete(settings, json); }; } + } - settings = $.extend( - true, - {}, - dataTablesDefaults, - { - paging: true, - searching: true, - language: { - emptyTable: options.emptyTable - ? options.emptyTable - : __("No data available in table"), - }, + var settings = $.extend( + true, + {}, + dataTablesDefaults, + { + paging: true, + searching: true, + language: { + emptyTable: options.emptyTable + ? options.emptyTable + : __("No data available in table"), }, - options - ); - } + }, + options + ); settings["buttons"] = _dt_buttons({ settings, table_settings }); -- 2.48.1