LP1819367 - Allow paste of list of barcodes in csv format user/stompro/lp1819367_item_status_csv_paste
authorJosh Stompro <stompro@stompro.org>
Fri, 13 Sep 2019 16:38:33 +0000 (11:38 -0500)
committerJosh Stompro <stompro@stompro.org>
Fri, 13 Sep 2019 16:38:33 +0000 (11:38 -0500)
Allow the item status scan box to accept a string of barcodes
separated with commas.

Signed-off-by: Josh Stompro <stompro@stompro.org>
Open-ILS/src/templates/staff/cat/item/index.tt2
Open-ILS/web/js/ui/default/staff/cat/item/app.js

index 9cb8be8..34bf65f 100644 (file)
@@ -70,6 +70,7 @@
         select-me="context.selectBarcode" ng-model="args.barcode">
       <input class="btn btn-default" 
         type="submit" value="[% l('Submit') %]"/>
+      <eg-help-popover help-text="[% l('Single barcode or list of barcodes separated with commas.') %]">
     </div>
     <!-- give the upload container div some padding to prevent force the
         upload widget into the vertical middle of the row -->
index 52d2d02..b9999e4 100644 (file)
@@ -401,17 +401,40 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
     $scope.context.search = function(args) {
         if (!args.barcode) return;
         $scope.context.itemNotFound = false;
-        itemSvc.fetch(args.barcode).then(function(res) {
-            if (res) {
-                copyGrid.refresh();
-                copyGrid.selectItems([res.index]);
-                $scope.args.barcode = '';
-            } else {
-                $scope.context.itemNotFound = true;
-                egCore.audio.play('warning.item_status.itemNotFound');
-            }
-            $scope.context.selectBarcode = true;
-        })
+
+        //check to see if there are multiple barcodes in CSV format
+        var barcodes = [];
+        //split on commas and clean up barcodes
+        angular.forEach(args.barcode.split(/,/), function(line) {
+            //remove all whitespace and commas
+            line = line.replace(/[\s,]+/g,'');
+
+            //Or remove leading/trailing whitespace
+            //line = line.replace(/(^[\s,]+|[\s,]+$/g,'');
+
+            if (!line) return;
+            barcodes.push(line);
+        });
+
+        if(barcodes.length > 1){
+            //convert to newline seperated list and send to barcodesFromFile processor
+            $scope.barcodesFromFile = barcodes.join('\n');
+            //console.log('Barcodes: ',barcodes);
+        }
+        else {
+            //Single Barcode
+            itemSvc.fetch(args.barcode).then(function(res) {
+                if (res) {
+                    copyGrid.refresh();
+                    copyGrid.selectItems([res.index]);
+                    $scope.args.barcode = '';
+                } else {
+                    $scope.context.itemNotFound = true;
+                    egCore.audio.play('warning.item_status.itemNotFound');
+                }
+                $scope.context.selectBarcode = true;
+            })
+        }
     }
 
     var add_barcode_to_list = function (b) {