lp1890498 Replace Item Barcode Duplcates user/mrisher/lp1890498-replace-barcode-page-duplicate
authorMike Risher <mrisher@catalyte.io>
Wed, 5 Aug 2020 21:34:12 +0000 (21:34 +0000)
committerMike Risher <mrisher@catalyte.io>
Wed, 5 Aug 2020 21:34:12 +0000 (21:34 +0000)
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>
 Changes to be committed:
modified:   Open-ILS/src/templates/staff/cat/share/t_replace_barcode.tt2
modified:   Open-ILS/web/js/ui/default/staff/cat/item/replace_barcode/app.js

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..fdc54b6 100644 (file)
@@ -14,6 +14,7 @@ function($scope , egCore) {
 
     $scope.updateBarcode = function() {
         $scope.copyNotFound = false;
+        $scope.duplicateBarcode = false;
         $scope.updateOK = false;
 
         egCore.pcrud.search('acp', 
@@ -26,12 +27,22 @@ function($scope , egCore) {
                 return;
             }
 
-            $scope.copyId = copy.id();
-            copy.barcode($scope.barcode2);
-
-            egCore.pcrud.update(copy).then(function(stat) {
-                $scope.updateOK = stat;
-                $scope.focusBarcode = true;
+            egCore.pcrud.search('acp', 
+                {deleted : 'f', barcode : $scope.barcode2})
+            .then(function(newBarcodeCopy) {
+                
+                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;
+                });
             });
         });
     }