webstaff: add a Transfer Copies to Previously Marked Library action
authorGalen Charlton <gmc@esilibrary.com>
Tue, 26 Jan 2016 21:13:27 +0000 (16:13 -0500)
committerKathy Lussier <klussier@masslnc.org>
Tue, 2 Feb 2016 19:58:54 +0000 (14:58 -0500)
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/templates/staff/cat/catalog/t_holdings.tt2
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js

index 8f3c6cc..6f50ceb 100644 (file)
@@ -40,7 +40,7 @@
     <eg-grid-action handler="attach_to_peer_bib"
       label="[% l('Link as Conjoined to Previously Marked Bib Record') %]"></eg-grid-action>
     <eg-grid-action handler="markLibAsVolTarget"
     <eg-grid-action handler="attach_to_peer_bib"
       label="[% l('Link as Conjoined to Previously Marked Bib Record') %]"></eg-grid-action>
     <eg-grid-action handler="markLibAsVolTarget"
-      label="[% l('Choose Library for Volume Transfer Destination') %]"></eg-grid-action>
+      label="[% l('Choose Library for Volume/Copy Transfer Destination') %]"></eg-grid-action>
 
     <eg-grid-action handler="selectedHoldingsItemStatus" group="[% l('Show') %]"
       label="[% l('Item Status (list)') %]"></eg-grid-action>
 
     <eg-grid-action handler="selectedHoldingsItemStatus" group="[% l('Show') %]"
       label="[% l('Item Status (list)') %]"></eg-grid-action>
@@ -83,6 +83,8 @@
 
     <eg-grid-action handler="transferVolumes" group="[% l('Transfer') %]"
       label="[% l('Volumes to Previously Marked Library') %]"></eg-grid-action>
 
     <eg-grid-action handler="transferVolumes" group="[% l('Transfer') %]"
       label="[% l('Volumes to Previously Marked Library') %]"></eg-grid-action>
+    <eg-grid-action handler="changeItemOwningLib" group="[% l('Transfer') %]"
+      label="[% l('Copies to Previously Marked Library') %]"></eg-grid-action>
     <eg-grid-action handler="transferItems" group="[% l('Transfer') %]"
       label="[% l('Items to Previously Marked Volume') %]"></eg-grid-action>
 
     <eg-grid-action handler="transferItems" group="[% l('Transfer') %]"
       label="[% l('Items to Previously Marked Volume') %]"></eg-grid-action>
 
index bb3abda..2ab0074 100644 (file)
@@ -1045,6 +1045,59 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         
     }
 
         
     }
 
+    // this "transfers" selected copies to a new owning library,
+    // auto-creating volumes and deleting unused volumes as required.
+    $scope.changeItemOwningLib = function() {
+        var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
+        var items = $scope.holdingsGridControls.selectedItems();
+        if (!xfer_target || !items.length) {
+            return;
+        }
+        var vols_to_move   = {};
+        var copies_to_move = {};
+        angular.forEach(items, function(item) {
+            if (item.call_number.owning_lib != xfer_target) {
+                if (item.call_number.id in vols_to_move) {
+                    copies_to_move[item.call_number.id].push(item.id);
+                } else {
+                    vols_to_move[item.call_number.id] = item.call_number;
+                    copies_to_move[item.call_number.id] = new Array;
+                    copies_to_move[item.call_number.id].push(item.id);
+                }
+            }
+        });
+    
+        var promises = [];
+        angular.forEach(vols_to_move, function(vol) {
+            promises.push(egCore.net.request(
+                'open-ils.cat',
+                'open-ils.cat.call_number.find_or_create',
+                egCore.auth.token(),
+                vol.label,
+                vol.record,
+                xfer_target,
+                vol.prefix.id,
+                vol.suffix.id,
+                vol.label_class
+            ).then(function(resp) {
+                var evt = egCore.evt.parse(resp);
+                if (evt) return;
+                return egCore.net.request(
+                    'open-ils.cat',
+                    'open-ils.cat.transfer_copies_to_volume',
+                    egCore.auth.token(),
+                    resp.acn_id,
+                    copies_to_move[vol.id]
+                );
+            }));
+        });
+        $q.all(promises).then(function() {
+            holdingsSvcInst.fetchAgain().then(function() {
+                $scope.holdingsGridDataProvider.refresh();
+            });
+        });
+    }
+
     $scope.transferItems = function (){
         var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
         var copy_ids = gatherSelectedHoldingsIds();
     $scope.transferItems = function (){
         var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
         var copy_ids = gatherSelectedHoldingsIds();