LP#1402797 add "Delete Selected Records From Catalog" action to record buckets
authorGalen Charlton <gmc@esilibrary.com>
Mon, 26 Jan 2015 22:30:03 +0000 (22:30 +0000)
committerBill Erickson <berickxx@gmail.com>
Wed, 25 Feb 2015 16:16:06 +0000 (11:16 -0500)
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/cat/bucket/record/index.tt2
Open-ILS/src/templates/staff/cat/bucket/record/t_records_not_deleted.tt2 [new file with mode: 0644]
Open-ILS/src/templates/staff/cat/bucket/record/t_view.tt2
Open-ILS/web/js/ui/default/staff/cat/bucket/record/app.js

index 2f21e72..2c45eff 100644 (file)
@@ -9,6 +9,12 @@
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/grid.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/ui.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/cat/bucket/record/app.js"></script>
+<script>
+  angular.module('egCoreMod').run(['egStrings', function(s) {
+    s.CONFIRM_DELETE_RECORD_BUCKET_ITEMS_FROM_CATALOG =
+      "[% l('Delete these records?') %]";
+  }]);
+</script>
 [% END %]
 
 <!-- using native Bootstrap taps because of limitations
diff --git a/Open-ILS/src/templates/staff/cat/bucket/record/t_records_not_deleted.tt2 b/Open-ILS/src/templates/staff/cat/bucket/record/t_records_not_deleted.tt2
new file mode 100644 (file)
index 0000000..fc8520f
--- /dev/null
@@ -0,0 +1,19 @@
+<div class="modal-dialog">
+  <div class="modal-content">
+    <div class="modal-header">
+      <button type="button" class="close" 
+        ng-click="cancel()" aria-hidden="true">&times;</button>
+      <h4 class="modal-title">[% l('Records That Could Not Be Deleted') %]</h4>
+    </div>
+    <div class="modal-body">
+      <ul>
+        <li ng-repeat="failure in failures">
+            {{failure.recordId}} / {{failure.desc}}
+        </li>
+      </ul>
+    </div>
+    <div class="modal-footer">
+      <button class="btn btn-primary" ng-click="ok()">[% l('OK') %]</button>
+    </div>
+  </div> <!-- modal-content -->
+</div> <!-- modal-dialog -->
index b6768c5..9ff16bf 100644 (file)
@@ -16,6 +16,9 @@
   <eg-grid-action label="[% l('Remove Selected Records') %]" 
     handler="detachRecords"></eg-grid-action>
 
+  <eg-grid-action label="[% l('Delete Selected Records from Catalog') %]" 
+    handler="deleteRecordsFromCatalog"></eg-grid-action>
+
   <eg-grid-action label="[% l('Export Records') %]" 
     handler="openExportBucketDialog"></eg-grid-action>
 
index 3bcd714..c2df9cd 100644 (file)
@@ -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 });