lp1890498: Replace Item Barcode now warns about duplicate barcode
authorMike Risher <mrisher@catalyte.io>
Wed, 5 Aug 2020 21:34:12 +0000 (21:34 +0000)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 13 Aug 2020 14:04:54 +0000 (10:04 -0400)
Modify the Replace Item Barcode page so that it displays an error
message when trying to replace a barcode with a barcode already
in use.

Signed-off-by: Mike Risher <mrisher@catalyte.io>
Signed-off-by: Elaine Hardy <ehardy@georgialibraries.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/cat/share/t_replace_barcode.tt2
Open-ILS/web/js/ui/default/staff/cat/item/replace_barcode/app.js

index f15a831..62f9c8b 100644 (file)
@@ -33,6 +33,9 @@
     <div class="alert alert-danger" ng-if="copyNotFound">
       [% l('Item Not Found') %]
     </div>
+    <div class="alert alert-danger" ng-if="duplicateBarcode">
+      [% l('Duplicate Barcode') %]
+    </div>
     <div class="alert alert-success" ng-if="updateOK">
       <span>[% l('Item Updated') %]</span>
       <span class="horiz-pad" ng-if="copyId">
index 33d1cb6..d9d9d3d 100644 (file)
@@ -14,9 +14,10 @@ function($scope , egCore) {
 
     $scope.updateBarcode = function() {
         $scope.copyNotFound = false;
+        $scope.duplicateBarcode = false;
         $scope.updateOK = false;
 
-        egCore.pcrud.search('acp', 
+        egCore.pcrud.search('acp',
             {deleted : 'f', barcode : $scope.barcode1})
         .then(function(copy) {
 
@@ -26,12 +27,22 @@ function($scope , egCore) {
                 return;
             }
 
-            $scope.copyId = copy.id();
-            copy.barcode($scope.barcode2);
+            egCore.pcrud.search('acp',
+                {deleted : 'f', barcode : $scope.barcode2})
+            .then(function(newBarcodeCopy) {
 
-            egCore.pcrud.update(copy).then(function(stat) {
-                $scope.updateOK = stat;
-                $scope.focusBarcode = true;
+                if (newBarcodeCopy) {
+                    $scope.duplicateBarcode = true;
+                    return;
+                }
+
+                $scope.copyId = copy.id();
+                copy.barcode($scope.barcode2);
+
+                egCore.pcrud.update(copy).then(function(stat) {
+                    $scope.updateOK = stat;
+                    $scope.focusBarcode = true;
+                });
             });
         });
     }