Browse Source

Bug 13021: guarantor search - main patch

This patch is the main patch.
The "common" template is improved to allow different type of picking:
"add" or "select".
The first one appends a patron to a list, the second one selects the
patron and close the result search window.

The members/guarantor_search.pl has completly changed but is quite the
same file as acqui/add_user_search.pl. Both should exist: they don't
belong to the same module (acqui vs members), the picking type is
different (add vs select) and the columns are not the same.

The changes in the common template are very powerful, it's now possible
to list the column we want! This will be very useful for further
reusability.

Before this patch, all patrons mathing the pattern were return. Now only
the first 20 are (depends on the DataTables selected value).

For QA: This patch introduces a new template plugin "To", for now it
permits to convert a perl structure to json. In the idea, it could
permit to convert foo to bar too.

Test plan:
1/ Verify there is no regression in the guarantor search. When the
selection has been done, all data from the guarantor should fill the
form in the "main address" section.
Note that the request is done when the search input in not empty and the
user stop to write for 1 sec.
2/ Verify there is no regression on the 2 other pages where this patron
search is used: link a patron to an order and to a basket (in the
acquisition module).

Signed-off-by: Morag Hills <the.invinnysible.one@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
3.20.x
Jonathan Druart 10 years ago
committed by Tomas Cohen Arazi
parent
commit
88816eebd9
  1. 2
      C4/Utils/DataTables/Members.pm
  2. 33
      Koha/Template/Plugin/To.pm
  3. 3
      acqui/add_user_search.pl
  4. 2
      koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt
  5. 6
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_user_search.tt
  6. 8
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt
  7. 63
      koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt
  8. 37
      koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
  9. 21
      koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt
  10. 97
      members/guarantor_search.pl

2
C4/Utils/DataTables/Members.pm

@ -37,7 +37,7 @@ sub search {
borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode,
borrowers.country, cardnumber, borrowers.dateexpiry,
borrowers.borrowernotes, borrowers.branchcode, borrowers.email,
borrowers.userid,
borrowers.userid, borrowers.dateofbirth,
categories.description AS category_description, categories.category_type,
branches.branchname";
my $from = "FROM borrowers

33
Koha/Template/Plugin/To.pm

@ -0,0 +1,33 @@
package Koha::Template::Plugin::To;
# This file is part of Koha.
#
# Copyright BibLibre 2014
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use base qw( Template::Plugin );
use JSON qw( to_json );
sub json {
my ( $self, $value ) = @_;
my $json = JSON->new->allow_nonref(1);
return $json->encode( $value );
}
1;

3
acqui/add_user_search.pl

@ -52,5 +52,8 @@ my $search_patrons_with_acq_perm_only =
$template->param(
patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
columns => ['cardnumber', 'name', 'branch', 'category', 'action'],
json_template => 'acqui/tables/members_results.tt',
selection_type => 'add',
);
output_html_with_http_headers( $input, $cookie, $template->output );

2
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt

@ -14,7 +14,7 @@
"dt_category":
"[% data.category_description |html %] ([% data.category_type |html %])",
"dt_action":
"<a style='cursor:pointer' onclick='add_user(\"[% data.borrowernumber %]\", \"[% data.firstname %] [% data.surname %]\");'>Add</a>"
"<a style='cursor:pointer' onclick='add_user(\"[% data.borrowernumber %]\", \"[% data.firstname %] [% data.surname %]\");'>Select</a>"
}[% UNLESS loop.last %],[% END %]
[% END %]
]

6
koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_user_search.tt

