webstaff: Transfer volume and item actions
authorMike Rylander <mrylander@gmail.com>
Thu, 3 Sep 2015 12:21:20 +0000 (08:21 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:18 +0000 (15:44 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/templates/staff/cat/catalog/t_holdings.tt2
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
Open-ILS/web/js/ui/default/staff/services/grid.js

index 8cf4396..27d434a 100644 (file)
       label="[% l('Triggered Events') %]"></eg-grid-action>
     <eg-grid-action handler="selectedHoldingsItemStatusHolds" group="[% l('Show') %]"
       label="[% l('Item Holds') %]"></eg-grid-action>
+
     <eg-grid-action handler="selectedHoldingsDamaged" group="[% l('Mark') %]"
       label="[% l('Item as Damaged') %]"></eg-grid-action>
     <eg-grid-action handler="selectedHoldingsMissing" group="[% l('Mark') %]"
       label="[% l('Item as Missing') %]"></eg-grid-action>
+    <eg-grid-action handler="markLibAsVolTarget" group="[% l('Mark') %]"
+      label="[% l('Library as Volume Transfer Destination') %]"></eg-grid-action>
+    <eg-grid-action handler="markVolAsItemTarget" group="[% l('Mark') %]" disabled="vols_not_shown"
+      label="[% l('Volume as Item Transfer Destination') %]"></eg-grid-action>
+
     <eg-grid-action handler="selectedHoldingsVolEdit" group="[% l('Edit') %]"
-      label="[% l('Selected Volumes') %]"></eg-grid-action>
+      label="[% l('Volumes') %]"></eg-grid-action>
     <eg-grid-action handler="selectedHoldingsCopyEdit" group="[% l('Edit') %]"
-      label="[% l('Selected Copies') %]"></eg-grid-action>
+      label="[% l('Copies') %]"></eg-grid-action>
     <eg-grid-action handler="selectedHoldingsVolCopyEdit" group="[% l('Edit') %]"
-      label="[% l('Selected Volumes and Copies') %]"></eg-grid-action>
+      label="[% l('Volumes and Copies') %]"></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="transferItems" group="[% l('Transfer') %]"
+      label="[% l('Items to Previously Marked Volume') %]"></eg-grid-action>
 
     <eg-grid-field label="[% l('Owning Library') %]"  path="owner_label" flex="4" align="right" visible></eg-grid-field>
     <eg-grid-field label="[% l('Call Number') %]"     path="call_number.label" visible></eg-grid-field>
index 61ad57f..c108774 100644 (file)
@@ -316,6 +316,10 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         })
     });
 
+    $scope.vols_not_shown = function () {
+        return !$scope.holdings_show_vols;
+    }
+
     $scope.holdings_checkbox_handler = function (item) {
         $scope.holdings_cb_changed(item.checkbox,item.checked);
     }
@@ -329,6 +333,27 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         return cp_id_list;
     }
 
