Bug 13891: DataTables server-side processing - budget users
authorJonathan Druart <jonathan.druart@biblibre.com>
Fri, 20 Mar 2015 12:13:25 +0000 (13:13 +0100)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Mon, 13 Apr 2015 13:55:13 +0000 (10:55 -0300)
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

Tested together with other patches.
Signed-off-by: Marc Veron <veron@veron.ch>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
admin/add_user_search.pl [new file with mode: 0755]
admin/aqbudget_user_search.pl [deleted file]
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudget_user_search.tt [deleted file]
koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgets.tt
koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt
svc/members/search

diff --git a/admin/add_user_search.pl b/admin/add_user_search.pl
new file mode 100755 (executable)
index 0000000..79425e0
--- /dev/null
@@ -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 <http://www.gnu.org/licenses>.
+
+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 (executable)
index 7221e41..0000000
+++ /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;
index b66af4d..5ad87ff 100644 (file)
@@ -1,3 +1,4 @@
+[% USE To %]
 {
     "sEcho": [% sEcho %],
     "iTotalRecords": [% iTotalRecords %],
                 "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 %]\");'>Select</a>"
+                    [%- IF selection_type == 'select' -%]
+                        "<a style='cursor:pointer' onclick='select_user(\"[% data.borrowernumber %]\", [% To.json(data) | html %] );'>Select</a>"
+                    [%- ELSE -%]
+                        "<a style='cursor:pointer' onclick='add_user(\"[% data.borrowernumber %]\", \"[% data.firstname %] [% data.surname %]\");'>Select</a>"
+                    [%- 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 (file)
index 7d513d6..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Budget
-    [% IF (type == 'owner') %]
-        owner
-    [% ELSE %]
-        user
-    [% END %]
-    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) {
-        [% IF (type == 'owner') %]
-            top.opener.edit_owner(borrowernumber, borrowername);
-            window.close();
-        [% ELSE %]
-            var ret = top.opener.add_user(borrowernumber, borrowername);
-            if (ret != 0) {
-                alert(_("This user is already in the list."));
-            }
-        [% END %]
-    }
-
-    //]]>
-    </script>
-</head>
-
-<body id="admin_aqbudget_owner_search" class="admin">
-<div id="custom-doc" class="yui-t7">
-<div id="bd">
-<div class="yui-g">
-
-<h3>Search for budget
-    [% IF (type == 'owner') %]
-        owner
-    [% ELSE %]
-        user
-    [% END %]
-</h3>
-<form action="/cgi-bin/koha/admin/aqbudget_user_search.pl" method="post">
-    <fieldset>
-        <input type="text" name="member" id="member" value="[% member %]"
-            class="focus" />
-
-        <input type="hidden" name="type" value="[% type %]" />
-        <input type="submit" class="button" value="Search" />
-    </fieldset>
-
-    <div class="hint">
-        Only staff with superlibrarian or acquisitions permissions are returned
-        in the search results.
-    </div>
-</form>
-
-
-[% IF ( results ) %]
-    <p>Searched for <span class="ex">[% member %]</span>,
-    [% resultsloop.size || 0 %] patron(s) found:</p>
-
-    <table>
-        <thead>
-            <tr>
-                <th>Cardnumber</th>
-                <th>Name</th>
-                <th>Library</th>
-                <th>Categorycode</th>
-                <th>Select?</th>
-            </tr>
-        </thead>
-
-        <tbody>
-            [% FOREACH result IN resultsloop %]
-                <tr>
-                    <td>[% result.cardnumber %]</td>
-                    <td>[% result.surname %], [% result.firstname %]</td>
-                    <td>[% result.branchcode %]</td>
-                    <td>[% result.categorycode %]</td>
-                    <td>
-                    <a style="cursor:pointer"
-                        onclick="add_user(
-                            '[% result.borrowernumber %]',
-                            '[% result.surname %]',
-                            '[% result.firstname %]'
-                        );"
-                    />Select</a>
-                    </td>
-                </tr>
-            [% END %]
-        </tbody>
-    </table>
-[% END %]
-
-<div id="closewindow">
-    <a href="#" class="close">Close</a>
-</div>
-</div>
-</div>
-[% INCLUDE 'intranet-bottom.inc' %]
index f88d6d8..5ff800a 100644 (file)
@@ -16,7 +16,7 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget")
 //<![CDATA[
 
     function userPopup() {
-        window.open("/cgi-bin/koha/admin/aqbudget_user_search.pl?type=user",
+        window.open("/cgi-bin/koha/admin/add_user_search.pl?selection_type=add",
             'PatronPopup',
             'width=740,height=450,location=yes,toolbar=no,'
             + 'scrollbars=yes,resize=yes'
@@ -24,16 +24,16 @@ var MSG_PARENT_BENEATH_BUDGET = "- " + _("New budget-parent is beneath budget")
     }
 
     function ownerPopup() {
-        window.open("/cgi-bin/koha/admin/aqbudget_user_search.pl?type=owner",
+        window.open("/cgi-bin/koha/admin/add_user_search.pl?selection_type=select",
             'PatronPopup',
             'width=740,height=450,location=yes,toolbar=no,'
             + 'scrollbars=yes,resize=yes'
         );
     }
 
-    function edit_owner(borrowernumber, borrowername) {
-        $('#budget_owner_name').empty();
-        $('#budget_owner_id').val('');
+    function select_user(borrowernumber, borrower) {
+        ownerRemove();
+        var borrowername = borrower.firstname + ' ' + borrower.surname
         if (borrowernumber) {
             var ownerlink = '<a href="/cgi-bin/koha/members/moremember.pl'
                 + '?borrowernumber=' + borrowernumber + '">'
@@ -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")
         <input type="hidden" name="budget_owner_id" id="budget_owner_id"
             value="[% budget_owner_id %]" />
 
-        <!-- FIXME: hardcoded button positions :/ -->
         <input type="button" id="edit_owner" value="Edit owner"
             onclick="ownerPopup(); return false;" />
         <input type="button" id="remove_owner" value="Remove owner"
index fd133e4..494d154 100644 (file)
@@ -44,6 +44,9 @@ $(document).ready(function(){
             },{
                 'name': 'template_path',
                 'value': '[% json_template %]',
+            },{
+                'name': 'selection_type',
+                'value': '[% selection_type %]',
             }
             [% IF patrons_with_acq_perm_only %]
             ,{
index 8889773..864a45c 100755 (executable)
@@ -45,6 +45,7 @@ my $branchcode = $input->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';