From 07f6496907ed78e644f2a91f08a4c75814276840 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 27 Apr 2022 16:44:53 +0200 Subject: [PATCH] Bug 30622: Patron search when placing hold should redirect if cardnumber is entered When search a patron for placing a hold, if a cardnumber is entered we should pick the patron and use it, instead of display the table result. This was a regression caused by bug 30063. Test plan: - Place a hold on anything in staff - Search for 42 or any other existing cardnumber in your database Signed-off-by: David Nind Signed-off-by: Katrin Fischer --- .../prog/en/includes/patron-search.inc | 49 ++++++++++++++----- .../prog/en/modules/reserve/request.tt | 2 +- 2 files changed, 38 insertions(+), 13 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 ec68d3620a..34f8b8597d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -195,6 +195,7 @@ [%# Get the following parameters: %] [%# - redirect_if_one_result: Redirect to the patron if the search returns only one result, note that it will not redirect if filters of the DT are used (this is a feature) %] [%# - redirect_url: The URL to use, the borrowernumber parameter will be added %] +[%# - redirect_if_attribute_equal: Name of the attribute to use for the redirect. Query using this attribute, before the normal search %] [%# filter: Same as patron_search_table %] [%# open_on_row_click: boolean, default off. Will allow to select a patron by clicking on the whole tr element %] [%# columns: list of columns that will be displayed. Possible values are: 'checkbox', 'cardnumber', 'dateofbirth', 'address', 'name', 'name-address', 'branch', 'category', 'dateexpiry', 'borrowernotes, 'phone', 'checkouts', 'account_balance', 'action' %] @@ -260,6 +261,18 @@ getSearchByLocation( false ); }); + [% SWITCH filter %] + [% CASE 'suggestions_managers' %] + let patron_search_url = '/api/v1/suggestions/managers'; + [% CASE 'baskets_managers' %] + let patron_search_url = '/api/v1/acquisitions/baskets/managers'; + [% CASE 'funds_owners' %] + let patron_search_url = '/api/v1/acquisitions/funds/owners'; + [% CASE 'funds_users' %] + let patron_search_url = '/api/v1/acquisitions/funds/users'; + [% CASE %] + let patron_search_url = '/api/v1/patrons'; + [% END %] $(document).ready(function(){ $("#info").hide(); @@ -317,6 +330,7 @@ return filters; } }; + [% UNLESS default_sort_column %] [% default_sort_column = "name" %] [% END %] @@ -324,18 +338,7 @@ [% SET embed = ['extended_attributes'] %] patrons_table = $("#[% table_id | html %]").kohaTable({ "ajax": { - [% SWITCH filter %] - [% CASE 'suggestions_managers' %] - "url": '/api/v1/suggestions/managers', - [% CASE 'baskets_managers' %] - "url": '/api/v1/acquisitions/baskets/managers', - [% CASE 'funds_owners' %] - "url": '/api/v1/acquisitions/funds/owners', - [% CASE 'funds_users' %] - "url": '/api/v1/acquisitions/funds/users', - [% CASE %] - "url": '/api/v1/patrons', - [% END %] + "url": patron_search_url, "dataSrc": function ( json ) { [% IF redirect_if_one_result %] // redirect if there is only 1 result. @@ -716,6 +719,28 @@ } function filter() { + [% IF redirect_if_attribute_equal %] + let filter = $("#search_patron_filter").val(); + if ( filter ) { + $.ajax({ + data: { cardnumber: filter, _match: 'exact' }, + type: 'GET', + url: patron_search_url, + success: function(data) { + if ( data.length == 1 ) { + let url = '[% redirect_url | url %]'.indexOf("?") != -1 + ? '[% redirect_url | url %]&borrowernumber=' + data[0].patron_id + : '[% redirect_url | url %]?borrowernumber=' + data[0].patron_id; + document.location.href = url; + return false; + } + }, + error: function() { + alert( _("An error occurred. Check the logs") ); + } + }); + } + [% END %] $("#firstletter_filter").val(''); $("#[% table_id | html %]_search_results").show(); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index 65d95f6e0f..e3ad31601c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -1607,7 +1607,7 @@ table_settings = [% TablesSettings.GetColumns( 'circ', 'circulation', 'table_borrowers', 'json' ) | $raw %]; - [% PROCESS patron_search_js table_id => 'table_borrowers', categories => categories, libraries => libraries, extended_attribute_types => attribute_type_codes, columns => columns, open_on_row_click => 1, on_click_url => '/cgi-bin/koha/reserve/request.pl?' _ url_biblio_params, redirect_if_one_result => 1, redirect_url => '/cgi-bin/koha/reserve/request.pl?' _ url_biblio_params %] + [% PROCESS patron_search_js table_id => 'table_borrowers', categories => categories, libraries => libraries, extended_attribute_types => attribute_type_codes, columns => columns, open_on_row_click => 1, on_click_url => '/cgi-bin/koha/reserve/request.pl?' _ url_biblio_params, redirect_if_one_result => 1, redirect_url => '/cgi-bin/koha/reserve/request.pl?' _ url_biblio_params, redirect_if_attribute_equal => 'cardnumber' %]