+    function gatherSelectedRawCopies () {
+        var cp_list = [];
+        angular.forEach(
+            $scope.holdingsGridControls.selectedItems(),
+            function (item) { cp_list = cp_list.concat(item.raw) }
+        );
+        return cp_list;
+    }
+
+    function gatherSelectedVolumeIds () {
+        var cn_id_list = [];
+        angular.forEach(
+            $scope.holdingsGridControls.selectedItems(),
+            function (item) {
+                if (cn_id_list.indexOf(item.call_number.id) == -1)
+                    cn_id_list.push(item.call_number.id)
+            }
+        );
+        return cn_id_list;
+    }
+
     spawnHoldingsEdit = function (hide_vols,hide_copies){
         egCore.net.request(
             'open-ils.actor',
@@ -357,6 +382,24 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         $timeout(function() { $window.open(url, '_blank') });
     }
 
+    $scope.markVolAsItemTarget = function() {
+        if ($scope.holdingsGridControls.selectedItems()[0].call_number.id) { // cn.id missing when vols are collapsed
+            egCore.hatch.setLocalItem(
+                'eg.cat.item_transfer_target',
+                $scope.holdingsGridControls.selectedItems()[0].call_number.id
+            );
+            console.log('item_transfer_dest: '+$scope.holdingsGridControls.selectedItems()[0].call_number.id);
+        }
+    }
+
+    $scope.markLibAsVolTarget = function() {
+        egCore.hatch.setLocalItem(
+            'eg.cat.volume_transfer_target',
+            $scope.holdingsGridControls.selectedItems()[0].owner_id
+        );
+        console.log('vol_transfer_dest: '+$scope.holdingsGridControls.selectedItems()[0].owner_id);
+    }
+
     $scope.selectedHoldingsItemStatusDetail = function (){
         angular.forEach(
             gatherSelectedHoldingsIds(),
@@ -368,6 +411,67 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         );
     }
 
+    $scope.transferVolumes = function (){
+        var xfer_target = egCore.hatch.getLocalItem('eg.cat.volume_transfer_target');
+
+        if (xfer_target) {
+            egCore.net.request(
+                'open-ils.cat',
+                'open-ils.open-ils.cat.asset.volume.batch.transfer.override',
+                egCore.auth.token(), {
+                    docid   : $scope.record_id,
+                    lib     : xfer_target,
+                    volumes : gatherSelectedVolumeIds()
+                }
+            ).then(function(success) {
+                if (success) {
+                    holdingsSvc.fetch({
+                        rid : $scope.record_id,
+                        org : $scope.holdings_ou,
+                        copy: $scope.holdings_show_copies,
+                        vol : $scope.holdings_show_vols,
+                        empty: $scope.holdings_show_empty
+                    }).then(function() {
+                        $scope.holdingsGridDataProvider.refresh();
+                    });
+                } else {
+                    alert('Could not transfer volumes!');
+                }
+            });
+        }
+        
+    }
+
+    $scope.transferItems = function (){
+        var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target');
+        if (xfer_target) {
+            var copy_list = gatherSelectedRawCopies();
+
+            angular.forEach(copy_list, function (cp) {
+                cp.call_number(xfer_target);
+            });
+
+            egCore.pcrud.update(
+                copy_list
+            ).then(function(success) {
+                if (success) {
+                    holdingsSvc.fetch({
+                        rid : $scope.record_id,
+                        org : $scope.holdings_ou,
+                        copy: $scope.holdings_show_copies,
+                        vol : $scope.holdings_show_vols,
+                        empty: $scope.holdings_show_empty
+                    }).then(function() {
+                        $scope.holdingsGridDataProvider.refresh();
+                    });
+                } else {
+                    alert('Could not transfer items!');
+                }
+            });
+        }
+        
+    }
+
     $scope.selectedHoldingsItemStatusTgrEvt = function (){
         angular.forEach(
             gatherSelectedHoldingsIds(),
@@ -756,6 +860,7 @@ function(egCore , $q) {
                             if (cp.barcode) current_blob.copy_count = 1;
                             current_blob.index = index++;
                             current_blob.id_list = cp.id_list;
+                            current_blob.raw = cp.raw;
                             current_blob.call_number = cp.call_number;
                             current_blob.owner_list = cp.owner_list;
                             current_blob.owner_label = cp.owner_label;
@@ -764,6 +869,7 @@ function(egCore , $q) {
                             if (prev_key == current_key) { // collapse into current_blob
                                 current_blob.copy_count++;
                                 current_blob.id_list = current_blob.id_list.concat(cp.id_list);
+                                current_blob.raw = current_blob.raw.concat(cp.raw);
                             } else {
                                 current_blob.barcode = current_blob.copy_count;
                                 cp_list.push(current_blob);
@@ -772,6 +878,7 @@ function(egCore , $q) {
                                 if (cp.barcode) current_blob.copy_count = 1;
                                 current_blob.index = index++;
                                 current_blob.id_list = cp.id_list;
+                                current_blob.raw = cp.raw;
                                 current_blob.owner_label = cp.owner_label;
                                 current_blob.call_number = cp.call_number;
                                 current_blob.owner_list = cp.owner_list;
@@ -794,6 +901,7 @@ function(egCore , $q) {
                                 prev_key = cp.owner_list.join('');
                                 current_blob.index = index++;
                                 current_blob.id_list = cp.id_list;
+                                current_blob.raw = cp.raw;
                                 current_blob.cn_count = 1;
                                 current_blob.copy_count = cp.copy_count;
                                 current_blob.owner_list = cp.owner_list;
@@ -804,6 +912,7 @@ function(egCore , $q) {
                                     current_blob.cn_count++;
                                     current_blob.copy_count += cp.copy_count;
                                     current_blob.id_list = current_blob.id_list.concat(cp.id_list);
+                                    current_blob.raw = current_blob.raw.concat(cp.raw);
                                 } else {
                                     current_blob.barcode = current_blob.copy_count;
                                     current_blob.call_number = { label : current_blob.cn_count };
@@ -812,6 +921,7 @@ function(egCore , $q) {
                                     current_blob = {};
                                     current_blob.index = index++;
                                     current_blob.id_list = cp.id_list;
+                                    current_blob.raw = cp.raw;
                                     current_blob.owner_label = cp.owner_label;
                                     current_blob.cn_count = 1;
                                     current_blob.copy_count = cp.copy_count;
@@ -844,29 +954,33 @@ function(egCore , $q) {
                     cp.call_number(cn);
                 });
 
-                var flat = egCore.idl.toHash(copies);
-                if (flat[0]) {
-                    var owner = egCore.org.get(flat[0].call_number.owning_lib);
+                var owner_id = cn.owning_lib();
+                var owner = egCore.org.get(owner_id);
 
-                    var owner_name_list = [];
-                    while (owner.parent_ou()) { // we're going to skip the top of the tree...
-                        owner_name_list.unshift(owner.name());
-                        owner = egCore.org.get(owner.parent_ou());
-                    }
+                var owner_name_list = [];
+                while (owner.parent_ou()) { // we're going to skip the top of the tree...
+                    owner_name_list.unshift(owner.name());
+                    owner = egCore.org.get(owner.parent_ou());
+                }
 
-                    angular.forEach(flat, function (cp) {
-                        cp.owner_list = owner_name_list;
-                        cp.id_list = [cp.id];
+                if (copies[0]) {
+                    var flat = [];
+                    angular.forEach(copies, function (cp) {
+                        var flat_cp = egCore.idl.toHash(cp);
+                        flat_cp.owner_id = owner_id;
+                        flat_cp.owner_list = owner_name_list;
+                        flat_cp.id_list = [flat_cp.id];
+                        flat_cp.raw = [cp];
+                        flat.push(flat_cp);
                     });
 
                     service.copies = service.copies.concat(flat);
-
-                    if (empty && flat.length == 0) {
-                        service.copies.push({
-                            owner_list : owner_name_list,
-                            call_number: egCore.idl.toHash(cn)
-                        });
-                    }
+                } else if (empty) {
+                    service.copies.push({
+                        owner_id   : owner_id,
+                        owner_list : owner_name_list,
+                        call_number: egCore.idl.toHash(cn)
+                    });
                 }
 
                 return cn;
index 02e462c..66a2bf3 100644 (file)
@@ -556,18 +556,22 @@ angular.module('egGridMod',
 
             // fires the hide handler function for a context action
             $scope.actionHide = function(action) {
-                if (!action.hide) {
+                if (typeof action.hide == 'undefined') {
                     return false;
                 }
-                return action.hide(action);
+                if (angular.isFunction(action.hide))
+                    return action.hide(action);
+                return action.hide;
             }
 
             // fires the disable handler function for a context action
             $scope.actionDisable = function(action) {
-                if (!action.disabled) {
+                if (typeof action.disabled == 'undefined') {
                     return false;
                 }
-                return action.disabled(action);
+                if (angular.isFunction(action.disabled))
+                    return action.disabled(action);
+                return action.disabled;
             }
 
             // fires the action handler function for a context action