From 8ad2e296a2120f1622838f45e14ff81d798bf24a Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Fri, 15 Aug 2025 15:16:45 +0000 Subject: [PATCH] Bug 40656: (follow-up) Create reusable additional filters library for DataTables This follow-up patch extracts the filter functionality into a reusable library: - Create AdditionalFilters.js library with chainable API for filter functionality - Rename table-filters.inc to additional-filters.inc for clarity - Refactor to use explicit element IDs instead of interpolation for better greppability (filter-expired vs filter-${id}) - Include proper cleanup methods (destroy) for memory management The library provides a fluent API: AdditionalFilters.init(['filter-expired', 'filter-cancelled']) .onChange((filters, { anyFiltersApplied }) => { ... }) .build({ status: ({ filters, isNotApplied }) => ... }); Test plan remains identical except for applying both patches on step 1. --- .../prog/en/includes/additional-filters.inc | 12 + .../prog/en/includes/table-filters.inc | 30 --- .../prog/en/modules/bookings/list.tt | 75 +++--- .../prog/js/additional-filters.js | 230 ++++++++++++++++++ 4 files changed, 270 insertions(+), 77 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/additional-filters.inc delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/table-filters.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/js/additional-filters.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-filters.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-filters.inc new file mode 100644 index 00000000000..5bf06dfc7b3 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-filters.inc @@ -0,0 +1,12 @@ +[% IF filters && filters.size > 0 %] + [% filter_class = filter_class || 'filters' %] + +
+ [% FOREACH filter IN filters %] + + [% filter.label_show | html %] + [% filter.label_hide | html %] + + [% END %] +
+[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/table-filters.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/table-filters.inc deleted file mode 100644 index 714ce3c1d78..00000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/table-filters.inc +++ /dev/null @@ -1,30 +0,0 @@ -[%# TABLE FILTER CONTROLS USAGE %] -[%# [ INCLUDE 'table-filters.inc' %] -[%# filters = [ %] -[%# { id = 'expired', label_show = t('Show expired'), label_hide = t('Hide expired') }, %] -[%# { id = 'cancelled', label_show = t('Show cancelled'), label_hide = t('Hide cancelled') }, %] -[%# { id = 'completed', label_show = t('Show completed'), label_hide = t('Hide completed') } %] -[%# ] %] -[%# filter_class = 'bookings' # Optional, defaults to 'filters' %] -[%# ] %] -[%# %] -[%# Parameters: %] -[%# - filters: Array of filter objects with: %] -[%# - id: Unique identifier for the filter %] -[%# - label_show: Text when filter shows items %] -[%# - label_hide: Text when filter hides items %] -[%# - active: Boolean - filter starts active (optional, defaults to true) %] -[%# - filter_class: CSS class prefix (optional, defaults to 'filters') %] - -[% IF filters && filters.size > 0 %] - [% filter_class = filter_class || 'filters' %] - -
- [% FOREACH filter IN filters %] - - [% filter.label_show | html %] - [% filter.label_hide | html %] - - [% END %] -
-[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt index f3341d5b714..16373710754 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/bookings/list.tt @@ -42,10 +42,10 @@
[% - INCLUDE 'table-filters.inc' + INCLUDE 'additional-filters.inc' filters = [ - { id = 'expired', label_show = t('Include expired'), label_hide = t('Exclude expired') }, - { id = 'cancelled', label_show = t('Include cancelled'), label_hide = t('Exclude cancelled') }, + { id = 'filter-expired', label_show = t('Include expired'), label_hide = t('Exclude expired') }, + { id = 'filter-cancelled', label_show = t('Include cancelled'), label_hide = t('Exclude cancelled') }, ] filter_class = 'bookings' %] @@ -74,6 +74,7 @@ [% Asset.js("js/modals/place_booking.js") | $raw %] [% Asset.js("js/cancel_booking_modal.js") | $raw %] [% Asset.js("js/combobox.js") | $raw %] + [% Asset.js("js/additional-filters.js") | $raw %]