Bug 19837: Add multiple patrons to a list by barcode
authorOwen Leonard <oleonard@myacpl.org>
Fri, 15 Dec 2017 17:26:12 +0000 (17:26 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sun, 18 Feb 2018 19:48:45 +0000 (16:48 -0300)
This patch adds the interface change and basic functionality for an
option to add multiple patrons to a patron list by scanning barcodes.

To test, apply the patch and go to Tools -> Patron lists.

- Create a patron list if necessary, and got to the "Add patrons"
  screen.
- Test the process for adding patrons using the "Patron search" text
  input.
- Test the process for adding patrons using the "Enter multiple card
  numbers" option.

This should really have some error-handling added to it: Onscreen
messages when a non-existing patron card number is submitted or when a
patron already exists on the list.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt
patron_lists/list.pl

index ba846b5..9f2eba1 100644 (file)
@@ -5,6 +5,20 @@
 [% INCLUDE 'doc-head-close.inc' %]
 
 <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
+<style type="text/css">
+    #add_patrons_by_search {
+        display: none;
+    }
+    #patron_barcodes_line {
+        display: none;
+    }
+    #patron_barcodes_submit {
+        display: none;
+    }
+    #searchheader {
+        margin-top: 1em;
+    }
+</style>
 </head>
 
 <body id="patlist_list" class="pat patlist">
         <div class="yui-b">
         <h1>[% list.name |html %]</h1>
 
-        <form action="list.pl" id="add_patrons" method="post">
-            <fieldset>
+        <form action="list.pl" id="add_patrons" method="post" class="clearfix">
+            <fieldset class="rows">
                 <legend>Add patrons</legend>
+                <ol>
+                    <li id="patron_search_line">
+                        <label for="find_patron">Patron search: </label>
+                        <input autocomplete="off" id="find_patron" type="text" style="width:150px" class="noEnterSubmit" />
+                    </li>
+                    <li id="add_patrons_by_search"><a href="#">
+                        <span class="label">&nbsp;</span>
+                        <i class="fa fa-plus"></i> Search for patrons</a></li>
+                    <li id="add_patrons_by_barcode"><a href="#">
+                        <span class="label">&nbsp;</span>
+                        <i class="fa fa-plus"></i> Enter multiple card numbers</a></li>
+                    <li id="patron_barcodes_line">
+                        <label for="patrons_by_barcode">Card number list (one barcode per line):</label>
+                        <textarea id="patrons_by_barcode" name="patrons_by_barcode" id="" cols="30" rows="10"></textarea>
+                    </li>
+                </ol>
+            </fieldset>
+            <fieldset id="patron_barcodes_submit" class="action">
+                <input type="submit" value="Submit" />
+            </fieldset>
 
-                    <label for="find_patron">Patron search: </label>
-                    <input autocomplete="off" id="find_patron" type="text" style="width:150px" class="noEnterSubmit" />
-                    <div id="find_patron_container"></div>
+            <div class="clearfix"></div>
 
-                <fieldset id="patrons_to_add_fieldset">
-                    <legend>Patrons to be added</legend>
-                    <div id="patrons_to_add"></div>
+            <fieldset id="patrons_to_add_fieldset">
+                <legend>Patrons to be added</legend>
+                <div id="patrons_to_add"></div>
 
-                    <fieldset class="action">
-                        <input type="hidden" name="patron_list_id" value="[% list.patron_list_id %]" />
-                        <input type="submit" value="Add patrons" />
-                        <a href="lists.pl" class="cancel">Cancel</a>
-                    </fieldset>
+                <fieldset class="action">
+                    <input type="hidden" name="patron_list_id" value="[% list.patron_list_id %]" />
+                    <input type="submit" value="Add patrons" />
+                    <a href="lists.pl" class="cancel">Cancel</a>
                 </fieldset>
-
             </fieldset>
         </form>
 
                     return false;
                 }
             });
+
+            $("#add_patrons_by_barcode a").on("click", function(){
+                $("#add_patrons_by_barcode, #patron_search_line").hide();
+                $("#add_patrons_by_search, #patron_barcodes_line, #patron_barcodes_submit").show();
+            });
+
+            $("#add_patrons_by_search a").on("click", function(){
+                $("#add_patrons_by_barcode, #patron_search_line").show();
+                $("#add_patrons_by_search, #patron_barcodes_line, #patron_barcodes_submit").hide();
+            });
         });
     </script>
 [% END %]
index 9a21681..91e6370 100755 (executable)
@@ -24,6 +24,7 @@ use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Output;
 use Koha::List::Patron;
+use List::MoreUtils qw/uniq/;
 
 my $cgi = new CGI;
 
@@ -40,6 +41,14 @@ my ( $template, $logged_in_user, $cookie ) = get_template_and_user(
 my ($list) =
   GetPatronLists( { patron_list_id => scalar $cgi->param('patron_list_id') } );
 
+my $cardnumbers = $cgi->param('patrons_by_barcode');
+my @patrons_by_barcode;
+
+if ( $cardnumbers ){
+    push my @patrons_by_barcode, uniq( split(/\s\n/, $cardnumbers) );
+    AddPatronsToList( { list => $list, cardnumbers => \@patrons_by_barcode } );
+}
+
 my @patrons_to_add = $cgi->multi_param('patrons_to_add');
 if (@patrons_to_add) {
     AddPatronsToList( { list => $list, cardnumbers => \@patrons_to_add } );