From 7934bbdbd354b197e4b672d755ebe38506e33640 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 14 Feb 2022 15:13:17 +0100 Subject: [PATCH] Bug 30094: Make the patron search from request-article.pl use the REST API Reuse what has been done before to implement the patron search using the REST API route, when requesting an article Test plan: Request an article for a patron and confirm that the search is working correctly. --- circ/request-article.pl | 31 ++---- .../prog/en/modules/circ/request-article.tt | 103 ++++-------------- 2 files changed, 31 insertions(+), 103 deletions(-) diff --git a/circ/request-article.pl b/circ/request-article.pl index 6a6e63c1d2c..a9724749dc4 100755 --- a/circ/request-article.pl +++ b/circ/request-article.pl @@ -21,7 +21,6 @@ use Modern::Perl; use C4::Output qw( output_and_exit output_html_with_http_headers ); use C4::Auth qw( get_template_and_user ); -use C4::Utils::DataTables::Members; use C4::Search qw( enabled_staff_search_views ); use C4::Serials qw( CountSubscriptionFromBiblionumber ); use Koha::Biblios; @@ -46,7 +45,7 @@ my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user( my $action = $cgi->param('action') || q{}; my $biblionumber = $cgi->param('biblionumber'); my $patron_cardnumber = $cgi->param('patron_cardnumber'); -my $patron_id = $cgi->param('patron_id'); +my $patron_id = $cgi->param('borrowernumber'); my $biblio = Koha::Biblios->find($biblionumber); output_and_exit( $cgi, $cookie, $template, 'unknown_biblio') @@ -105,28 +104,7 @@ if ( $action eq 'create' ) { ); } }; - -} - -if ( !$patron && $patron_cardnumber ) { - my $results = C4::Utils::DataTables::Members::search( - { - searchmember => $patron_cardnumber, - dt_params => { iDisplayLength => -1 }, - } - ); - - my $patrons = $results->{patrons}; - - if ( scalar @$patrons == 1 ) { - $patron = Koha::Patrons->find( $patrons->[0]->{borrowernumber} ); - } - elsif (@$patrons) { - $template->param( patrons => $patrons ); - } - else { - $template->param( no_patrons_found => $patron_cardnumber ); - } + undef $patron; } if ( $patron && !$patron->can_request_article ) { @@ -145,6 +123,11 @@ $template->param( patron => $patron, subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber), C4::Search::enabled_staff_search_views, + attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes') + ? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ] + : [] + ), ); + output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt index 618a3c62f01..46f02428013 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt @@ -3,6 +3,7 @@ [% USE Context %] [% USE KohaDates %] [% USE Branches %] +[% USE Categories %] [% USE ItemTypes %] [% USE AuthorisedValues %] [% USE Price %] @@ -10,6 +11,10 @@ [% SET article_requests_view = 1 %] [% SET biblionumber = biblio.biblionumber %] [% INCLUDE 'doc-head-open.inc' %] +[% SET libraries = Branches.all %] +[% SET categories = Categories.all.unblessed %] +[% SET columns = ['name', 'address', 'cardnumber', 'dateofbirth', 'category', 'branch', 'phone'] %] +[% PROCESS "patron-search.inc" %] Request article › Circulation › Koha [% INCLUDE 'doc-head-close.inc' %] @@ -96,52 +101,12 @@ [% END %] [% END %] - [% IF no_patrons_found %] -
-

Patron not found

-

No patron with this name, please, try another

-
- [% ELSIF patrons %] -
-
- - - - - - - - - - - - - [% FOREACH patron IN patrons %] - - - - - - - - - [% END %] - -
NameCardnumberCategoryLibraryAddress
[% patron.surname | html %], [% patron.firstname | html %][% patron.cardnumber | html %][% patron.categorycode | html %][% patron.branchcode | html %][% patron.address | html %]
- -
-
-
- [% ELSIF !patron %] -
-
- -
Enter patron card number or partial name:
- - - -
-
+ [% UNLESS patron %] +
+ + [% PROCESS patron_search_filters_simple %] + [% PROCESS patron_search_table table_id => 'table_borrowers', open_on_row_click => 1 %] +
[% ELSE %] [% IF biblio.can_article_request( patron ) %] [% IF article_request_fee > 0 %] @@ -396,39 +361,6 @@ }); $(document).ready(function() { - if ( $( "#patron" ).size() ){ - $( "#patron" ).autocomplete({ - source: "/cgi-bin/koha/circ/ysearch.pl", - minLength: 3, - select: function( event, ui ) { - $( "#patron" ).val( ui.item.cardnumber ); - $( "#holds_patronsearch" ).submit(); - return false; - } - }) - .data( "ui-autocomplete" )._renderItem = function( ul, item ) { - return $( "
  • " ) - .data( "ui-autocomplete-item", item ) - .append( - "" - + ( item.surname ? item.surname.escapeHtml() : "" ) - + ", " - + ( item.firstname ? item.firstname.escapeHtml() : "" ) - + " (" + ( item.cardnumber ? item.cardnumber.escapeHtml() : "" ) + ")" - + " " - + "" - + ( item.address ? item.address.escapeHtml() : "" ) - + " " - + ( item.city ? item.city.escapeHtml() : "" ) - + " " - + ( item.zipcode ? item.zipcode.escapeHtml() : "" ) - + " " - + ( item.country ? item.country.escapeHtml() : "" ) - + "" - + "" ) - .appendTo( ul ); - }; - } $( ".ar-update-branchcode" ).on('focus', function(){ previous_branchcode = this.value; @@ -503,6 +435,19 @@ } }); + + [% 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/circ/request-article.pl?biblionumber=' _ biblio.biblionumber, + redirect_if_one_result => 1, + redirect_url => '/cgi-bin/koha/circ/request-article.pl?biblionumber=' _ biblio.biblionumber, + %] + [% END %] [% INCLUDE 'intranet-bottom.inc' %] -- 2.25.1