@ -22,12 +22,12 @@
//<![CDATA[
// modify parent window owner element
function add_user(borrowernumber, surname, firstname) {
function add_user(borrowernumber, borrowername) {
[% IF (type == 'owner') %]
top.opener.edit_owner(borrowernumber, surname, firstname);
top.opener.edit_owner(borrowernumber, borrowername);
window.close();
[% ELSE %]
var ret = top.opener.add_user(borrowernumber, surname, firstname);
var ret = top.opener.add_user(borrowernumber, borrowername);
if (ret != 0) {
alert(_("This user is already in the list."));
}

8
koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt

@ -31,13 +31,13 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget")
);
}
function edit_owner(borrowernumber, surname, firstname) {
function edit_owner(borrowernumber, borrowername) {
$('#budget_owner_name').empty();
$('#budget_owner_id').val('');
if (borrowernumber) {
var ownerlink = '<a href="/cgi-bin/koha/members/moremember.pl'
+ '?borrowernumber=' + borrowernumber + '">'
+ firstname + ' ' + surname + '</a>';
+ borrowername + '</a>';
$('#budget_owner_name').html(ownerlink);
$('#budget_owner_id').val(borrowernumber);
}
@ -47,12 +47,12 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget")
edit_owner(0);
}
function add_user(borrowernumber, surname, firstname) {
function add_user(borrowernumber, borrowername) {
var ids = $("#budget_users_id").val().split(':');
if(borrowernumber && ids.indexOf(borrowernumber) == -1) {
var li = '<li id="user_' + borrowernumber + '">'
+ '<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber='
+ borrowernumber + '">' + firstname + ' ' + surname
+ borrowernumber + '">' + borrowername
+ '</a> [<a style="cursor:pointer"'
+ 'onclick="del_user(' + borrowernumber +')">Remove</a>]</li>';
$(li).insertBefore("li#add_user_button");

63
koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt

@ -35,7 +35,7 @@ $(document).ready(function(){
},
{
'name': 'template_path',
'value': 'acqui/tables/members_results.tt',
'value': '[% json_template %]',
}
[% IF patrons_with_acq_perm_only %]
,{
@ -55,11 +55,14 @@ $(document).ready(function(){
});
},
'aoColumns':[
{ 'mDataProp': 'dt_cardnumber' },
{ 'mDataProp': 'dt_name' },
{ 'mDataProp': 'dt_branch' },
{ 'mDataProp': 'dt_category' },
{ 'mDataProp': 'dt_action', 'bSortable': false }
[% FOR column IN columns %]
[% IF column == 'action' %]
{ 'mDataProp': 'dt_action', 'bSortable': false }
[% ELSE %]
{ 'mDataProp': 'dt_[% column %]' }
[% END %]
[% UNLESS loop.last %],[% END %]
[% END %]
],
'bAutoWidth': false,
[% IF patrons_with_acq_perm_only %]
@ -97,19 +100,27 @@ function filter() {
}
// modify parent window owner element
function add_user(borrowernumber, borrowername) {
var p = window.opener;
$("#info").hide();
$("#error").hide();
if ( p.add_user(borrowernumber, borrowername) < 0 ) {
$("#error").html(_("Borrower '%s' is already in the list.").format(borrowername));
$("#error").show();
} else {
$("#info").html(_("Borrower '%s' added.").format(borrowername));
$("#info").show();
[% IF selection_type == 'add' %]
[%# Note that add_user could sent data instead of borrowername too %]
function add_user(borrowernumber, borrowername) {
var p = window.opener;
$("#info").hide();
$("#error").hide();
if ( p.add_user(borrowernumber, borrowername) < 0 ) {
$("#error").html(_("Borrower '%s' is already in the list.").format(borrowername));
$("#error").show();
} else {
$("#info").html(_("Borrower '%s' added.").format(borrowername));
$("#info").show();
}
}
}
[% ELSIF selection_type == 'select' %]
function select_user(borrowernumber, data) {
var p = window.opener;
p.select_user(borrowernumber, data);
window.close();
}
[% END %]
//]]>
</script>
@ -135,11 +146,17 @@ function filter() {
<table id="memberresultst">
<thead>
<tr>
<th>Card</th>
<th>Name</th>
<th>Library</th>
<th>Category</th>
<th>&nbsp;</th>
[% FOR column IN columns %]
[% SWITCH column %]
[% CASE 'cardnumber' %]<th>Card</th>
[% CASE 'dateofbirth' %]<th>Date of birth</th>
[% CASE 'address' %]<th>Address</th>
[% CASE 'name' %]<th>Name</th>
[% CASE 'branch' %]<th>Library</th>
[% CASE 'category' %]<th>Category</th>
[% CASE 'action' %]<th>&nbsp;</th>
[% END %]
[% END %]
</tr>
</thead>
<tbody></tbody>

37
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt

@ -99,6 +99,43 @@
$(mytables).find(" li[data-category_code='']").show();
}
function select_user(borrowernumber, borrower) {
var form = $('#entryform').get(0);
if (form.guarantorid.value) {
$("#contact-details").find('a').remove();
$("#contactname, #contactfirstname").parent().find('span').remove();
}
var id = borrower.borrowernumber;
form.guarantorid.value = id;
$('#contact-details')
.show()
.find('span')
.after('<a target="blank" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=' + id + '">' + id + '</a>');
$(form.contactname)
.val(borrower.surname)
.before('<span>' + borrower.surname + '</span>').get(0).type = 'hidden';
$(form.contactfirstname)
.val(borrower.firstname)
.before('<span>' + borrower.firstname + '</span>').get(0).type = 'hidden';
form.streetnumber.value = borrower.streetnumber;
form.address.value = borrower.address;
form.address2.value = borrower.address2;
form.city.value = borrower.city;
form.state.value = borrower.state;
form.zipcode.value = borrower.zipcode;
form.country.value = borrower.country;
form.branchcode.value = borrower.branchcode;
form.guarantorsearch.value = 'Change';
return 0;
}
var MSG_SEPARATOR = _("Separator must be / in field %s");
var MSG_INCORRECT_DAY = _("Invalid day entered in field %s");
var MSG_INCORRECT_MONTH = _("Invalid month entered in field %s");

21
koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt

@ -0,0 +1,21 @@
[% USE To %]
[% USE KohaDates %]
{
"sEcho": [% sEcho %],
"iTotalRecords": [% iTotalRecords %],
"iTotalDisplayRecords": [% iTotalDisplayRecords %],
"aaData": [
[% FOREACH data IN aaData %]
{
"dt_cardnumber":
"[% data.cardnumber %]",
"dt_dateofbirth":
"[% data.dateofbirth | $KohaDates %]",
"dt_address":
"[% data.streetnumber %] [% data.address | html %] [% data.address2 | html %] [% data.city | html %] [% data.state | html %] [% data.zipcode | html %] [% data.country | html %] [% data.branchcode %]",
"dt_action":
"<a style='cursor:pointer' onclick='select_user(\"[% data.borrowernumber %]\", [% To.json(data) | html %] );'>Select</a>"
}[% UNLESS loop.last %],[% END %]
[% END %]
]
}

97
members/guarantor_search.pl

@ -1,100 +1,51 @@
#!/usr/bin/perl
# script to find a guarantor
# Copyright 2006 OUEST PROVENCE
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# Copyright 2014 BibLibre
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
use C4::Output;
use C4::Dates qw/format_date/;
use C4::Members;
my $input = new CGI;
my ( $template, $loggedinuser, $cookie );
( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "members/guarantor_search.tt",
my $dbh = C4::Context->dbh;
my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user(
{ template_name => "common/patron_search.tt",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => { borrowers => 1 },
debug => 1,
}
);
my $member = $input->param('member') // '';
my $orderby = $input->param('orderby');
my $category_type = $input->param('category_type');
$orderby = "surname,firstname" unless $orderby;
$member =~ s/,//g; #remove any commas from search string
$member =~ s/\*/%/g;
$template->param( results => $member );
my $q = $input->param('q') || '';
my $op = $input->param('op') || '';
my $search_category = 'A';
if ( $category_type eq 'P' ) {
$search_category = 'I';
}
my ( $count, $results );
my @resultsdata;
if ( $member ne '' ) {
$results =
Search( { '' => $member, category_type => $search_category }, $orderby );
$count = $results ? @$results : 0;
for ( my $i = 0 ; $i < $count ; $i++ ) {
my %row = (
count => $i + 1,
borrowernumber => $results->[$i]{'borrowernumber'},
cardnumber => $results->[$i]{'cardnumber'},
surname => $results->[$i]{'surname'},
firstname => $results->[$i]{'firstname'},
categorycode => $results->[$i]{'categorycode'},
streetnumber => $results->[$i]{'streetnumber'},
address => $results->[$i]{'address'},
address2 => $results->[$i]{'address2'},
city => $results->[$i]{'city'},
state => $results->[$i]{'state'},
zipcode => $results->[$i]{'zipcode'},
country => $results->[$i]{'country'},
branchcode => $results->[$i]{'branchcode'},
dateofbirth => format_date( $results->[$i]{'dateofbirth'} ),
borrowernotes => $results->[$i]{'borrowernotes'}
);
push( @resultsdata, \%row );
}
}
my $referer = $input->referer();
$template->param(
member => $member,
numresults => $count,
category_type => $category_type,
resultsloop => \@resultsdata
view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
columns => ['cardnumber', 'dateofbirth', 'address', 'action' ],
json_template => 'members/tables/guarantor_search.tt',
selection_type => 'select',
);
output_html_with_http_headers $input, $cookie, $template->output;
output_html_with_http_headers( $input, $cookie, $template->output );

Loading…
Cancel
Save