From 6725b10866a5a4720669c76a4368909b2527f37b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 30 Mar 2015 12:15:42 +0200 Subject: [PATCH] Bug 13926: ake circulation.pl not using C4::Members::Search This patch uses the same method as bug 13894. Important note: This will modify the UI. The patron list will now be displayed in a table (instead of a select). Test plan: 1/ Search for a patron using the checkout tab 2/ The patron list should appear correctly Test with different type of search (returns 0, 1, 1+ results). No behavior changes should be observed. --- circ/circulation.pl | 61 ++++++++-------------- .../prog/en/modules/circ/circulation.tt | 60 ++++++++++++++++----- 2 files changed, 68 insertions(+), 53 deletions(-) diff --git a/circ/circulation.pl b/circ/circulation.pl index 22c5e24..d093c00 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -34,6 +34,7 @@ use C4::Dates qw/format_date/; use C4::Branch; # GetBranches use C4::Koha; # GetPrinter use C4::Circulation; +use C4::Utils::DataTables::Members; use C4::Members; use C4::Biblio; use C4::Search; @@ -202,29 +203,31 @@ if ( $print eq 'yes' && $borrowernumber ne '' ) { # STEP 2 : FIND BORROWER # if there is a list of find borrowers.... # -my $borrowerslist; my $message; if ($findborrower) { - my $borrowers = Search($findborrower, 'cardnumber') || []; - if (C4::Context->preference("AddPatronLists")) { - if (C4::Context->preference("AddPatronLists")=~/code/){ - my $categories = GetBorrowercategoryList; - $categories->[0]->{'first'} = 1; - $template->param(categories=>$categories); + my $borrower = C4::Members::GetMember( cardnumber => $findborrower ); + if ( $borrower ) { + $borrowernumber = $borrower->{borrowernumber}; + } else { + my $dt_params = { iDisplayLength => -1 }; + my $results = C4::Utils::DataTables::Members::search( + { + searchmember => $findborrower, + dt_params => $dt_params, + } + ); + my $borrowers = $results->{patrons}; + if ( scalar @$borrowers == 1 ) { + $borrowernumber = $borrowers->[0]->{borrowernumber}; + $query->param( 'borrowernumber', $borrowernumber ); + $query->param( 'barcode', '' ); + } elsif ( @$borrowers ) { + $template->param( borrowers => $borrowers ); + } else { + $query->param( 'findborrower', '' ); + $message = "'$findborrower'"; } } - if ( @$borrowers == 0 ) { - $query->param( 'findborrower', '' ); - $message = "'$findborrower'"; - } - elsif ( @$borrowers == 1 ) { - $borrowernumber = $borrowers->[0]->{'borrowernumber'}; - $query->param( 'borrowernumber', $borrowernumber ); - $query->param( 'barcode', '' ); - } - else { - $borrowerslist = $borrowers; - } } # get the borrower information..... @@ -420,25 +423,6 @@ if ($borrowernumber) { if ( $borrower->{'category_type'} eq 'A' ); } -my @values; -my %labels; -my $selectborrower; -if ($borrowerslist) { - foreach ( - sort {(lc $a->{'surname'} cmp lc $b->{'surname'} || lc $a->{'firstname'} cmp lc $b->{'firstname'}) - } @$borrowerslist - ) - { - push @values, $_->{'borrowernumber'}; - $labels{ $_->{'borrowernumber'} } = -"$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'} - $_->{'branchcode'}) ... $_->{'address'} "; - } - $selectborrower = { - values => \@values, - labels => \%labels, - }; -} - #title my $flags = $borrower->{'flags'}; foreach my $flag ( sort keys %$flags ) { @@ -589,7 +573,6 @@ $template->param( stickyduedate => $stickyduedate, duedatespec => $duedatespec, message => $message, - selectborrower => $selectborrower, totaldue => sprintf('%.2f', $total), inprocess => $inprocess, is_child => ($borrowernumber && $borrower->{'category_type'} eq 'C'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index f72f32e..69ce8df 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -44,7 +44,7 @@ var relatives_borrowernumbers = new Array(); var MSG_ADD_MESSAGE = _("Add a new message"); var MSG_EXPORT_SELECT_CHECKOUTS = _("You must select checkout(s) to export"); [% IF ( borrowernumber ) %]if($.cookie("holdfor") != [% borrowernumber %]){ $.cookie("holdfor",null, { path: "/", expires: 0 }); }[% ELSE %]$.cookie("holdfor",null, { path: "/", expires: 0 });[% END %] -[% UNLESS ( borrowernumber ) %][% UNLESS ( selectborrower ) %]window.onload=function(){ $('#findborrower').focus(); };[% END %][% END %] +[% UNLESS ( borrowernumber ) %][% UNLESS ( borrowers ) %]window.onload=function(){ $('#findborrower').focus(); };[% END %][% END %] // On-site checkout function toggle_onsite_checkout(){ @@ -83,6 +83,23 @@ $(document).ready(function() { $("#onsite_checkout").click(function(){ toggle_onsite_checkout(); }); + + var table = $("#table_borrowers").dataTable($.extend(true, {}, dataTablesDefaults, { + "aoColumnDefs": [ + { "aTargets": [ 0 ], "bSortable": false, "bSearchable": false }, + ], + "aaSorting": [ 2, "asc" ], + "sDom": "t", + "iDisplayLength": -1 + })); + $(table).find('tbody tr').filter(':has(:radio:checked)').end().click(function(event) { + $('#table_borrowers tbody tr').removeClass('selected'); + $(this).addClass('selected'); + if (event.target.type !== 'radio') { + $(':radio', this).attr('checked', 'true') + } + }); + }); //]]> @@ -100,7 +117,7 @@ $(document).ready(function() { Checkouts [% END %] -[% IF ( selectborrower ) %] +[% IF ( $borrowers ) %]
@@ -500,19 +517,34 @@ No patron matched [% message %] -
  1. - - -
  2. -
-

+ + + + + + + + + + + + + [% FOREACH borrower IN borrowers %] + + + + + + + + + [% END %] + +
NameCardnumberCategoryLibraryAddress
[% borrower.surname %], [% borrower.firstname %][% borrower.cardnumber %][% borrower.categorycode %][% borrower.branchcode %][% borrower.address %]
+
-[% ELSE %] +[% ELSE %] @@ -878,7 +910,7 @@ No patron matched [% message %]
-[% UNLESS ( selectborrower ) %][% IF ( borrowernumber ) %]
+[% UNLESS ( borrowers ) %][% IF ( borrowernumber ) %]
[% INCLUDE 'circ-menu.inc' %]
[% END %][% END %]
-- 2.1.0