From c07ca27204a4872d66b8fdebc89d7cf76cac8353 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Thu, 6 Jul 2017 10:41:24 -0400 Subject: [PATCH] serials: Confirm scap delete, and protect it with an ML method Signed-off-by: Mike Rylander --- .../src/perlmods/lib/OpenILS/Application/Serial.pm | 35 ++++++++++++++++++++ Open-ILS/src/templates/staff/serials/index.tt2 | 4 +++ .../staff/serials/directives/prediction_manager.js | 37 +++++++++++++++------- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm index fed5604a28..e6bca9fed8 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm @@ -2495,6 +2495,18 @@ __PACKAGE__->register_method( __PACKAGE__->register_method( method => 'safe_delete', + api_name => 'open-ils.serial.caption_and_pattern.safe_delete', + signature => q/ + Deletes an existing caption and pattern object, but only + if there are no attached serial issuances. + @param authtoken The login session key + @param strid The id of the scap to delete + @return 1 on success - Event otherwise. + / +); + +__PACKAGE__->register_method( + method => 'safe_delete', api_name => 'open-ils.serial.subscription.safe_delete.dry_run', ); __PACKAGE__->register_method( @@ -2505,6 +2517,10 @@ __PACKAGE__->register_method( method => 'safe_delete', api_name => 'open-ils.serial.stream.safe_delete.dry_run', ); +__PACKAGE__->register_method( + method => 'safe_delete', + api_name => 'open-ils.serial.caption_and_pattern.safe_delete.dry_run', +); sub safe_delete { my( $self, $conn, $authtoken, $id ) = @_; @@ -2569,6 +2585,24 @@ sub safe_delete { $obj = $sdist; + } elsif ($type eq 'caption_and_pattern') { + my $scap = $e->retrieve_serial_caption_and_pattern([ + $id, + { flesh => 1, flesh_fields => { scap => ['subscription'] } } + ]) or return $e->die_event; + + return $e->die_event unless + $e->allowed("ADMIN_SERIAL_CAPTION_PATTERN", $scap->subscription->owning_lib); + + my $siss = $e->search_serial_issuance({ + caption_and_pattern => $id + }); + + return OpenILS::Event->new('SERIAL_CAPTION_AND_PATTERN_HAS_ISSUANCES', payload=>$id) + if (@$siss); + + $obj = $scap; + } else { # subscription my $sub = $e->retrieve_serial_subscription([ $id, { @@ -2605,6 +2639,7 @@ sub safe_delete { $e->$method($obj) or return $e->die_event; $e->commit; } + return 1; } diff --git a/Open-ILS/src/templates/staff/serials/index.tt2 b/Open-ILS/src/templates/staff/serials/index.tt2 index 16e35a10e8..17f152b403 100644 --- a/Open-ILS/src/templates/staff/serials/index.tt2 +++ b/Open-ILS/src/templates/staff/serials/index.tt2 @@ -33,6 +33,8 @@ angular.module('egCoreMod').run(['egStrings', function(s) { s.SERIALS_DISTRIBUTION_FAIL_DELETE = "[% l('Failed to delete serial distribution') %]"; s.SERIALS_STREAM_SUCCESS_DELETE = "[% l('Deleted serial stream') %]"; s.SERIALS_STREAM_FAIL_DELETE = "[% l('Failed to delete serial stream') %]"; + s.SERIALS_SCAP_SUCCESS_DELETE = "[% l('Deleted serial prediction pattern') %]"; + s.SERIALS_SCAP_FAIL_DELETE = "[% l('Failed to delete serial prediction pattern') %]"; s.SERIALS_ISSUANCE_FAIL_SAVE = "[% l('Failed to save issuance') %]"; s.SERIALS_ISSUANCE_SUCCESS_SAVE = "[% l('Issuance saved') %]"; s.SERIALS_DISTRIBUTION_SUCCESS_LINK_MFHD = "[% l('Distribution linked to MFHD') %]"; @@ -50,6 +52,8 @@ angular.module('egCoreMod').run(['egStrings', function(s) { s.CONFIRM_DELETE_DISTRIBUTION_MESSAGE = "[% l('Will delete {{count}} distribution(s)') %]"; s.CONFIRM_DELETE_STREAM = "[% l('Delete selected stream(s)?') %]"; s.CONFIRM_DELETE_STREAM_MESSAGE = "[% l('Will delete {{count}} stream(s)') %]"; + s.CONFIRM_DELETE_SCAP = "[% l('Delete prediction pattern?') %]"; + s.CONFIRM_DELETE_SCAP_MESSAGE = "[% l('Will delete the prediction pattern if there are no attached issuances.') %]"; s.CONFIRM_CHANGE_ITEMS = {}; s.CONFIRM_CHANGE_ITEMS_MESSAGE = {}; diff --git a/Open-ILS/web/js/ui/default/staff/serials/directives/prediction_manager.js b/Open-ILS/web/js/ui/default/staff/serials/directives/prediction_manager.js index eb588536b5..2390f69470 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/directives/prediction_manager.js +++ b/Open-ILS/web/js/ui/default/staff/serials/directives/prediction_manager.js @@ -11,9 +11,9 @@ angular.module('egSerialsAppDep') templateUrl: './serials/t_prediction_manager', controller: ['$scope','$q','egSerialsCoreSvc','egCore','egGridDataProvider', - '$uibModal','$timeout','$location', + '$uibModal','$timeout','$location','egConfirmDialog','ngToast', function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , - $uibModal , $timeout , $location) { + $uibModal , $timeout , $location , egConfirmDialog , ngToast) { $scope.has_pattern_to_import = false; egSerialsCoreSvc.fetch($scope.bibId).then(function() { @@ -66,18 +66,31 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , } $scope.deleteScap = function(pred) { var scap = egCore.idl.fromTypedHash(pred); - // TODO ask to confirm - // TODO check whether there are linked issuances - egCore.pcrud.remove(scap).then(function() { - // completely reset the model in order to reset the - // forms; causes a blink, alas - $scope.predictions = []; - egSerialsCoreSvc.fetch($scope.bibId).then(function() { - reload($scope.ssubId); - }); + egConfirmDialog.open( + egCore.strings.CONFIRM_DELETE_SCAP, + egCore.strings.CONFIRM_DELETE_SCAP_MESSAGE, + {} + ).result.then(function () { + egCore.net.request( + 'open-ils.serial', + 'open-ils.serial.caption_and_pattern.safe_delete', + egCore.auth.token(), + scap.id() + ).then(function(resp){ + var evt = egCore.evt.parse(resp); + if (evt) { + ngToast.danger(egCore.strings.SERIALS_SCAP_FAIL_DELETE + ' : ' + evt.desc); + } else { + ngToast.success(egCore.strings.SERIALS_SCAP_SUCCESS_DELETE); + } + + $scope.predictions = []; + egSerialsCoreSvc.fetch($scope.bibId).then(function() { + reload($scope.ssubId); + }); + }) }); } - $scope.cancelNewScap = function() { $scope.new_prediction = null; } -- 2.11.0