[Koha-patches] [PATCH] [SIGNED-OFF 5/5] Bug 5227 [3.4] Enhance the label batch edit interface

Galen Charlton gmcharlt at gmail.com
Tue Oct 26 15:10:57 CEST 2010


From: Chris Nighswonger <cnighswonger at foundations.edu>

This patch adds the ability to enter items into label batches via
barcode scanning

Work sponsored by Tamil - http://www.tamil.fr

Signed-off-by: Frédéric Demians <f.demians at tamil.fr>
Signed-off-by: Galen Charlton <gmcharlt at gmail.com>
---
 .../prog/en/includes/labels-batches-toolbar.inc    |    8 +++-
 .../prog/en/modules/labels/label-edit-batch.tmpl   |   44 ++++++++++++++++++-
 labels/label-edit-batch.pl                         |   13 +++++-
 3 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/labels-batches-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/labels-batches-toolbar.inc
index 47a0b8f..f3a2006 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/labels-batches-toolbar.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/labels-batches-toolbar.inc
@@ -46,7 +46,13 @@
                 }
             };
             function Add() {
-                window.open("/cgi-bin/koha/labels/label-item-search.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=labels",'FindABibIndex','width=875,height=400,toolbar=no,scrollbars=yes');
+                var barcodes = document.getElementById("barcode");
+                if (barcodes.value == '') {
+                    window.open("/cgi-bin/koha/labels/label-item-search.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=labels",'FindABibIndex','width=875,height=400,toolbar=no,scrollbars=yes');
+                }
+                else {
+                    document.forms["add_by_barcode"].submit();
+                }
             };
             function DeDuplicate() {
                 window.location = "/cgi-bin/koha/labels/label-edit-batch.pl?op=de_duplicate&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->";
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tmpl
index df1f556..7ca0d02 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tmpl
@@ -1,9 +1,26 @@
+    <!-- PLEASE MAINTAIN PROPER INDENTATION!!!!  -->
     <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
     <title>Koha &rsaquo; Tools &rsaquo; Labels &rsaquo; Manage Label Batches</title>
     <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
     <!-- TMPL_INCLUDE NAME="greybox.inc" -->
+    <script type="text/javascript">
+    //<![CDATA[
+        function dofocus() {    // named function req'd for body onload event by some FF and IE7 security models
+            $(".focus:last").select();
+        }
+        function verifyBarcodes(barcodes) {
+            if (barcodes.value == '') {
+                alert("Please add barcodes using either the direct entry text area or the item search.");
+                return false;   // not ok
+            }
+            else {
+                return true;    // ok
+            };
+        }
+    //]]>
+    </script>
 </head>
-<body>
+<body onload="dofocus();">
     <!-- TMPL_INCLUDE NAME="header.inc" -->
     <!-- TMPL_INCLUDE NAME="cat-search.inc" -->
     <div id="breadcrumbs">
@@ -21,6 +38,21 @@
                     <div class="yui-g">
                         <div class="yui-u first" id="manage-label-batches">
                             <div class="hint">Current Branch: <!-- TMPL_VAR NAME="LoginBranchname" --></div>
+                            <form name="add_by_barcode" action="/cgi-bin/koha/labels/label-edit-batch.pl" method="post">
+                                <div>
+                                    <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
+                                    <ol><li>
+                                    <input type="hidden" name="op" value="add" \>
+                                    <input type="hidden" name="batch_id" value="<!-- TMPL_VAR NAME="batch_id" -->" \>
+                                    <label for="barcode">Add by Barcode(s): 
+                                        <br \> <span class="hint">One barcode per line.</span>
+                                        <br \> <span class="hint">Leave empty to add via item search.</span>
+                                    </label>
+                                    <textarea rows="5" id="barcode" name="barcode" tabindex="1" class="focus"></textarea>
+                                    </li></ol>
+                                    </fieldset>
+                                </div>
+                            </form>
                                 <!-- TMPL_IF NAME="table_loop" -->
                                 <form name="items" class="checkboxed">
                                     <h2>Items in batch number <!-- TMPL_VAR NAME="batch_id" --></h2>
@@ -47,8 +79,14 @@
                                     </table>
                                 </form>
                                 <!-- TMPL_ELSE -->
-                                    <div class="dialog message"><h4>There are no items in Batch <!-- TMPL_VAR NAME="batch_id" --> yet</h4>
-                                    <p>Use the toolbar above to add items.</p></div>
+                                <fieldset class="rows" style="border-bottom: 0px; border: 0px;">
+                                <ol><li>
+                                    <div class="dialog message">
+                                        <h4>There are no items in Batch <!-- TMPL_VAR NAME="batch_id" --> yet</h4>
+                                        <p>Add items by barcode using the text area above or leave empty to add via item search.</p>
+                                    </div>
+                                </li></ol>
+                                </fieldset>
                                 <!-- /TMPL_IF -->
                             </div>
                             <!-- TMPL_IF NAME="err" -->
diff --git a/labels/label-edit-batch.pl b/labels/label-edit-batch.pl
index 94d56b4..370807c 100755
--- a/labels/label-edit-batch.pl
+++ b/labels/label-edit-batch.pl
@@ -27,6 +27,7 @@ use CGI;
 use C4::Auth qw(get_template_and_user);
 use C4::Output qw(output_html_with_http_headers);
 use C4::Branch qw(get_branch_code_from_name);
+use C4::Items qw(GetItemnumberFromBarcode);
 use C4::Creators 1.000000;
 use C4::Labels 1.000000;
 
@@ -57,7 +58,8 @@ my $display_columns = [ {_label_number  => {label => 'Label Number', link_field
 my $op = $cgi->param('op') || 'edit';
 my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || undef;
 my @label_ids = $cgi->param('label_id') if $cgi->param('label_id');
-my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
+my @item_numbers = $cgi->param('item_number') || ();
+my $barcode = $cgi->param('barcode') if $cgi->param('barcode');
 
 my $branch_code = get_branch_code_from_name($template->param('LoginBranchname'));
 
@@ -76,6 +78,15 @@ elsif ($op eq 'delete') {
     $errstr = "batch $batch_id was not deleted." if $err;
 }
 elsif ($op eq 'add') {
+    if ($barcode) {
+        my @barcodes = split /\n/, $barcode; # $barcode is effectively passed in as a <cr> separated list
+        foreach my $number (@barcodes) {
+            $number =~ s/\r$//; # strip any naughty return chars
+            if (my $item_number = GetItemnumberFromBarcode($number)) {  # we must test in case an invalid barcode is passed in; we effectively disgard them atm
+                push @item_numbers, $item_number;
+            }
+        }
+    }
     $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
     $batch = C4::Labels::Batch->new(branch_code => $branch_code) if $batch == -2;
     if ($branch_code){
-- 
1.7.0



More information about the Koha-patches mailing list