From c9158b4378e8a8e4623618b8e60bc2fb7f0bd848 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 20 Mar 2015 13:13:25 +0100 Subject: [PATCH] Bug 13891: DataTables server-side processing - budget users This first patch remove the previous way to search for users to link to budgets. Test plan: 1/ Edit or create a fund 2/ Edit the owner of this fund a select a patron 3/ Add 1+ users to the user lists of this fund --- admin/add_user_search.pl | 60 +++++++++++ admin/aqbudget_user_search.pl | 89 ----------------- .../en/modules/acqui/tables/members_results.tt | 7 +- .../prog/en/modules/admin/aqbudget_user_search.tt | 111 --------------------- .../prog/en/modules/admin/aqbudgets.tt | 14 +-- .../prog/en/modules/common/patron_search.tt | 3 + svc/members/search | 4 +- 7 files changed, 79 insertions(+), 209 deletions(-) create mode 100755 admin/add_user_search.pl delete mode 100755 admin/aqbudget_user_search.pl delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_user_search.tt diff --git a/admin/add_user_search.pl b/admin/add_user_search.pl new file mode 100755 index 0000000..79425e0 --- /dev/null +++ b/admin/add_user_search.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright 2014 BibLibre +# +# 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, see . + +use Modern::Perl; + +use CGI qw ( -utf8 ); +use C4::Auth; +use C4::Output; +use C4::Members; + +my $input = new CGI; + +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 => { acquisition => 'budget_modify' }, + } +); + +my $q = $input->param('q') || ''; +my $op = $input->param('op') || ''; +my $selection_type = $input->param('selection_type') || 'add'; + +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|admin/aqbudgets.pl| ) + ? 1 : 0; + +$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 => $selection_type, +); +output_html_with_http_headers( $input, $cookie, $template->output ); diff --git a/admin/aqbudget_user_search.pl b/admin/aqbudget_user_search.pl deleted file mode 100755 index 7221e41..0000000 --- a/admin/aqbudget_user_search.pl +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/perl - -# script to find owner and users for a budget - -# Copyright 2008-2009 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. -# -# 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 C4::Auth ; -use C4::Output; -use CGI qw ( -utf8 ); -use C4::Dates qw/format_date/; -use C4::Members; - -my $input = new CGI; - -my $dbh = C4::Context->dbh; - -my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( - { template_name => "admin/aqbudget_user_search.tt", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { acquisition => 'budget_modify' }, - debug => 1, - } -); - -# only used if allowthemeoverride is set -my $type = $input->param('type'); -my $member = $input->param('member') // ''; - -$member =~ s/,//g; #remove any commas from search string -$member =~ s/\*/%/g; -if ( $member eq '' ) { - $template->param( results => 0 ); -} else { - $template->param( results => 1 ); -} - -my @resultsdata; - -if ( $member ) { - my $results = Search($member, "surname"); - - foreach my $res (@$results) { - my $perms = haspermission( $res->{'userid'} ); - my $subperms = get_user_subpermissions( $res->{'userid'} ); - - # if the member has 'acqui' permission set, then display to table. - if ( $perms->{superlibrarian} == 1 || - $perms->{acquisition} == 1 || - exists $subperms->{acquisition} ) - { - my %row = ( - borrowernumber => $res->{'borrowernumber'}, - cardnumber => $res->{'cardnumber'}, - surname => $res->{'surname'}, - firstname => $res->{'firstname'}, - categorycode => $res->{'categorycode'}, - branchcode => $res->{'branchcode'}, - ); - push( @resultsdata, \%row ); - } - } -} - -$template->param( - type => $type, - member => $member, - resultsloop => \@resultsdata -); - -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 b66af4d..5ad87ff 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 @@ -1,3 +1,4 @@ +[% USE To %] { "sEcho": [% sEcho %], "iTotalRecords": [% iTotalRecords %], @@ -14,7 +15,11 @@ "dt_category": "[% data.category_description |html %] ([% data.category_type |html %])", "dt_action": - "Select" + [%- IF selection_type == 'select' -%] + "Select" + [%- ELSE -%] + "Select" + [%- END -%] }[% 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 deleted file mode 100644 index 7d513d6..0000000 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_user_search.tt +++ /dev/null @@ -1,111 +0,0 @@ -[% INCLUDE 'doc-head-open.inc' %] -Koha › Budget - [% IF (type == 'owner') %] - owner - [% ELSE %] - user - [% END %] - search - -[% INCLUDE 'doc-head-close.inc' %] - - - - - - -
-
-
- -

Search for budget - [% IF (type == 'owner') %] - owner - [% ELSE %] - user - [% END %] -

-
-
- - - - -
- -
- Only staff with superlibrarian or acquisitions permissions are returned - in the search results. -
-
- - -[% IF ( results ) %] -

Searched for [% member %], - [% resultsloop.size || 0 %] patron(s) found:

- - - - - - - - - - - - - - [% FOREACH result IN resultsloop %] - - - - - - - - [% END %] - -
CardnumberNameLibraryCategorycodeSelect?
[% result.cardnumber %][% result.surname %], [% result.firstname %][% result.branchcode %][% result.categorycode %] - Select -
-[% END %] - -
- Close -
-
-
-[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt index f88d6d8..5ff800a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt @@ -16,7 +16,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") //' @@ -44,7 +44,8 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") } function ownerRemove() { - edit_owner(0); + $('#budget_owner_name').empty(); + $('#budget_owner_id').val(''); } function add_user(borrowernumber, borrowername) { @@ -483,7 +484,6 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget") - param('branchcode'); my $searchtype = $input->param('searchtype'); my $searchfieldstype = $input->param('searchfieldstype') || 'standard'; my $has_permission = $input->param('has_permission'); +my $selection_type = $input->param('selection_type'); if ( $searchfieldstype eq "dateofbirth" ) { $searchmember = output_pref({dt => dt_from_string($searchmember), dateformat => 'iso', dateonly => 1}); @@ -115,7 +116,8 @@ $template->param( sEcho => $sEcho, iTotalRecords => $results->{iTotalRecords}, iTotalDisplayRecords => $results->{iTotalDisplayRecords}, - aaData => $results->{patrons} + aaData => $results->{patrons}, + selection_type => $selection_type, ); output_with_http_headers $input, $cookie, $template->output, 'json'; -- 2.1.0