LP#1402797 implement "delete all from catalog" for copy buckets
authorGalen Charlton <gmc@esilibrary.com>
Fri, 16 Jan 2015 22:12:01 +0000 (22:12 +0000)
committerBill Erickson <berickxx@gmail.com>
Wed, 25 Feb 2015 16:16:05 +0000 (11:16 -0500)
TODO: at present, this is pretty optimistic

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/cat/bucket/copy/index.tt2
Open-ILS/src/templates/staff/cat/bucket/copy/t_view.tt2
Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js

index 9b08f10..8a81f6d 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/copy/app.js"></script>
+<script>
+  angular.module('egCoreMod').run(['egStrings', function(s) {
+    s.CONFIRM_DELETE_COPY_BUCKET_ITEMS_FROM_CATALOG =
+      "[% l('Are you sure you want to delete all items in bucket from catalog?') %]";
+  }])
+</script>
 [% END %]
 
 <!-- using native Bootstrap taps because of limitations
index 336c1b7..e9446bd 100644 (file)
@@ -12,6 +12,8 @@
 
   <eg-grid-action label="[% l('Remove Selected Copies') %]" 
     handler="detachCopies"></eg-grid-action>
+  <eg-grid-action label="[% l('Delete All from Catalog') %]" 
+    handler="deleteCopiesFromCatalog"></eg-grid-action>
 
   <eg-grid-field path="id" required hidden></eg-grid-field>
   <eg-grid-field path="call_number.record.id" required hidden></eg-grid-field>
index 061a23b..3a9bf0e 100644 (file)
@@ -402,8 +402,10 @@ function($scope,  $routeParams,  bucketSvc , egGridDataProvider,   egCore) {
 }])
 
 .controller('ViewCtrl',
-       ['$scope','$q','$routeParams','bucketSvc',
-function($scope,  $q , $routeParams,  bucketSvc) {
+       ['$scope','$q','$routeParams','bucketSvc', 'egCore',
+        'egConfirmDialog',
+function($scope,  $q , $routeParams,  bucketSvc, egCore,
+         egConfirmDialog) {
 
     $scope.setTab('view');
     $scope.bucketId = $routeParams.id;
@@ -447,6 +449,40 @@ function($scope,  $q , $routeParams,  bucketSvc) {
         return $q.all(promises).then(drawBucket);
     }
 
+    $scope.deleteCopiesFromCatalog = function() {
+        egConfirmDialog.open(
+            egCore.strings.CONFIRM_DELETE_COPY_BUCKET_ITEMS_FROM_CATALOG,
+            '', {}
+        ).result.then(function() {
+            var fleshed_copies = [];
+            var promises = [];
+            angular.forEach(bucketSvc.currentBucket.items(), function(i) {
+                promises.push(
+                    egCore.net.request(
+                        'open-ils.search',
+                        'open-ils.search.asset.copy.fleshed2.retrieve',
+                        i.target_copy()
+                    ).then(function(copy) {
+                        copy.ischanged(1);
+                        copy.isdeleted(1);
+                        fleshed_copies.push(copy);
+                    })
+                );
+            });
+            $q.all(promises).then(function() {
+                egCore.net.request(
+                    'open-ils.cat',
+                    'open-ils.cat.asset.copy.fleshed.batch.update',
+                    egCore.auth.token(), fleshed_copies, true
+                ).then(function(resp) {
+                    // TODO deal with events that this method could return
+                    bucketSvc.bucketNeedsRefresh = true;
+                    drawBucket();
+                });
+            });
+        });
+    }
+
     // fetch the bucket;  on error show the not-allowed message
     if ($scope.bucketId) 
         drawBucket()['catch'](function() { $scope.forbidden = true });