From 6cfd3368434c98d103a92d2252b635898c90d293 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Feb 2022 16:29:23 +0100 Subject: [PATCH] Bug 30093: Make patron search from request.pl use the REST API In this patch we want to reuse what has been done in the previous bug report to search patrons using the REST API route. The code is mainly in members/search.tt, for all the patron searches that "add" or "select" a patron (popup windows). The patron search for holds is a bit different, we don't want to open a popup window. We are moving to code to an include file (patron-search.tt) to make it reusable easily. Note that we are improving how the patron's addresses are displayed, and provide a JS equivalent to the TT includes files. Test plan: Search for patrons from the "Place a hold on" view. You should see the same view as behaviour, with more filters. --- .../en/includes/js-patron-format-address.inc | 110 +++- .../prog/en/includes/patron-search.inc | 493 ++++++++++++++++++ .../prog/en/modules/members/search.tt | 387 +------------- .../prog/en/modules/reserve/request.tt | 128 ++--- .../modules/reserve/tables/members_results.tt | 32 -- members/search.pl | 1 - reserve/request.pl | 10 +- 7 files changed, 651 insertions(+), 510 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/reserve/tables/members_results.tt diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format-address.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format-address.inc index 935a1f36c48..317afd1d097 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format-address.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-format-address.inc @@ -1,20 +1,112 @@ +[% USE raw %] +[% USE To %] +[% USE AuthorisedValues %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc new file mode 100644 index 00000000000..90e0d9ff895 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -0,0 +1,493 @@ +[% USE Koha %] +[% USE Branches %] +[% USE raw %] +[% USE To %] + +[% BLOCK patron_search_filters_simple %] +
+
Enter patron card number or partial name:
+ + +
+[% END %] + +[% BLOCK patron_search_filters %] +
+
+

Search for patron

+
    +
  1. + +
    Enter patron card number or partial name:
    + +
  2. + + [% FOR column IN columns %] + [% SWITCH column %] + [% CASE 'branch' %] +
  3. + + +
  4. + [% CASE 'category' %] +
  5. + + +
  6. + [% END %] + [% END %] +
+
+ +
+
+
+[% END %] + +[% BLOCK patron_search_table %] + + [% IF filter == 'suggestions_managers' %] +
Only staff with superlibrarian or suggestions_manage permissions are returned in the search results
+ [% ELSIF filter == 'orders_managers' %] +
Only staff with superlibrarian or acquisitions permissions (or order_manage permission if granular permissions are enabled) are returned in the search results
+ [% ELSIF filter == 'funds_owners' OR filter == 'funds_users' %] +
Only staff with superlibrarian or acquisitions permissions (or budget_modify permission if granular permissions are enabled) are returned in the search results
+ [% END %] + +
+ Browse by last name: + [% SET alphabet = Koha.Preference('alphabet').split(' ') %] + [% UNLESS alphabet.size %] + [% alphabet = ['A' .. 'Z'] %] + [% END %] + [% FOREACH letter IN alphabet %] + [% letter | html %] + [% END %] +
+ + + + + + +[% END %] + +[% BLOCK patron_search_js %] + + [% IF redirect_if_one_result && !redirect_url %] + + [% END %] + + + [% INCLUDE 'datatables.inc' %] + [% INCLUDE 'js-date-format.inc' %] + [% INCLUDE 'js-patron-get-age.inc' %] + [% INCLUDE 'js-patron-format.inc' %] + [% INCLUDE 'js-patron-format-address.inc' %] + + +[% END %] 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 d74f044ea29..620a9d73db6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/search.tt @@ -1,5 +1,4 @@ [% USE raw %] -[% USE To %] [% USE Asset %] [% USE Koha %] [% USE Branches %] @@ -8,393 +7,37 @@ [% INCLUDE 'doc-head-open.inc' %] [% SET libraries = Branches.all %] [% SET categories = Categories.all.unblessed %] +[% PROCESS 'patron-search.inc' %] Patron search › Koha [% INCLUDE 'doc-head-close.inc' %] - +[%# FIXME This is not great, we should make members/memberentrygen.tt use a modal as well and we won't need that here %] - [% MACRO jsinclude BLOCK %] - - [% INCLUDE 'datatables.inc' %] - [% INCLUDE 'js-date-format.inc' %] - [% INCLUDE 'js-patron-get-age.inc' %] - [% INCLUDE 'js-patron-format.inc' %] - [% INCLUDE 'js-patron-format-address.inc' %] - - + [% PROCESS patron_search_js + table_id => 'memberresultst', + categories => categories, + libraries => libraries, + extended_attribute_types => extended_attribute_types, + columns => columns, + filter => filter, + selection_type => selection_type, + callback => callback + %] [% END %] [% SET popup_window = 1 %] 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 cee579cc3b6..1a40ef665f8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -14,6 +14,10 @@ [% PROCESS 'i18n.inc' %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] +[% SET libraries = Branches.all %] +[% SET categories = Categories.all.unblessed %] +[% SET columns = ['name', 'cardnumber', 'dateofbirth', 'category', 'branch', 'address', 'phone'] %] +[% PROCESS "patron-search.inc" %] [% UNLESS ( multi_hold ) %] Place a hold on [% INCLUDE 'biblio-title-head.inc' %] › Holds › Circulation › Koha [% ELSE %] @@ -163,30 +167,9 @@ [% END %]
-
-
Enter patron card number or partial name:
- - - [% FOREACH biblionumber IN biblionumbers %] - - [% END %] -
- - - - - - - - - - - - - - - + [% PROCESS patron_search_filters_simple %] + [% PROCESS patron_search_table table_id => 'table_borrowers', open_on_row_click => 1 %]
[% IF clubcount %]
@@ -1187,7 +1170,6 @@ } var MSG_CANCEL_SELECTED = _("Cancel selected (%s)"); - columns_settings_borrowers_table = [% TablesSettings.GetColumns( 'circ', 'circulation', 'table_borrowers', 'json' ) | $raw %]; $.fn.select2.defaults.set("width", "100%" ); $.fn.select2.defaults.set("dropdownAutoWidth", true ); @@ -1569,79 +1551,35 @@ } return false; }); + }); + - [% FOREACH biblionumber IN biblionumbers %] - [% SET url_biblio_params = url_biblio_params _ "&biblionumber=" _ biblionumber %] - [% END %] - [% IF multi_hold %] - [% SET url_biblio_params = url_biblio_params _ "&multi_hold=1" %] - [% END %] - search = 0; - dtMemberResults = KohaTable("table_borrowers", { - 'bServerSide': true, - 'sAjaxSource': "/cgi-bin/koha/svc/members/search", - 'fnServerData': function(sSource, aoData, fnCallback) { - if ( ! search ) { - return; - } - aoData.push({ - 'name': 'searchmember', - 'value': $("#patron").val() - },{ - 'name': 'template_path', - 'value': 'reserve/tables/members_results.tt', - }); - $.ajax({ - 'dataType': 'json', - 'type': 'POST', - 'url': sSource, - 'data': aoData, - 'success': function(json){ - // redirect if there is only 1 result. - if ( json.iTotalDisplayRecords == 1 ) { - var borrowernumber = json.aaData[0].borrowernumber; - document.location.href = '/cgi-bin/koha/reserve/request.pl?borrowernumber=' + borrowernumber + "[% url_biblio_params %]" - return false; - } - fnCallback(json); - } - }); - }, - 'fnDrawCallback': function (oSettings) { - var data = this.fnGetData(); - $.each($(this).find("tbody tr"), function(index, tr) { - let url = '/cgi-bin/koha/reserve/request.pl?borrowernumber=' + data[index].borrowernumber + "[% url_biblio_params %]" - $(tr).off('click').on('click', function() { - document.location.href = url; - }).addClass('clickable'); - $(tr).find("a.patron_preview").attr('href', url); - }); - }, - 'aoColumns':[ - { 'mDataProp': 'dt_name' }, - { 'mDataProp': 'dt_address' }, - { 'mDataProp': 'dt_cardnumber' }, - { 'mDataProp': 'dt_dateofbirth' }, - { 'mDataProp': 'dt_category' }, - { 'mDataProp': 'dt_branch' }, - { 'mDataProp': 'dt_phone' }, - ], - 'bFilter': false, - 'bAutoWidth': false, - 'sPaginationType': 'full_numbers', - "bProcessing": true - }, columns_settings_borrowers_table ); - $("#table_borrowers_wrapper").hide(); - - function filter() { - search = 1; - $("#table_borrowers").show(); - $("#table_borrowers_wrapper").show(); - dtMemberResults.fnDraw(); - return false; - } - $("#holds_patronsearch").on("submit", filter); + + + [% SET url_biblio_params = "biblionumber=" _ biblionumbers.join("&biblionumber=") %] + [% IF multi_hold %] + [% SET url_biblio_params = url_biblio_params _ "&multi_hold=1" %] + [% END %] + + [% 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 + %] + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/tables/members_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/tables/members_results.tt deleted file mode 100644 index 15370307a58..00000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/tables/members_results.tt +++ /dev/null @@ -1,32 +0,0 @@ -[% USE raw %] -[% USE I18N %] -[% USE To %] -[% USE Price %] -[% PROCESS 'member-display-address-style.inc' %] -{ - "sEcho": [% sEcho | html %], - "iTotalRecords": [% iTotalRecords | html %], - "iTotalDisplayRecords": [% iTotalDisplayRecords | html %], - "aaData": [ - [% FOREACH data IN aaData %] - { - "dt_name": - "[% INCLUDE 'patron-title.inc' borrowernumber = data.borrowernumber category_type = data.category_type firstname = data.firstname surname = data.surname othernames = data.othernames invert_name = 1 | $To %]
", - "dt_address": - "[%~ INCLUDE 'display-address-style' patron=data no_line_break=1 | $To ~%]", - "dt_cardnumber": - "[% data.cardnumber | html | $To %]", - "dt_dateofbirth": - "[% INCLUDE 'patron-age.inc' patron = data %]", - "dt_category": - "[% data.category_description | html | $To %] ([% data.category_type | html | $To %])", - "dt_branch": - "[% data.branchname | html | $To %]", - "dt_phone": - "[% data.phone| html | $To %]", - "borrowernumber": - "[% data.borrowernumber | html %]" - }[% UNLESS loop.last %],[% END %] - [% END %] - ] -} diff --git a/members/search.pl b/members/search.pl index b53773ad007..c3d80a2e4fb 100755 --- a/members/search.pl +++ b/members/search.pl @@ -46,7 +46,6 @@ $template->param( columns => \@columns, 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') ] : [] ), diff --git a/reserve/request.pl b/reserve/request.pl index 433923980cc..8af97c234a1 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -39,7 +39,6 @@ use C4::Koha qw( getitemtypeimagelocation ); use C4::Serials qw( CountSubscriptionFromBiblionumber ); use C4::Circulation qw( GetTransfers _GetCircControlBranch GetBranchItemRule ); use Koha::DateUtils qw( dt_from_string output_pref ); -use C4::Utils::DataTables::Members; use C4::Search qw( enabled_staff_search_views ); use Koha::Biblios; @@ -51,6 +50,7 @@ use Koha::Items; use Koha::ItemTypes; use Koha::Libraries; use Koha::Patrons; +use Koha::Patron::Attribute::Types; use Koha::Clubs; use Koha::BackgroundJob::BatchCancelHold; @@ -686,6 +686,14 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) } $template->param( biblionumbers => \@biblionumbers ); +$template->param( + attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes') + ? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ] + : [] + ), +); + + # pass the userenv branch if no pickup location selected $template->param( pickup => $pickup || C4::Context->userenv->{branch} ); -- 2.25.1