From 46f1f53051665a9a8b6358ed9d61f541d071a8ff Mon Sep 17 00:00:00 2001
From: Jane Sandberg <sandbej@linnbenton.edu>
Date: Thu, 17 Oct 2019 11:11:34 -0700
Subject: [PATCH] LP1735566: Ask before deleting items in non-ideal statuses in
 AngularJS

To test:

1) Apply this commit.
2) Log in as a user with COPY_DELETE_WARNING.override permission.
3) Go to item status and scan an item in a non-ideal status (like #1:
checked out)
4) Delete the item.  Note that you are alerted of the item's non-ideal
status, and you can confirm that you actually want to delete it.
5) Repeat steps 3-4 with an item in an ideal status (like #0:
Available). Note that no such alert appears.
6) Open the holdings view and repeat steps 4-5.
7) Log in as a user without the COPY_DELETE_WARNING.override
permission. Note that you are still informed about the non-ideal status,
but you aren't able to continue with the deletion without an admin
using their credentials.

Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Garry Collum <gcollum@gmail.com>
Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
---
 Open-ILS/src/templates/staff/cat/catalog/index.tt2 |  4 +++
 .../templates/staff/circ/share/circ_strings.tt2    |  4 +++
 .../web/js/ui/default/staff/cat/catalog/app.js     | 30 ++++++++++++++++++----
 .../web/js/ui/default/staff/circ/services/item.js  | 25 +++++++++++++++---
 4 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/Open-ILS/src/templates/staff/cat/catalog/index.tt2 b/Open-ILS/src/templates/staff/cat/catalog/index.tt2
index 6db7ceee76..be572de284 100644
--- a/Open-ILS/src/templates/staff/cat/catalog/index.tt2
+++ b/Open-ILS/src/templates/staff/cat/catalog/index.tt2
@@ -31,6 +31,10 @@
       "[% l('Permanently delete selected items and/or call numbers from catalog?') %]";
     s.CONFIRM_DELETE_COPIES_VOLUMES_MESSAGE =
       "[% l('Will delete {{copies}} items and {{volumes}} call numbers') %]";
+    s.OVERRIDE_DELETE_ITEMS_FROM_CATALOG_TITLE =
+      "[% l('One or more items could not be deleted. Override?') %]";
+    s.OVERRIDE_DELETE_ITEMS_FROM_CATALOG_BODY =
+      "[% l('Reason(s) include: [_1]', '{{evt_desc}}') %]";
     s.CONFIRM_DELETE_PEERS =
       "[% l('Unlink selected conjoined items?') %]";
     s.CONFIRM_DELETE_PEERS_MESSAGE =
diff --git a/Open-ILS/src/templates/staff/circ/share/circ_strings.tt2 b/Open-ILS/src/templates/staff/circ/share/circ_strings.tt2
index 5e40fb520d..9849afeceb 100644
--- a/Open-ILS/src/templates/staff/circ/share/circ_strings.tt2
+++ b/Open-ILS/src/templates/staff/circ/share/circ_strings.tt2
@@ -66,6 +66,10 @@ s.ON_DEMAND_COPY_ALERT = {
         'CLAIMSNEVERCHECKEDOUT' : '[% l("Item was marked claims never checked out") %]'
     }
 };
+s.OVERRIDE_DELETE_ITEMS_FROM_CATALOG_TITLE =
+  "[% l('One or more items could not be deleted. Override?') %]";
+s.OVERRIDE_DELETE_ITEMS_FROM_CATALOG_BODY =
+  "[% l('Reason(s) include: [_1]', '{{evt_desc}}') %]";
 }]);
 </script>
 
diff --git a/Open-ILS/web/js/ui/default/staff/cat/catalog/app.js b/Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
index 0793e0106b..f05c363295 100644
--- a/Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
+++ b/Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
@@ -1301,12 +1301,32 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         ).result.then(function() {
             egCore.net.request(
                 'open-ils.cat',
-                'open-ils.cat.asset.volume.fleshed.batch.update.override',
+                'open-ils.cat.asset.volume.fleshed.batch.update',
                 egCore.auth.token(), cnList, 1, flags
-            ).then(function(update_count) {
-                holdingsSvcInst.fetchAgain().then(function() {
-                    $scope.holdingsGridDataProvider.refresh();
-                });
+            ).then(function(resp) {
+                var evt = egCore.evt.parse(resp);
+                if (evt) {
+                    egConfirmDialog.open(
+                        egCore.strings.OVERRIDE_DELETE_ITEMS_FROM_CATALOG_TITLE,
+                        egCore.strings.OVERRIDE_DELETE_ITEMS_FROM_CATALOG_BODY,
+                        {'evt_desc': evt.desc}
+                    ).result.then(function() {
+                        egCore.net.request(
+                            'open-ils.cat',
+                            'open-ils.cat.asset.volume.fleshed.batch.update.override',
+                            egCore.auth.token(), cnList, 1,
+                            { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
+                        ).then(function() {
+                            holdingsSvcInst.fetchAgain().then(function() {
+                                $scope.holdingsGridDataProvider.refresh();
+                            });
+                        });
+                    });
+                } else {
+                    holdingsSvcInst.fetchAgain().then(function() {
+                        $scope.holdingsGridDataProvider.refresh();
+                    });
+                }
             });
         });
     }
diff --git a/Open-ILS/web/js/ui/default/staff/circ/services/item.js b/Open-ILS/web/js/ui/default/staff/circ/services/item.js
index 8e2142882f..d07c598e81 100644
--- a/Open-ILS/web/js/ui/default/staff/circ/services/item.js
+++ b/Open-ILS/web/js/ui/default/staff/circ/services/item.js
@@ -580,10 +580,28 @@ function(egCore , egOrg , egCirc , $uibModal , $q , $timeout , $window , ngToast
             ).result.then(function() {
                 egCore.net.request(
                     'open-ils.cat',
-                    'open-ils.cat.asset.volume.fleshed.batch.update.override',
+                    'open-ils.cat.asset.volume.fleshed.batch.update',
                     egCore.auth.token(), cnList, 1, flags
-                ).then(function(){
-                    angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
+                ).then(function(resp){
+                    var evt = egCore.evt.parse(resp);
+                    if (evt) {
+                        egConfirmDialog.open(
+                            egCore.strings.OVERRIDE_DELETE_ITEMS_FROM_CATALOG_TITLE,
+                            egCore.strings.OVERRIDE_DELETE_ITEMS_FROM_CATALOG_BODY,
+                            {'evt_desc': evt.desc}
+                        ).result.then(function() {
+                            egCore.net.request(
+                                'open-ils.cat',
+                                'open-ils.cat.asset.volume.fleshed.batch.update.override',
+                                egCore.auth.token(), cnList, 1,
+                                { events: ['TITLE_LAST_COPY', 'COPY_DELETE_WARNING'] }
+                            ).then(function() {
+                                angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
+                            });
+                        });
+                    } else {
+                        angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
+                    }
                 });
             });
         },
@@ -980,3 +998,4 @@ function(egCore , egOrg , egCirc , $uibModal , $q , $timeout , $window , ngToast
     return service;
 }])
 .filter('string_pick', function() { return function(i){ return arguments[i] || ''; }; })
+
-- 
2.11.0