From 89a54da63ea8da4951d9f3f02a10ca50e96c399f 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Séverine Queune Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- .../en/includes/js-patron-format-address.inc | 110 +++- .../prog/en/includes/patron-search.inc | 500 ++++++++++++++++++ .../prog/en/modules/members/search.tt | 392 +------------- .../prog/en/modules/reserve/request.tt | 125 ++--- .../modules/reserve/tables/members_results.tt | 32 -- members/search.pl | 1 - reserve/request.pl | 10 +- 7 files changed, 655 insertions(+), 515 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 935a1f36c4..60923ec524 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 0000000000..07ec9cd093 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -0,0 +1,500 @@ +[% 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 7422381373..620a9d73db 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,398 +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 6273c69c66..1e48c1b19a 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 %]
@@ -1189,7 +1172,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 ); @@ -1571,79 +1553,32 @@ } return false; }); + }); + - [% FOREACH biblionumber IN biblionumbers %] - [% SET url_biblio_params = url_biblio_params _ "&biblionumber=" _ biblionumber | uri %] - [% 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 | $raw %]" - 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 | $raw %]" - $(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 + %] +