From 88816eebd9a7b3edabdc894a2d7722f5ddec0a38 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 2 Oct 2014 09:42:11 +0200 Subject: [PATCH] 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 Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Utils/DataTables/Members.pm | 2 +- Koha/Template/Plugin/To.pm | 33 +++++++ acqui/add_user_search.pl | 3 + .../modules/acqui/tables/members_results.tt | 2 +- .../en/modules/admin/aqbudget_user_search.tt | 6 +- .../prog/en/modules/admin/aqbudgets.tt | 8 +- .../prog/en/modules/common/patron_search.tt | 63 +++++++----- .../prog/en/modules/members/memberentrygen.tt | 37 +++++++ .../members/tables/guarantor_search.tt | 21 ++++ members/guarantor_search.pl | 97 +++++-------------- 10 files changed, 167 insertions(+), 105 deletions(-) create mode 100644 Koha/Template/Plugin/To.pm create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm index 7b3a1eca5d..c9ad109b2c 100644 --- a/C4/Utils/DataTables/Members.pm +++ b/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 diff --git a/Koha/Template/Plugin/To.pm b/Koha/Template/Plugin/To.pm new file mode 100644 index 0000000000..41adc70126 --- /dev/null +++ b/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; diff --git a/acqui/add_user_search.pl b/acqui/add_user_search.pl index 6b6d18c3c6..e86b0e498f 100755 --- a/acqui/add_user_search.pl +++ b/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 ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt index 074865fa85..b66af4d266 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt +++ b/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": - "Add" + "Select" }[% UNLESS loop.last %],[% END %] [% END %] ] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_user_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_user_search.tt index 316a00ab38..7d513d66c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_user_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_user_search.tt @@ -22,12 +22,12 @@ //' - + firstname + ' ' + surname + ''; + + borrowername + ''; $('#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 = '
  • ' + '' + firstname + ' ' + surname + + borrowernumber + '">' + borrowername + ' [Remove]
  • '; $(li).insertBefore("li#add_user_button"); 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 2a7233fc02..3e938990ea 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 @@ -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 %] //]]> @@ -135,11 +146,17 @@ function filter() { - - - - - + [% FOR column IN columns %] + [% SWITCH column %] + [% CASE 'cardnumber' %] + [% CASE 'dateofbirth' %] + [% CASE 'address' %] + [% CASE 'name' %] + [% CASE 'branch' %] + [% CASE 'category' %] + [% CASE 'action' %] + [% END %] + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index b10ac47586..8412c90a65 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/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('' + id + ''); + + $(form.contactname) + .val(borrower.surname) + .before('' + borrower.surname + '').get(0).type = 'hidden'; + $(form.contactfirstname) + .val(borrower.firstname) + .before('' + borrower.firstname + '').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"); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/guarantor_search.tt new file mode 100644 index 0000000000..0a375f8a42 --- /dev/null +++ b/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": + "Select" + }[% UNLESS loop.last %],[% END %] + [% END %] + ] +} diff --git a/members/guarantor_search.pl b/members/guarantor_search.pl index a9fe9dd95d..49bd57dfce 100755 --- a/members/guarantor_search.pl +++ b/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 . 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 ); -- 2.39.5
    CardNameLibraryCategory CardDate of birthAddressNameLibraryCategory