Bugzilla – Attachment 31971 Details for
Bug 13021
DataTables server-side processing - guarantor search
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13021: guarantor search - main patch
Bug-13021-guarantor-search---main-patch.patch (text/plain), 17.19 KB, created by
Jonathan Druart
on 2014-10-02 08:27:36 UTC
(
hide
)
Description:
Bug 13021: guarantor search - main patch
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-10-02 08:27:36 UTC
Size:
17.19 KB
patch
obsolete
>From 2c56f2d306860308edce6b383acc284f73e00913 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >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). >--- > C4/Utils/DataTables/Members.pm | 2 +- > Koha/Template/Plugin/To.pm | 33 ++++++++ > acqui/add_user_search.pl | 3 + > .../en/modules/acqui/tables/members_results.tt | 2 +- > .../prog/en/modules/common/patron_search.tt | 63 +++++++++----- > .../prog/en/modules/members/memberentrygen.tt | 37 +++++++++ > .../en/modules/members/tables/guarantor_search.tt | 21 +++++ > members/guarantor_search.pl | 97 ++++++---------------- > 8 files changed, 160 insertions(+), 98 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 7b3a1ec..c9ad109 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 0000000..41adc70 >--- /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 22ca8d0..931530b 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 3668d93..56593ba 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": >- "<a style=\"cursor:pointer\" onclick=\"add_user('[% data.borrowernumber %]', '[% data.surname %]', '[% data.firstname %]');\">Add</a>" >+ "<a style=\"cursor:pointer\" onclick=\"add_user('[% data.borrowernumber %]', '[% data.surname %]', '[% data.firstname %]');\">Select</a>" > }[% UNLESS loop.last %],[% END %] > [% END %] > ] >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 2a7233f..3e93899 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 %] > //]]> > </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> </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> </th> >+ [% END %] >+ [% END %] > </tr> > </thead> > <tbody></tbody> >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 56cc570..028bc48 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >@@ -103,6 +103,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"); >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 0000000..0ee2af5 >--- /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": >+ "<a style='cursor:pointer' onclick='select_user(\"[% data.borrowernumber %]\", [% To.json(json) | html %] );'>Select</a>" >+ }[% UNLESS loop.last %],[% END %] >+ [% END %] >+ ] >+} >diff --git a/members/guarantor_search.pl b/members/guarantor_search.pl >index e5b39df..3c5e786 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 <http://www.gnu.org/licenses>. > > use Modern::Perl; > > use CGI; >- > 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.1.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13021
:
31970
|
31971
|
31972
|
32231
|
32232
|
32233
|
35296
|
35297
|
35321
|
35322
|
35323
|
35324
|
35371
|
35627
|
35628
|
35629
|
35630
|
35631
|
35632