From ababed96a0f3f56f04f6cc24d4253f0bc74554e1 Mon Sep 17 00:00:00 2001 From: Michael Hafen Date: Tue, 20 Jul 2021 12:12:42 -0600 Subject: [PATCH] Bug 28726 - Add sort1 and sort2 to patron card creator - patron search. Also adds a select all / clear all and checkboxes. Signed-off-by: The Minh Luong --- C4/Utils/DataTables/Members.pm | 10 ++++ .../prog/en/modules/common/patron_search.tt | 52 +++++++++++++++++++ .../patroncards/tables/members_results.tt | 2 + patroncards/add_user_search.pl | 8 ++- svc/members/search | 4 ++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm index 15f04eb972..f81eb7430d 100644 --- a/C4/Utils/DataTables/Members.pm +++ b/C4/Utils/DataTables/Members.pm @@ -11,6 +11,8 @@ sub search { my $firstletter = $params->{firstletter}; my $categorycode = $params->{categorycode}; my $branchcode = $params->{branchcode}; + my $sort1 = $params->{sort1}; + my $sort2 = $params->{sort2}; my $searchtype = $params->{searchtype} || 'contain'; my $searchfieldstype = $params->{searchfieldstype} || 'standard'; my $has_permission = $params->{has_permission}; @@ -111,6 +113,14 @@ sub search { push @where_strs, "borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")"; push @where_args, @restricted_branchcodes; } + if(defined $sort1 and $sort1 ne '') { + push @where_strs, "borrowers.sort1 = ?"; + push @where_args, $sort1; + } + if(defined $sort2 and $sort2 ne '') { + push @where_strs, "borrowers.sort2 = ?"; + push @where_args, $sort2; + } my $searchfields = { standard => C4::Context->preference('DefaultPatronSearchFields') || 'surname,firstname,othernames,cardnumber,userid', diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt index 9009d7a187..d6a128f6c3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt @@ -42,6 +42,24 @@ [% END %] +
  • + + +
  • +
  • + + +
  • @@ -69,11 +87,21 @@
    + [% FOR column IN columns %] [% SWITCH column %] + [% CASE 'select' %] [% CASE 'cardnumber' %] [% CASE 'dateofbirth' %] [% CASE 'address' %] @@ -150,6 +178,12 @@ },{ 'name': 'branchcode', 'value': $("#branchcode_filter").val() + },{ + 'name': 'sort1', + 'value': $("#sort1_filter").val() + },{ + 'name': 'sort2', + 'value': $("#sort2_filter").val() },{ 'name': 'name_sorton', 'value': 'borrowers.surname borrowers.firstname' @@ -204,6 +238,8 @@ [% FOR column IN columns %] [% IF column == 'action' %] { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' } + [% ELSIF column == 'select' %] + { 'mDataProp': 'dt_select', 'bSortable': false, 'sClass': 'selections' } [% ELSIF column == 'address' %] { 'mDataProp': 'dt_address', 'bSortable': false } [% ELSE %] @@ -225,6 +261,22 @@ e.preventDefault(); filterByFirstLetterSurname($(this).text()); }); + $("#select_all").on("click",function(e){ + e.preventDefault(); + $("#searchresults .selection").prop("checked", true).change(); + }); + $("#clear_all").on("click",function(e){ + e.preventDefault(); + $("#searchresults .selection").prop("checked", false).change(); + }); + $("#add-selected").on('click', function(e){ + $("#searchresults .selection:checked").each(function(){ + var borrowernumber = $(this).data("borrowernumber"); + var firstname = $(this).data("firstname"); + var surname = $(this).data("surname"); + add_user( borrowernumber, firstname + " " + surname ); + }); + }); $("body").on("click",".add_user",function(e){ e.preventDefault(); var borrowernumber = $(this).data("borrowernumber"); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/tables/members_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/tables/members_results.tt index 9660e3e56e..ef7264addf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/tables/members_results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/tables/members_results.tt @@ -6,6 +6,8 @@ "aaData": [ [% FOREACH data IN aaData %] { + "dt_select": + "", "dt_cardnumber": "[% data.cardnumber | html %]", "dt_name": diff --git a/patroncards/add_user_search.pl b/patroncards/add_user_search.pl index 04bc0eb5b3..e40c2852a2 100755 --- a/patroncards/add_user_search.pl +++ b/patroncards/add_user_search.pl @@ -20,6 +20,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); +use List::MoreUtils qw(uniq); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::Members; @@ -44,13 +45,18 @@ my $op = $input->param('op') || ''; my $referer = $input->referer(); my $patron_categories = Koha::Patron::Categories->search_with_library_limits; +my $sort_filter = { ( C4::Context->only_my_library ? (branchcode => C4::Context->userenv->{branch}) : () ) }; +my @sort1 = sort {$a cmp $b} uniq( Koha::Patrons->search($sort_filter)->get_column('sort1') ); +my @sort2 = sort {$a cmp $b} uniq( Koha::Patrons->search($sort_filter)->get_column('sort2') ); $template->param( view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", - columns => ['cardnumber', 'name', 'category', 'branch', 'dateexpiry', 'borrowernotes', 'action'], + columns => ['select', 'cardnumber', 'name', 'category', 'branch', 'dateexpiry', 'borrowernotes', 'action'], json_template => 'patroncards/tables/members_results.tt', selection_type => 'add', alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ), categories => $patron_categories, + sort1 => \@sort1, + sort2 => \@sort2, aaSorting => 1, ); output_html_with_http_headers( $input, $cookie, $template->output ); diff --git a/svc/members/search b/svc/members/search index 7cad0e8ab0..005a788f64 100755 --- a/svc/members/search +++ b/svc/members/search @@ -42,6 +42,8 @@ my $searchmember = $input->param('searchmember'); my $firstletter = $input->param('firstletter'); my $categorycode = $input->param('categorycode'); my $branchcode = $input->param('branchcode'); +my $sort1 = $input->param('sort1'); +my $sort2 = $input->param('sort2'); my $searchtype = $input->param('searchtype'); my $searchfieldstype = $input->param('searchfieldstype') || 'standard'; my $has_permission = $input->param('has_permission'); @@ -83,6 +85,8 @@ $results = C4::Utils::DataTables::Members::search( firstletter => $firstletter, categorycode => $categorycode, branchcode => $branchcode, + sort1 => $sort1, + sort2 => $sort2, searchtype => $searchtype, searchfieldstype => $searchfieldstype, dt_params => \%dt_params, -- 2.25.1
     CardDate of birthAddress