webstaff: Support adding copies and volumes
authorMike Rylander <mrylander@gmail.com>
Thu, 3 Sep 2015 13:11:30 +0000 (09:11 -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/cat/volcopy/app.js

index 27d434a..5ef56d1 100644 (file)
     <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="selectedHoldingsCopyAdd" group="[% l('Add') %]" disabled="vols_not_shown"
+      label="[% l('Copies') %]"></eg-grid-action>
+    <eg-grid-action handler="selectedHoldingsVolCopyAdd" group="[% l('Add') %]"
+      label="[% l('Volumes and Copies') %]"></eg-grid-action>
+
     <eg-grid-action handler="selectedHoldingsVolEdit" group="[% l('Edit') %]"
       label="[% l('Volumes') %]"></eg-grid-action>
     <eg-grid-action handler="selectedHoldingsCopyEdit" group="[% l('Edit') %]"
index c108774..3dcea57 100644 (file)
@@ -354,6 +354,42 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         return cn_id_list;
     }
 
+    spawnHoldingsAdd = function (hide_vols,hide_copies){
+        var raw = [];
+        if (hide_vols) { // just a copy on existing volumes
+            angular.forEach(gatherSelectedVolumeIds(), function (v) {
+                raw.push( {callnumber : v} );
+            });
+        } else {
+            angular.forEach(
+                $scope.holdingsGridControls.selectedItems(),
+                function (item) {
+                    raw.push({owner : item.owner_id});
+                }
+            );
+        }
+
+        egCore.net.request(
+            'open-ils.actor',
+            'open-ils.actor.anon_cache.set_value',
+            null, 'edit-these-copies', {
+                record_id: $scope.record_id,
+                raw: raw,
+                hide_vols : hide_vols,
+                hide_copies : hide_copies
+            }
+        ).then(function(key) {
+            if (key) {
+                var url = egCore.env.basePath + 'cat/volcopy/' + key;
+                $timeout(function() { $window.open(url, '_blank') });
+            } else {
+                alert('Could not create anonymous cache key!');
+            }
+        });
+    }
+    $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(false,false) }
+    $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(true,false) }
+
     spawnHoldingsEdit = function (hide_vols,hide_copies){
         egCore.net.request(
             'open-ils.actor',
@@ -864,6 +900,7 @@ function(egCore , $q) {
                             current_blob.call_number = cp.call_number;
                             current_blob.owner_list = cp.owner_list;
                             current_blob.owner_label = cp.owner_label;
+                            current_blob.owner_id = cp.owner_id;
                         } else {
                             var current_key = cp.owner_list.join('') + cp.call_number.label;
                             if (prev_key == current_key) { // collapse into current_blob
@@ -880,6 +917,7 @@ function(egCore , $q) {
                                 current_blob.id_list = cp.id_list;
                                 current_blob.raw = cp.raw;
                                 current_blob.owner_label = cp.owner_label;
+                                current_blob.owner_id = cp.owner_id;
                                 current_blob.call_number = cp.call_number;
                                 current_blob.owner_list = cp.owner_list;
                             }
@@ -906,6 +944,7 @@ function(egCore , $q) {
                                 current_blob.copy_count = cp.copy_count;
                                 current_blob.owner_list = cp.owner_list;
                                 current_blob.owner_label = cp.owner_label;
+                                current_blob.owner_id = cp.owner_id;
                             } else {
                                 var current_key = cp.owner_list.join('');
                                 if (prev_key == current_key) { // collapse into current_blob
@@ -923,6 +962,7 @@ function(egCore , $q) {
                                     current_blob.id_list = cp.id_list;
                                     current_blob.raw = cp.raw;
                                     current_blob.owner_label = cp.owner_label;
+                                    current_blob.owner_id = cp.owner_id;
                                     current_blob.cn_count = 1;
                                     current_blob.copy_count = cp.copy_count;
                                     current_blob.owner_list = cp.owner_list;
index 638a77f..8cd4b78 100644 (file)
@@ -32,6 +32,8 @@ angular.module('egVolCopy',
 function(egCore , $q) {
 
     var service = {
+        new_cp_id : 0,
+        new_cn_id : 0,
         tree : {}, // holds lib->cn->copy hash stack
         copies : [] // raw copy list
     };
@@ -282,7 +284,6 @@ function(egCore , $q) {
         scope: {allcopies: "=", copies: "=" },
         controller : ['$scope','itemSvc','egCore',
             function ( $scope , itemSvc , egCore ) {
-                $scope.new_cp_id = 0;
                 $scope.callNumber =  $scope.copies[0].call_number();
 
                 $scope.idTracker = function (x) { if (x) return x.id() };
@@ -391,7 +392,7 @@ function(egCore , $q) {
                 $scope.changeCPCount = function () {
                     while ($scope.copy_count > $scope.copies.length) {
                         var cp = new egCore.idl.acp();
-                        cp.id( --$scope.new_cp_id );
+                        cp.id( --itemSvc.new_cp_id );
                         cp.isnew( true );
                         cp.circ_lib( $scope.lib );
                         cp.call_number( $scope.callNumber );
@@ -437,7 +438,6 @@ function(egCore , $q) {
         scope: { allcopies: "=", struct: "=", lib: "@", record: "@" },
         controller : ['$scope','itemSvc','egCore',
             function ( $scope , itemSvc , egCore ) {
-                $scope.new_cn_id = 0;
                 $scope.first_cn = Object.keys($scope.struct)[0];
                 $scope.full_cn = $scope.struct[$scope.first_cn][0].call_number();
 
@@ -458,13 +458,13 @@ function(egCore , $q) {
                     if (n > o) { // adding
                         for (var i = o; o < n; o++) {
                             var cn = new egCore.idl.acn();
-                            cn.id( --$scope.new_cn_id );
+                            cn.id( --itemSvc.new_cn_id );
                             cn.isnew( true );
                             cn.owning_lib( $scope.owning_lib.id() );
                             cn.record( $scope.full_cn.record() );
 
                             var cp = new egCore.idl.acp();
-                            cp.id( --$scope.new_cp_id );
+                            cp.id( --itemSvc.new_cp_id );
                             cp.isnew( true );
                             cp.circ_lib( $scope.owning_lib.id() );
                             cp.call_number( cn );
@@ -810,17 +810,51 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
 
                 if (data.raw && data.raw.length) {
 
-                    /* data.raw must be an array of copies with (at least)
-                     * the call number fleshed on each.  For new copies
-                     * create from whole cloth, the id for each should
-                     * probably be negative and isnew() should return true.
-                     * Each /distinct/ call number must have a distinct id
-                     * as well, probably negative also if they're new. Clear?
+                    /* data.raw data structure looks like this:
+                     * [{
+                     *      callnumber : $cn_id, // optional, to add a copy to a cn
+                     *      owner      : $org, // optional, defaults to ws_ou
+                     *      label      : $cn_label, // optional, to supply a label on a new cn
+                     *      barcode    : $cp_barcode // optional, to supply a barcode on a new cp
+                     * },...]
+                     * 
+                     * All can be left out and a completely empty vol/copy combo will be vivicated.
                      */
 
                     angular.forEach(
                         data.raw,
-                        function (cp) { itemSvc.addCopy(cp) }
+                        function (proto) {
+                            if (proto.callnumber) {
+                                return egCore.pcrud.retrieve('acn', proto.callnumber)
+                                .then(function(cn) {
+                                    var cp = new egCore.idl.acp();
+                                    cp.call_number( cn );
+                                    cp.id( --itemSvc.new_cp_id );
+                                    cp.isnew( true );
+                                    cp.circ_lib( $scope.record_id );
+                                    if (proto.barcode) cp.barcode( proto.barcode );
+
+                                    itemSvc.addCopy(cp)
+                                });
+                            } else {
+                                var cn = new egCore.idl.acn();
+                                cn.id( --itemSvc.new_cn_id );
+                                cn.isnew( true );
+                                cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
+                                cn.record( $scope.record_id );
+                                if (proto.label) cn.label( proto.label );
+
+                                var cp = new egCore.idl.acp();
+                                cp.call_number( cn );
+                                cp.id( --itemSvc.new_cp_id );
+                                cp.isnew( true );
+                                cp.circ_lib( $scope.record_id );
+                                if (proto.barcode) cp.barcode( proto.barcode );
+
+                                itemSvc.addCopy(cp)
+                            }
+    
+                        }
                     );
 
                     return itemSvc.copies;