From 8bbfab31e0a64310bf55d50ece2e185a331b07aa Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 17 Oct 2024 15:24:24 +0200 Subject: [PATCH] Bug 33484: External filter into state - support checkboxes Signed-off-by: Pedro Amorim Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 8cfb356739..7a073e1318 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -1014,7 +1014,19 @@ function _dt_save_restore_state(table_settings, external_filter_nodes={}){ // but only the main one has the table settings (and so the state saved) data.external_filters = Object.keys(external_filter_nodes).reduce( (r, k) => { - r[k] = $(external_filter_nodes[k]).val(); + let node = $(external_filter_nodes[k]); + let tag_name = node.prop("tagName"); + if (tag_name == "INPUT" && node.prop("type") == "checkbox") { + r[k] = $(external_filter_nodes[k]).prop("checked"); + } else if (tag_name == "INPUT" || tag_name == "SELECT") { + r[k] = $(external_filter_nodes[k]).val(); + } else { + console.log( + "Tag '%s' not supported yet for DT state".format( + tag_name + ) + ); + } return r; }, {} @@ -1026,7 +1038,22 @@ function _dt_save_restore_state(table_settings, external_filter_nodes={}){ if (data.external_filters) { Object.keys(external_filter_nodes).forEach((k, i) => { if (data.external_filters.hasOwnProperty(k)) { - $(external_filter_nodes[k]).val(data.external_filters[k]); + let node = $(external_filter_nodes[k]); + let tag_name = node.prop("tagName"); + if ( + tag_name == "INPUT" && + node.prop("type") == "checkbox" + ) { + node.prop("checked", data.external_filters[k]); + } else if (tag_name == "INPUT" || tag_name == "SELECT") { + node.val(data.external_filters[k]); + } else { + console.log( + "Tag '%s' not supported yet for DT state".format( + tag_name + ) + ); + } } }); } -- 2.39.5