LP #1705497 Replaces functionality in web client from legacy
authorAdam Bowling <abowling@emeralddata.net>
Thu, 7 Mar 2019 04:06:09 +0000 (23:06 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Wed, 16 Oct 2019 18:45:00 +0000 (14:45 -0400)
XUL client by including a find function for originating
acquisition where it exists.

Signed-off-by: Adam Bowling <abowling@emeralddata.net>
Signed-off-by: Tiffany Little <tlittle@georgialibraries.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/web/js/ui/default/staff/cat/item/app.js

index 52d2d02..857e522 100644 (file)
@@ -145,6 +145,41 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
         itemSvc.manage_reservations([$scope.args.copyBarcode]);
     }
 
+    $scope.findAcquisition = function() {
+        var acqData;
+        var promises = [];
+        $scope.openAcquisitionLineItem([$scope.args.copyId]);
+    }
+
+    $scope.openAcquisitionLineItem = function (cp_list) {
+        var hasResults = false;
+        var promises = [];
+
+        angular.forEach(cp_list, function (copyId) {
+            promises.push(
+                egNet.request(
+                    'open-ils.acq',
+                    'open-ils.acq.lineitem.retrieve.by_copy_id',
+                    egCore.auth.token(),
+                    copyId
+                ).then(function (acqData) {
+                    if (acqData) {
+                        if (acqData.a) {
+                            acqData = egCore.idl.toHash(acqData);
+                            var url = '/eg/acq/po/view/' + acqData.purchase_order + '/' + acqData.id;
+                            $timeout(function () { $window.open(url, '_blank') });
+                            hasResults = true;
+                        }
+                    }
+                })
+            )
+        });
+
+        $q.all(promises).then(function () {
+            !hasResults ? alert('There is no corresponding purchase order for this item.') : false;
+        });
+    }
+
     $scope.requestItems = function() {
         itemSvc.requestItems([$scope.args.copyId],[$scope.args.recordId]);
     }