Update UI code for backend changes.
authorJason Stephenson <jason@sigio.com>
Sun, 2 Sep 2018 00:46:22 +0000 (20:46 -0400)
committerJason Stephenson <jason@sigio.com>
Fri, 26 Oct 2018 23:04:56 +0000 (19:04 -0400)
Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/templates/staff/circ/share/circ_strings.tt2
Open-ILS/web/js/ui/default/staff/circ/services/circ.js
Open-ILS/web/js/ui/default/staff/circ/services/item.js

index a2b1198..a67b891 100644 (file)
@@ -26,8 +26,12 @@ s.LOCATION_ALERT_MSG =
   '[% l("Item [_1] needs to be routed to [_2]", 
     "{{copy.barcode()}}","{{copy.location().name()}}") %]';
 s.MARK_DAMAGED_CONFIRM = '[% l("Mark {{num_items}} items as DAMAGED?") %]';
-s.MARK_DISCARD_CONFIRM = '[% l("Mark {{num_items}} items as DISCARD/WEED?") %]';
 s.MARK_MISSING_CONFIRM = '[% l("Mark {{num_items}} items as MISSING?") %]';
+s.MARK_DISCARD_CHECKED_OUT = '[% l("Item to mark Discard/Weed is checked out.") %]';
+s.MARK_DISCARD_IN_TRANSIT = '[% l("Item to mark Discard/Weed is in transit.") %]';
+s.MARK_DISCARD_RESTRICT_DELETE = '[% l("Item to mark Discard/Weed is in a status with a copy delete warning.") %]';
+s.MARK_DISCARD_LAST_HOLD_COPY = '[% l("Item with barcode {{barcode}} is the last item to fill a hold.") %]';
+s.MARK_DISCARD_CONTINUE = '[% l("Do you wish to continue?") %]';
 s.ABORT_TRANSIT_CONFIRM = '[% l("Cancel {{num_transits}} transits?") %]';
 s.ROUTE_TO_HOLDS_SHELF = '[% l("Holds Shelf") %]';
 s.ROUTE_TO_CATALOGING = '[% l("Cataloging") %]';
index c21d801..5c06221 100644 (file)
@@ -1374,31 +1374,86 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,  egAddCopyAl
         }).result;
     }
 
-    service.mark_discard = function(copy_ids) {
-        return egConfirmDialog.open(
-            egCore.strings.MARK_DISCARD_CONFIRM, '',
-            {   num_items : copy_ids.length,
-                ok : function() {},
-                cancel : function() {}
-            }
-        ).result.then(function() {
-            var promises = [];
-            angular.forEach(copy_ids, function(copy_id) {
-                promises.push(
-                    egCore.net.request(
-                        'open-ils.circ',
-                        'open-ils.circ.mark_item_discard',
-                        egCore.auth.token(), copy_id
-                    ).then(function(resp) {
-                        if (evt = egCore.evt.parse(resp)) {
-                            console.error('mark discard/weed failed: ' + evt);
-                        }
-                    })
-                );
+    service.mark_discard = function(copy) {
+        if (!copy) return $q.when();
+        // Make sure the copy status is fleshed.
+        if (!isNaN(copy.status)) {
+            service.flesh_copy_status(copy);
+        }
+        var doRefresh = copy.refresh;
+        var arg = {};
+        if (copy.status.id == 1) {
+            egConfimDialog.open(
+                egCore.strings.MARK_DISCARD_CHECKED_OUT,
+                egCore.strings.MARK_DISCARD_CONTINUE,
+                {
+                    ok : function() {},
+                    cancel :function() {}
+                }
+            ).result.then(function() {
+                arg.handle_checkin = 1;
             });
-
-            return $q.all(promises);
+        } else if (copy.status.id == 6) {
+            egConfimDialog.open(
+                egCore.strings.MARK_DISCARD_IN_TRANSIT,
+                egCore.strings.MARK_DISCARD_CONTINUE,
+                {
+                    ok : function() {},
+                    cancel :function() {}
+                }
+            ).result.then(function() {
+                arg.handle_transit = 1;
+            });
+        } else if (copy.status.restrict_copy_delete == "t") {
+            egConfimDialog.open(
+                egCore.strings.MARK_DISCARD_RESTRICT_DELETE,
+                egCore.strings.MARK_DISCARD_CONTINUE,
+                {
+                    ok : function() {},
+                    cancel :function() {}
+                }
+            ).result.then(function() {
+                arg.handle_copy_delete_warning = 1;
+            });
+        }
+        var result = egCore.net.request(
+            'open-ils.circ',
+            'open-ils.circ.mark_item_discard',
+            egCore.auth.token(), copy.id, arg
+        ).then(function(resp) {
+            if (evt = egCore.evt.parse(resp)) {
+                if (evt.textcode == "ITEM_TO_MARK_LAST_HOLD_COPY") {
+                    egConfimDialog.open(
+                        egCore.strings.MARK_DISCARD_LAST_HOLD_COPY,
+                        egCore.strings.MARK_DISCARD_CONTINUE,
+                        {
+                            barcode : copy.barcode,
+                            ok : function() {},
+                            cancel :function() {}
+                        }
+                    ).result.then(function() {
+                        arg.handle_last_hold_copy = 1;
+                        result = egCore.net.request(
+                            'open-ils.circ',
+                            'open-ils.circ.mark_item_discard',
+                            egCore.auth.token(), copy.id, arg
+                        ).then(function(resp) {
+                            if (evt == egCore.evt.parse(resp)) {
+                                console.error('mark discard/weed failed: ' + evt);
+                                doRefresh = false;
+                            }
+                        });
+                    });
+                } else {
+                    console.error('mark discard/weed failed: ' + evt);
+                    doRefresh = false;
+                }
+            }
         });
+        if (doRefresh) {
+            egItem.add_barcode_to_list(copy.barcode);
+        }
+        return result;
     }
 
     service.mark_missing = function(copy_ids) {
index fec54e7..707928b 100644 (file)
@@ -644,21 +644,11 @@ function(egCore , egCirc , $uibModal , $q , $timeout , $window , egConfirmDialog
         });
     }
 
-    // service.selectedHoldingsDiscard = function (items) {
-    //     angular.forEach(items, function(cp) {
-    //         if (cp) {
-    //             egCirc.mark_discard({
-    //                 id: cp.id,
-    //                 barcode: cp.barcode,
-    //                 refresh: cp.refresh
-    //             });
-    //         }
-    //     });
-    // }
-
     service.selectedHoldingsDiscard = function (items) {
-        egCirc.mark_discard(items.map(function(el){return el.id;})).then(function(){
-            angular.forEach(items, function(cp){service.add_barcode_to_list(cp.barcode)});
+        angular.forEach(items, function(cp) {
+            if (cp) {
+                egCirc.mark_discard(cp);
+            }
         });
     }