From: Galen Charlton Date: Mon, 26 Jan 2015 22:30:03 +0000 (+0000) Subject: LP#1402797 add "Delete Selected Records From Catalog" action to record buckets X-Git-Tag: sprint4-merge-nov22~1544 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b149ca10bf198aa3fd00546e3f43a9a8b25a9138;p=working%2FEvergreen.git LP#1402797 add "Delete Selected Records From Catalog" action to record buckets Signed-off-by: Galen Charlton Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/templates/staff/cat/bucket/record/index.tt2 b/Open-ILS/src/templates/staff/cat/bucket/record/index.tt2 index 2f21e7258c..2c45eff177 100644 --- a/Open-ILS/src/templates/staff/cat/bucket/record/index.tt2 +++ b/Open-ILS/src/templates/staff/cat/bucket/record/index.tt2 @@ -9,6 +9,12 @@ + [% END %] + diff --git a/Open-ILS/src/templates/staff/cat/bucket/record/t_view.tt2 b/Open-ILS/src/templates/staff/cat/bucket/record/t_view.tt2 index b6768c5e9f..9ff16bfbb3 100644 --- a/Open-ILS/src/templates/staff/cat/bucket/record/t_view.tt2 +++ b/Open-ILS/src/templates/staff/cat/bucket/record/t_view.tt2 @@ -16,6 +16,9 @@ + + diff --git a/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js b/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js index 3bcd714668..c2df9cd8f1 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js @@ -195,6 +195,24 @@ angular.module('egCatRecordBuckets', return deferred.promise; } + service.deleteRecordFromCatalog = function(recordId) { + var deferred = $q.defer(); + + egCore.net.request( + 'open-ils.cat', + 'open-ils.cat.biblio.record_entry.delete', + egCore.auth.token(), recordId + ).then(function(resp) { + // rather than rejecting the promise in the + // case of a failure, we'll let the caller + // look for errors -- doing this because AngularJS + // does not have a native $q.allSettled() yet. + deferred.resolve(resp); + }); + + return deferred.promise; + } + // delete bucket by ID. // resolved w/ response on successful delete, // rejected otherwise. @@ -486,9 +504,9 @@ function($scope, $routeParams, bucketSvc , egGridDataProvider) { .controller('ViewCtrl', ['$scope','$q','$routeParams','bucketSvc', 'egCore', '$window', - '$timeout', + '$timeout', 'egConfirmDialog', '$modal', function($scope, $q , $routeParams, bucketSvc, egCore, $window, - $timeout) { + $timeout, egConfirmDialog, $modal) { $scope.setTab('view'); $scope.bucketId = $routeParams.id; @@ -544,6 +562,42 @@ function($scope, $q , $routeParams, bucketSvc, egCore, $window, return $q.all(promises).then(drawBucket); } + $scope.deleteRecordsFromCatalog = function(records) { + egConfirmDialog.open( + egCore.strings.CONFIRM_DELETE_RECORD_BUCKET_ITEMS_FROM_CATALOG, + '', + {} + ).result.then(function() { + var promises = []; + angular.forEach(records, function(rec) { + promises.push(bucketSvc.deleteRecordFromCatalog(rec.id)); + }); + bucketSvc.bucketNeedsRefresh = true; + return $q.all(promises).then(function(results) { + var failures = results.filter(function(result) { + return egCore.evt.parse(result); + }).map(function(result) { + var evt = egCore.evt.parse(result); + if (evt) { + return { recordId: evt.payload, desc: evt.desc }; + } + }); + if (failures.length) { + $modal.open({ + templateUrl: './cat/bucket/record/t_records_not_deleted', + controller : + ['$scope', '$modalInstance', function($scope, $modalInstance) { + $scope.failures = failures; + $scope.ok = function() { $modalInstance.close() } + $scope.cancel = function() { $modalInstance.dismiss() } + }] + }); + } + drawBucket(); + }); + }); + } + // fetch the bucket; on error show the not-allowed message if ($scope.bucketId) drawBucket()['catch'](function() { $scope.forbidden = true });