Bugzilla – Attachment 30025 Details for
Bug 12648
Link patrons to an order
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12648: Refactoring to prepare user search for reuse
Bug-12648-Refactoring-to-prepare-user-search-for-r.patch (text/plain), 16.48 KB, created by
Jonathan Druart
on 2014-07-24 11:53:12 UTC
(
hide
)
Description:
Bug 12648: Refactoring to prepare user search for reuse
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-07-24 11:53:12 UTC
Size:
16.48 KB
patch
obsolete
>From 7577701e0f6c5ec0d6fc7f8b34c33f316197dc61 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Thu, 24 Jul 2014 13:33:06 +0200 >Subject: [PATCH] Bug 12648: Refactoring to prepare user search for reuse > >A previous enhancement allows to link basket with patrons. >Next patches will use the same way to link order with patrons. > >In order to avoir c/p of code, this patch refactores this part of code. > >Test plan: >1/ Verify there is no regression on adding/modifying users to a basket. >(acqui/basket.pl?basketno=XXX, "Managed by", "Add user"). >2/ Note that you get a friendly message if the user is already present in the >list and when the user has correctly been added to the list. >3/ Note that the list uses the member search service (ie. DataTable + >serverside processing). >--- > C4/Utils/DataTables/Members.pm | 6 +- > .../{aqbasketuser_search.pl => add_user_search.pl} | 58 ++++++++----- > .../prog/en/modules/acqui/add_user_search.tt | 95 ++++++++++++++++++++++ > .../prog/en/modules/acqui/aqbasketuser_search.tt | 79 ------------------ > .../intranet-tmpl/prog/en/modules/acqui/basket.tt | 32 ++++---- > svc/members/search | 2 +- > 6 files changed, 155 insertions(+), 117 deletions(-) > rename acqui/{aqbasketuser_search.pl => add_user_search.pl} (50%) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt > delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/aqbasketuser_search.tt > >diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm >index c52007a..64b8b60 100644 >--- a/C4/Utils/DataTables/Members.pm >+++ b/C4/Utils/DataTables/Members.pm >@@ -13,9 +13,13 @@ sub search { > my $categorycode = $params->{categorycode}; > my $branchcode = $params->{branchcode}; > my $searchtype = $params->{searchtype}; >- my $searchfieldstype = $params->{searchfieldstype}; >+ my $searchfieldstype = $params->{searchfieldstype} || 'standard'; > my $dt_params = $params->{dt_params}; > >+ unless ( $searchmember ) { >+ $searchmember = $dt_params->{sSearch}; >+ } >+ > my ($iTotalRecords, $iTotalDisplayRecords); > > # If branches are independant and user is not superlibrarian >diff --git a/acqui/aqbasketuser_search.pl b/acqui/add_user_search.pl >similarity index 50% >rename from acqui/aqbasketuser_search.pl >rename to acqui/add_user_search.pl >index 6c020ca..ff7a579 100755 >--- a/acqui/aqbasketuser_search.pl >+++ b/acqui/add_user_search.pl >@@ -1,23 +1,21 @@ > #!/usr/bin/perl > >-# script to find a basket user >- >-# Copyright 2012 BibLibre SARL >-# > # 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; > >@@ -31,7 +29,7 @@ my $input = new CGI; > my $dbh = C4::Context->dbh; > > my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( >- { template_name => "acqui/aqbasketuser_search.tt", >+ { template_name => "acqui/add_user_search.tt", > query => $input, > type => "intranet", > authnotrequired => 0, >@@ -42,18 +40,35 @@ my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( > my $q = $input->param('q') || ''; > my $op = $input->param('op') || ''; > >+my $referer = $input->referer(); >+ >+# If this script is called by acqui/basket.pl >+# the patrons to return should be superlibrarian or have the order_manage >+# acquisition flag. >+my $search_patrons_with_acq_perm_only = >+ ( $referer =~ m|acqui/basket.pl| ) >+ ? 1 : 0; >+ > if( $op eq "do_search" ) { > my $results = C4::Members::Search( $q, "surname"); > > my @users_loop; > my $nresults = 0; > foreach my $res (@$results) { >- my $perms = haspermission( $res->{userid} ); >- my $subperms = get_user_subpermissions( $res->{userid} ); >+ my $should_be_returned = 1; >+ >+ if ( $search_patrons_with_acq_perm_only ) { >+ $should_be_returned = 0; >+ my $perms = haspermission( $res->{userid} ); >+ my $subperms = get_user_subpermissions( $res->{userid} ); > >- if( $perms->{superlibrarian} == 1 >- || $perms->{acquisition} == 1 >- || $subperms->{acquisition}->{'order_manage'} ) { >+ if( $perms->{superlibrarian} == 1 >+ || $perms->{acquisition} == 1 >+ || $subperms->{acquisition}->{'order_manage'} ) { >+ $should_be_returned = 1; >+ } >+ } >+ if ( $should_be_returned ) { > my %row = ( > borrowernumber => $res->{borrowernumber}, > cardnumber => $res->{cardnumber}, >@@ -74,4 +89,7 @@ if( $op eq "do_search" ) { > ); > } > >+$template->param( >+ patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only, >+); > output_html_with_http_headers( $input, $cookie, $template->output ); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt >new file mode 100644 >index 0000000..02c8035 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt >@@ -0,0 +1,95 @@ >+[% USE Koha %] >+[% INCLUDE 'doc-head-open.inc' %] >+<title>Koha › Patron search</title> >+[% INCLUDE 'doc-head-close.inc' %] >+<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" /> >+[% INCLUDE 'datatables.inc' %] >+ >+<script type="text/javascript"> >+//<![CDATA[ >+ >+$(document).ready(function(){ >+ $("#info").hide(); >+ $("#error").hide(); >+ // Apply DataTables on the results table >+ dtMemberResults = $("#memberresultst").dataTable($.extend(true, {}, dataTablesDefaults, { >+ 'bServerSide': true, >+ 'sAjaxSource': "/cgi-bin/koha/svc/members/search", >+ 'fnServerData': function(sSource, aoData, fnCallback) { >+ aoData.push({ >+ 'name': 'template_path', >+ 'value': 'acqui/tables/members_results.tt', >+ }); >+ $.ajax({ >+ 'dataType': 'json', >+ 'type': 'POST', >+ 'url': sSource, >+ 'data': aoData, >+ 'success': function(json){ >+ fnCallback(json); >+ } >+ }); >+ }, >+ 'aoColumns':[ >+ { 'mDataProp': 'dt_cardnumber' }, >+ { 'mDataProp': 'dt_name' }, >+ { 'mDataProp': 'dt_branch' }, >+ { 'mDataProp': 'dt_category' }, >+ { 'mDataProp': 'dt_action', 'bSortable': false } >+ ], >+ 'bAutoWidth': false, >+ 'sPaginationType': 'full_numbers', >+ "iDisplayLength": [% Koha.Preference('PatronsPerPage') %], >+ "bProcessing": true, >+ })); >+ dtMemberResults.fnAddFilters("filter", 750); >+}); >+ >+ // 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(); >+ >+ } >+ } >+//]]> >+</script> >+ >+</head> >+<body> >+<div id="patron_search" class="yui-t7"> >+ <div id="bd"> >+ <div class="yui-g"> >+ >+ <h3>Search for patron</h3> >+ [% IF patrons_with_acq_perm_only %] >+ <div class="hint">Only staff with superlibrarian or acquisitions permissions (or order_manage permission if granular permissions are enabled) are returned in the search results</div> >+ [% END %] >+ >+ <div id="info" class="dialog message"></div> >+ <div id="error" class="dialog alert"></div> >+ >+ <table id="memberresultst"> >+ <thead> >+ <tr> >+ <th>Card</th> >+ <th>Name</th> >+ <th>Library</th> >+ <th>Category</th> >+ <th> </th> >+ </tr> >+ </thead> >+ <tbody></tbody> >+ </table> >+ >+<div id="closewindow"><a href="#" class="close">Close</a></div> >+</div> >+</div> >+[% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/aqbasketuser_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/aqbasketuser_search.tt >deleted file mode 100644 >index 91ca764..0000000 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/aqbasketuser_search.tt >+++ /dev/null >@@ -1,79 +0,0 @@ >-[% INCLUDE 'doc-head-open.inc' %] >-<title>Koha › Basket User Search</title> >-[% INCLUDE 'doc-head-close.inc' %] >- >-<style type="text/css"> >- #custom-doc { >- width:44.46em; >- *width:43.39em; >- min-width:578px; >- margin:auto; >- text-align:left; >- } >-</style> >- >-<script type="text/javascript"> >-//<![CDATA[ >- // modify parent window owner element >- function add_user(borrowernumber, borrowername) { >- var p = window.opener; >- if(p.add_basket_user(borrowernumber, borrowername) < 0) { >- alert(_("Borrower '%s' is already in the list.").format(borrowername)); >- } >- } >-//]]> >-</script> >- >-</head> >-<body> >-<div id="custom-doc" class="yui-t7"> >- <div id="bd"> >- <div class="yui-g"> >- >- <h3>Search for Basket User</h3> >- <form action="/cgi-bin/koha/acqui/aqbasketuser_search.pl" method="post"> >- <fieldset> >- <input type="hidden" name="op" id="op" value="do_search" /> >- <input type="text" name="q" id="q" value="[% q %]" class="focus" /> >- <input type="submit" class="button" value="Search" /> >- </fieldset> >- <div class="hint">Only staff with superlibrarian or acquisitions permissions (or order_manage permission if granular permissions are enabled) are returned in the search results</div> >- </form> >- >-[% IF (q) %] >- <p>Searched for <span class="ex">[% q %]</span>, [% nresults %] patron(s) found.</p> >-[% END %] >-[% IF ( users_loop ) %] >- <table> >- <thead> >- <tr> >- <th>Cardnumber</th> >- <th>Name</th> >- <th>Branch</th> >- <th>Categorycode</th> >- <th>Select?</th> >- </tr> >- </thead> >- <tbody> >- [% FOREACH user IN users_loop %] >- [% IF ( user.toggle ) %] >- <tr> >- [% ELSE %] >- <tr class="highlight"> >- [% END %] >- <td>[% user.cardnumber %]</td> >- <td>[% user.surname %], [% user.firstname %]</td> >- <td>[% user.branchcode %]</td> >- <td>[% user.categorycode %]</td> >- <td> >- <a style="cursor:pointer" onclick="add_user('[% user.borrowernumber %]', '[% user.firstname %] [% user.surname %]');">Add</a> >- </td> >- </tr> >- [% END %] >- </table> >-[% END %] >- >-<div id="closewindow"><a href="#" class="close">Close</a></div> >-</div> >-</div> >-[% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >index 37ac2d2..29432bc 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt >@@ -118,16 +118,16 @@ > }); > }); > >- function basketUserSearchPopup(f) { >+ function UserSearchPopup(f) { > window.open( >- "/cgi-bin/koha/acqui/aqbasketuser_search.pl", >- 'BasketUserSearchPopup', >+ "/cgi-bin/koha/acqui/add_user_search.pl", >+ 'UserSearchPopup', > 'width=740,height=450,toolbar=no,' > ); > } > >- function add_basket_user(borrowernumber, borrowername) { >- var ids = $("#basketusers_ids").val(); >+ function add_user(borrowernumber, borrowername) { >+ var ids = $("#users_ids").val(); > if(ids.length > 0) { > ids = ids.split(':'); > } else { >@@ -135,21 +135,21 @@ > } > if (ids.indexOf(borrowernumber) < 0) { > ids.push(borrowernumber); >- $("#basketusers_ids").val(ids.join(':')); >+ $("#users_ids").val(ids.join(':')); > var li = '<li id="user_'+borrowernumber+'">'+borrowername >- + ' [<a style="cursor:pointer" onclick="del_basket_user('+borrowernumber+');">' >+ + ' [<a style="cursor:pointer" onclick="del_user('+borrowernumber+');">' > + _("Delete user") + '</a>]</li>'; >- $("#basketusers_names").append(li); >+ $("#users_names").append(li); > return 0; > } > return -1; > } > >- function del_basket_user(borrowernumber) { >+ function del_user(borrowernumber) { > $("#user_"+borrowernumber).remove(); >- var ids = $("#basketusers_ids").val().split(':'); >+ var ids = $("#users_ids").val().split(':'); > ids.splice(ids.indexOf(borrowernumber.toString()), 1); >- $("#basketusers_ids").val(ids.join(':')); >+ $("#users_ids").val(ids.join(':')); > } > //]]> > </script> >@@ -290,18 +290,18 @@ > <form action="" method="post"> > <span class="label">Managed by:</span> > <div style="float:left"> >- <ul id="basketusers_names" style="padding-left:0"> >- [% FOREACH user IN basketusers %] >+ <ul id="users_names" style="padding-left:0"> >+ [% FOREACH user IN users %] > <li id="user_[% user.borrowernumber %]"> > [% user.firstname %] [% user.surname %] >- [<a onclick="del_basket_user([% user.borrowernumber %]);" style="cursor:pointer">Delete user</a>] >+ [<a onclick="del_user([% user.borrowernumber %]);" style="cursor:pointer">Delete user</a>] > </li> > [% END %] > </ul> > <input type="hidden" id="basketno" name="basketno" value="[% basketno %]" /> >- <input type="hidden" id="basketusers_ids" name="basketusers_ids" value="[% basketusers_ids %]" /> >+ <input type="hidden" id="users_ids" name="users_ids" value="[% users_ids %]" /> > <input type="hidden" id="op" name="op" value="mod_users" /> >- <input type="button" id="add_user" onclick="basketUserSearchPopup();" value="Add user" /> >+ <input type="button" id="add_user" onclick="UserSearchPopup();" value="Add user" /> > <input type="submit" value="Save changes" /> > </div> > </form> >diff --git a/svc/members/search b/svc/members/search >index 1b3a02a..309c2ce 100755 >--- a/svc/members/search >+++ b/svc/members/search >@@ -43,7 +43,7 @@ my $firstletter = $input->param('firstletter'); > my $categorycode = $input->param('categorycode'); > my $branchcode = $input->param('branchcode'); > my $searchtype = $input->param('searchtype'); >-my $searchfieldstype = $input->param('searchfieldstype'); >+my $searchfieldstype = $input->param('searchfieldstype') || 'standard'; > > if ( $searchfieldstype eq "dateofbirth" ) { > $searchmember = output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1}); >-- >2.0.0.rc2
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 12648
:
30024
|
30025
|
30026
|
30027
|
30988
|
30989
|
30990
|
30991
|
31273
|
31960
|
31961
|
32230
|
33186
|
33187
|
33188
|
33189
|
33190
|
33191
|
33192
|
33193
|
34224
|
34225
|
34226
|
34227
|
34228
|
34229
|
34230
|
34231
|
34477
|
34487
|
34488
|
34489
|
34490
|
34491
|
34492
|
34493
|
34494
|
34495
|
35056
|
35058
|
35059
|
35060
|
35061
|
35062
|
35063
|
35064
|
35065
|
35066
|
36795
|
36796
|
36797
|
36798
|
36799
|
36800
|
36801
|
36802
|
36803
|
36804
|
36805
|
36807
|
36810
|
36817