From 9c6d3c2f9d0e559c806988d8013fd0dd98e39a22 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Wed, 9 Sep 2015 18:02:06 -0400 Subject: [PATCH] webstaff: Transfer Copies to Marked Volume in Copy Bucket Signed-off-by: Jason Etheridge Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- .../src/perlmods/lib/OpenILS/Application/Cat.pm | 70 ++++++++++++++++++++++ .../src/templates/staff/cat/bucket/copy/index.tt2 | 6 ++ .../src/templates/staff/cat/bucket/copy/t_view.tt2 | 2 + .../web/js/ui/default/staff/cat/bucket/copy/app.js | 46 ++++++++++++++ 4 files changed, 124 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index 4a5d1b3957..91566c2aed 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -756,6 +756,76 @@ sub reset_hold_list { $ses->request('open-ils.circ.hold.reset.batch', $auth, $hold_ids); } +__PACKAGE__->register_method( + method => "transfer_copies_to_volume", + api_name => "open-ils.cat.transfer_copies_to_volume", + argc => 3, + signature => { + desc => 'Transfers specified copies to the specified call number, and changes Circ Lib to match the new Owning Lib.', + params => [ + {desc => 'Authtoken', type => 'string'}, + {desc => 'Call Number ID', type => 'number'}, + {desc => 'Array of Copy IDs', type => 'array'}, + ] + }, + return => {desc => '1 on success, Event on error'} +); + +__PACKAGE__->register_method( + method => "transfer_copies_to_volume", + api_name => "open-ils.cat.transfer_copies_to_volume.override",); + +sub transfer_copies_to_volume { + my( $self, $conn, $auth, $volume, $copies, $oargs ) = @_; + my $delete_stats = 1; + my $force_delete_empty_bib = undef; + my $create_parts = undef; + + # initial tests + + return 1 unless ref $copies; + my( $reqr, $evt ) = $U->checkses($auth); + return $evt if $evt; + my $editor = new_editor(requestor => $reqr, xact => 1); + if ($self->api_name =~ /override/) { + $oargs = { all => 1 } unless defined $oargs; + } else { + $oargs = {}; + } + + # does the volume exist? good, we also need its owning_lib later + my( $cn, $cn_evt ) = $U->fetch_callnumber( $volume, 0, $editor ); + return $cn_evt if $cn_evt; + + # flesh and munge the copies + my $fleshed_copies = []; + my ($copy, $copy_evt); + foreach my $copy_id ( @{ $copies } ) { + ($copy, $copy_evt) = $U->fetch_copy($copy_id); + return $copy_evt if $copy_evt; + $copy->call_number( $volume ); + $copy->circ_lib( $cn->owning_lib() ); + $copy->ischanged( 't' ); + push @$fleshed_copies, $copy; + } + + # actual work + my $retarget_holds = []; + $evt = OpenILS::Application::Cat::AssetCommon->update_fleshed_copies( + $editor, $oargs, undef, $fleshed_copies, $delete_stats, $retarget_holds, $force_delete_empty_bib, $create_parts); + + if( $evt ) { + $logger->info("copy to volume transfer failed with event: ".OpenSRF::Utils::JSON->perl2JSON($evt)); + $editor->rollback; + return $evt; + } + + $editor->commit; + $logger->info("copy to volume transfer successfully updated ".scalar(@$copies)." copies"); + reset_hold_list($auth, $retarget_holds); + + return 1; +} __PACKAGE__->register_method( method => 'in_db_merge', diff --git a/Open-ILS/src/templates/staff/cat/bucket/copy/index.tt2 b/Open-ILS/src/templates/staff/cat/bucket/copy/index.tt2 index db0e6dcff3..aa80153def 100644 --- a/Open-ILS/src/templates/staff/cat/bucket/copy/index.tt2 +++ b/Open-ILS/src/templates/staff/cat/bucket/copy/index.tt2 @@ -17,6 +17,12 @@ "[% l('One or more items could not be deleted. Override?') %]"; s.OVERRIDE_DELETE_COPY_BUCKET_ITEMS_FROM_CATALOG_BODY = "[% l('Reason(s) include: [_1]', '{{evt_desc}}') %]"; + s.CONFIRM_TRANSFER_COPY_BUCKET_ITEMS_TO_MARKED_VOLUME = + "[% l('Are you sure you want to transfer selected items to the marked volume?') %]"; + s.OVERRIDE_TRANSFER_COPY_BUCKET_ITEMS_TO_MARKED_VOLUME_TITLE = + "[% l('One or more items could not be transferred. Override?') %]"; + s.OVERRIDE_TRANSFER_COPY_BUCKET_ITEMS_TO_MARKED_VOLUME_BODY = + "[% l('Reason(s) include: [_1]', '{{evt_desc}}') %]"; }]) [% END %] diff --git a/Open-ILS/src/templates/staff/cat/bucket/copy/t_view.tt2 b/Open-ILS/src/templates/staff/cat/bucket/copy/t_view.tt2 index 420dd8052c..6a66ed66f9 100644 --- a/Open-ILS/src/templates/staff/cat/bucket/copy/t_view.tt2 +++ b/Open-ILS/src/templates/staff/cat/bucket/copy/t_view.tt2 @@ -16,6 +16,8 @@ handler="spawnHoldingsEdit"> + diff --git a/Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js b/Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js index c866a65ecc..ebc4bb96c1 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js @@ -602,6 +602,52 @@ function($scope, $q , $routeParams , $timeout , $window , $modal , bucketSvc , }); } + $scope.transferCopies = function(copies) { + var xfer_target = egCore.hatch.getLocalItem('eg.cat.item_transfer_target'); + var copy_ids = copies.map( + function(curr,idx,arr) { + return curr.id; + } + ); + if (xfer_target) { + egCore.net.request( + 'open-ils.cat', + 'open-ils.cat.transfer_copies_to_volume', + egCore.auth.token(), + xfer_target, + copy_ids + ).then( + function(resp) { // oncomplete + var evt = egCore.evt.parse(resp); + if (evt) { + egConfirmDialog.open( + egCore.strings.OVERRIDE_TRANSFER_COPY_BUCKET_ITEMS_TO_MARKED_VOLUME_TITLE, + egCore.strings.OVERRIDE_TRANSFER_COPY_BUCKET_ITEMS_TO_MARKED_VOLUME_BODY, + {'evt_desc': evt.desc} + ).result.then(function() { + egCore.net.request( + 'open-ils.cat', + 'open-ils.cat.transfer_copies_to_volume.override', + egCore.auth.token(), + xfer_target, + copy_ids, + { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] } + ).then(function(resp) { + bucketSvc.bucketNeedsRefresh = true; + drawBucket(); + }); + }); + } else { + bucketSvc.bucketNeedsRefresh = true; + drawBucket(); + } + }, + null, // onerror + null // onprogress + ) + } + } + // fetch the bucket; on error show the not-allowed message if ($scope.bucketId) drawBucket()['catch'](function() { $scope.forbidden = true }); -- 2.11.0