LP#1715697: Ability to add empty volumes
authorMike Rylander <mrylander@gmail.com>
Wed, 25 Apr 2018 16:32:15 +0000 (12:32 -0400)
committerDan Wells <dbw2@calvin.edu>
Wed, 18 Jul 2018 13:40:39 +0000 (09:40 -0400)
Staff can add volumes to any library that is allowed to have holdings.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
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/services/holdings.js
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js

index 222ea20..545374f 100644 (file)
@@ -72,6 +72,8 @@
     <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="selectedHoldingsVolAdd" group="[% l('Add') %]"
+      label="[% l('Volumes') %]"></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') %]"
index 5debd68..fec7089 100644 (file)
@@ -1119,6 +1119,15 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         $scope.holdings_cb_changed(item.checkbox,item.checked);
     }
 
+    function gatherSelectedOwners () {
+        var owner_list = [];
+        angular.forEach(
+            $scope.holdingsGridControls.selectedItems(),
+            function (item) { owner_list.push(item.owner_id) }
+        );
+        return owner_list;
+    }
+
     function gatherSelectedHoldingsIds () {
         var cp_id_list = [];
         angular.forEach(
@@ -1278,18 +1287,28 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
     $scope.selectedHoldingsVolCopyAdd = function () { spawnHoldingsAdd(true,false) }
     $scope.selectedHoldingsCopyAdd = function () { spawnHoldingsAdd(false,true) }
 
-    spawnHoldingsEdit = function (hide_vols,hide_copies){
+    spawnHoldingsEdit = function (hide_vols,hide_copies,add_vol){
+
+        var raw;
+        if (add_vol) {
+            raw = [{callnumber:null}];
+        } else {
+            raw = gatherSelectedEmptyVolumeIds().map(
+                function(v){ return { callnumber : v } }
+            );
+        }
+
         egCore.net.request(
             'open-ils.actor',
             'open-ils.actor.anon_cache.set_value',
             null, 'edit-these-copies', {
                 record_id: $scope.record_id,
                 copies: gatherSelectedHoldingsIds(),
-                raw: gatherSelectedEmptyVolumeIds().map(
-                    function(v){ return { callnumber : v } }
-                ),
+                raw: raw,
                 hide_vols : hide_vols,
-                hide_copies : hide_copies
+                hide_copies : hide_copies,
+                only_add_vol : ((add_vol) ? true : false),
+                owners : gatherSelectedOwners()
             }
         ).then(function(key) {
             if (key) {
@@ -1304,6 +1323,8 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
     $scope.selectedHoldingsVolEdit = function () { spawnHoldingsEdit(false,true) }
     $scope.selectedHoldingsCopyEdit = function () { spawnHoldingsEdit(true,false) }
 
+    $scope.selectedHoldingsVolAdd = function () { spawnHoldingsEdit(false,true,true) }
+
     $scope.selectedHoldingsItemStatus = function (){
         var url = egCore.env.basePath + 'cat/item/search/' + gatherSelectedHoldingsIds().join(',')
         $timeout(function() { $window.open(url, '_blank') });
index b4fb738..ec387ec 100644 (file)
@@ -360,6 +360,15 @@ function(egCore , $q) {
                     }
                 });
 
+                function gatherSelectedOwners () {
+                    var owner_list = [];
+                    angular.forEach(
+                        $scope.holdingsGridControls.selectedItems(),
+                        function (item) { owner_list.push(item.owner_id) }
+                    );
+                    return owner_list;
+                }
+
                 function gatherHoldingsIds () {
                     var cp_id_list = [];
                     angular.forEach(
@@ -369,7 +378,7 @@ function(egCore , $q) {
                     return cp_id_list;
                 }
 
-                var spawn_volume_editor = function (copies_too) {
+                var spawn_volume_editor = function (copies_too,add_vol) {
                     egCore.net.request(
                         'open-ils.actor',
                         'open-ils.actor.anon_cache.set_value',
@@ -377,7 +386,9 @@ function(egCore , $q) {
                             record_id: $scope.recordId,
                             copies: gatherHoldingsIds(),
                             hide_vols : false,
-                            hide_copies : ((copies_too) ? false : true)
+                            hide_copies : ((copies_too) ? false : true),
+                            only_add_vol : ((add_vol) ? true : false),
+                            owners : gatherSelectedOwners()
                         }
                     ).then(function(key) {
                         if (key) {
@@ -399,11 +410,14 @@ function(egCore , $q) {
                         }
                     });
                 }
+                $scope.add_emtpy_volumes = function() {
+                    spawn_volume_editor(false,true);
+                }
                 $scope.edit_volumes = function() {
-                    spawn_volume_editor(false);
+                    spawn_volume_editor(false,false);
                 }
                 $scope.edit_copies = function() {
-                    spawn_volume_editor(true);
+                    spawn_volume_editor(true,false);
                 }
 
                 function load_holdings() {
index a744a0c..32222cf 100644 (file)
@@ -1367,11 +1367,19 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
         ).then(function (data) {
 
             if (data) {
+                var owners = [ egCore.auth.user().ws_ou() ];
+
                 if (data.hide_vols && !$scope.defaults.always_volumes) $scope.show_vols = false;
                 if (data.hide_copies) {
                     $scope.show_copies = false;
                     $scope.only_vols = true;
                 }
+                if (data.only_add_vol) {
+                    $scope.only_add_vol = true;
+                    $scope.only_vols = true;
+                    $scope.show_copies = false;
+                    owners = data.owners;
+                }
 
                 $scope.record_id = data.record_id;
 
@@ -1414,63 +1422,64 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                                     itemSvc.addCopy(cp)
                                 });
                             } else {
-                                var cn = new egCore.idl.acn();
-                                cn.id( --itemSvc.new_cn_id );
-                                cn.isnew( true );
-                                cn.prefix( $scope.defaults.prefix || -1 );
-                                cn.suffix( $scope.defaults.suffix || -1 );
-                                cn.owning_lib( proto.owner || egCore.auth.user().ws_ou() );
-                                cn.record( $scope.record_id );
-                                egCore.org.settings(
-                                    ['cat.default_classification_scheme'],
-                                    cn.owning_lib()
-                                ).then(function (val) {
-                                    cn.label_class(
-                                        $scope.defaults.classification ||
-                                        val['cat.default_classification_scheme'] ||
-                                        1
-                                    );
-                                    if (proto.label) {
-                                        cn.label( proto.label );
-                                    } else {
-                                        egCore.net.request(
-                                            'open-ils.cat',
-                                            'open-ils.cat.biblio.record.marc_cn.retrieve',
-                                            $scope.record_id,
-                                            cn.label_class()
-                                        ).then(function(cn_array) {
-                                            if (cn_array.length > 0) {
-                                                for (var field in cn_array[0]) {
-                                                    cn.label( cn_array[0][field] );
-                                                    break;
+                                angular.forEach(owners, function(owner) {
+                                    var cn = new egCore.idl.acn();
+                                    cn.id( --itemSvc.new_cn_id );
+                                    cn.isnew( true );
+                                    cn.prefix( $scope.defaults.prefix || -1 );
+                                    cn.suffix( $scope.defaults.suffix || -1 );
+                                    cn.owning_lib( owner );
+                                    cn.record( $scope.record_id );
+                                    egCore.org.settings(
+                                        ['cat.default_classification_scheme'],
+                                        cn.owning_lib()
+                                    ).then(function (val) {
+                                        cn.label_class(
+                                            $scope.defaults.classification ||
+                                            val['cat.default_classification_scheme'] ||
+                                            1
+                                        );
+                                        if (proto.label) {
+                                            cn.label( proto.label );
+                                        } else {
+                                            egCore.net.request(
+                                                'open-ils.cat',
+                                                'open-ils.cat.biblio.record.marc_cn.retrieve',
+                                                $scope.record_id,
+                                                cn.label_class()
+                                            ).then(function(cn_array) {
+                                                if (cn_array.length > 0) {
+                                                    for (var field in cn_array[0]) {
+                                                        cn.label( cn_array[0][field] );
+                                                        break;
+                                                    }
                                                 }
-                                            }
-                                        });
-                                    }
-                                });
+                                            });
+                                        }
+                                    });
 
-                                var cp = new itemSvc.generateNewCopy(
-                                    cn,
-                                    proto.owner || egCore.auth.user().ws_ou(),
-                                    $scope.is_fast_add,
-                                    true
-                                );
+                                    var cp = new itemSvc.generateNewCopy(
+                                        cn,
+                                        proto.owner || egCore.auth.user().ws_ou(),
+                                        $scope.is_fast_add,
+                                        true
+                                    );
 
-                                if (proto.barcode) {
-                                    cp.barcode( proto.barcode );
-                                    cp.empty_barcode = false;
-                                }
+                                    if (proto.barcode) {
+                                        cp.barcode( proto.barcode );
+                                        cp.empty_barcode = false;
+                                    }
 
-                                itemSvc.addCopy(cp)
+                                    itemSvc.addCopy(cp)
+                                });
                             }
-    
                         }
                     );
 
                     return itemSvc.copies;
                 }
 
-                if (data.copies && data.copies.length)
+                if (!$scope.only_add_vol && data.copies && data.copies.length)
                     return itemSvc.fetchIds(data.copies).then(fetchRaw);
 
                 return fetchRaw();
@@ -1485,16 +1494,24 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
         $scope.can_save = false;
         function check_saveable () {
             var can_save = true;
+
             angular.forEach(
                 itemSvc.copies,
                 function (i) {
-                    if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label)
+                    if (!$scope.only_add_vol) {
+                        if (i.duplicate_barcode || i.empty_barcode || i.call_number().empty_label) {
+                            can_save = false;
+                        }
+                    } else if (i.call_number().empty_label) {
                         can_save = false;
+                    }
                 }
             );
+
             if ($scope.forms.myForm && $scope.forms.myForm.$invalid) {
                 can_save = false;
             }
+
             $scope.can_save = can_save;
         }
 
@@ -1781,9 +1798,15 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                     cnHash[cn_id].suffix(cnHash[cn_id].suffix().id()); // un-object-ize some fields
             });
 
-            angular.forEach(perCnCopies, function (v, k) {
-                cnHash[k].copies(v);
-            });
+            if ($scope.only_add_vol) { // strip off copies when we're in add-empty-vol mode
+                angular.forEach(cnHash, function (v, k) {
+                    cnHash[k].copies([]);
+                });
+            } else {
+                angular.forEach(perCnCopies, function (v, k) {
+                    cnHash[k].copies(v);
+                });
+            }
 
             cnList = [];
             angular.forEach(cnHash, function (v, k) {