From 49e5b9daef34413823c1976d8111a8919897868a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 10 Feb 2022 18:00:22 +0100 Subject: [PATCH] Bug 30055: Put extended attributes search back Last patches remove the ability to search on extended attributes. C4::Utils::DataTables::Members::search is searching on all the attributes that are flagged as "searchable", we want to keep this behaviour. I have tried several things and this is the simplest I have found. --- .../prog/en/modules/members/search.tt | 21 ++++++++++++++++++- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 14 ++++++++++--- members/search.pl | 5 +++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt index 112f96a9e52..ed1857207aa 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt @@ -139,6 +139,10 @@ map[l.branchcode] = l; return map; }, {}); + + [% IF Koha.Preference('ExtendedPatronAttributes') %] + let extended_attribute_types = [% To.json(attribute_type_codes) | $raw %]; + [% END %] [% INCLUDE 'datatables.inc' %] [% INCLUDE 'js-date-format.inc' %] @@ -160,7 +164,21 @@ let start_with = $("#firstletter_filter").val() if (!start_with) return ""; return { "like": start_with + "%" } - } + }, + [% IF Koha.Preference('ExtendedPatronAttributes') %] + "-or": function(){ + let filter = $("#searchmember_filter").val(); + if (!filter) return ""; + return [ + { + "extended_attributes.value": { "like": "%" + filter + "%" } + }, + { + "extended_attributes.code": extended_attribute_types + } + ]; + }, + [% END %] }; patrons_table = $("#memberresultst").kohaTable({ "ajax": { @@ -177,6 +195,7 @@ "url": '/api/v1/patrons' [% END %] }, + embed: ['extended_attributes'], "order": [[ 1, "asc" ]], "iDeferLoading": 0, "columns": [ diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 73e67fde4f7..327bd00cb62 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -556,7 +556,6 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { _per_page: length }; - function build_query(col, value){ var parts = []; var attributes = col.data.split(':'); @@ -601,13 +600,22 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { if ( default_filters ) { let additional_filters = {}; for ( f in default_filters ) { + let k; let v; if ( typeof(default_filters[f]) === 'function' ) { let val = default_filters[f](); if ( val != undefined && val != "" ) { - additional_filters[f] = val; + k = f; v = val; } } else { - additional_filters[f] = default_filters[f]; + k = f; v = default_filters[f]; + } + + // Pass to -or if you want a separate OR clause + // It's not the usual DBIC notation! + if ( f == '-or' ) { + if (v) or_query_parameters.push(v) + } else if ( v ) { + additional_filters[k] = v; } } if ( Object.keys(additional_filters).length ) { diff --git a/members/search.pl b/members/search.pl index 4689cf89b17..b53773ad007 100755 --- a/members/search.pl +++ b/members/search.pl @@ -18,8 +18,10 @@ use Modern::Perl; use CGI qw ( -utf8 ); +use C4::Context; use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); +use Koha::Patron::Attribute::Types; my $input = CGI->new; @@ -45,5 +47,8 @@ $template->param( filter => $filter, selection_type => $selection_type, alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ), + attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes') + ? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ] + : [] ), ); output_html_with_http_headers( $input, $cookie, $template->output ); -- 2.25.1