Try rearranging the code to look up new copy status only once.
authorJason Stephenson <jason@sigio.com>
Sun, 21 Oct 2018 17:10:07 +0000 (13:10 -0400)
committerJason Stephenson <jason@sigio.com>
Fri, 26 Oct 2018 23:04:56 +0000 (19:04 -0400)
Open-ILS/web/js/ui/default/staff/circ/services/circ.js

index 35dfef6..7fc2b12 100644 (file)
@@ -1380,7 +1380,7 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,  egAddCopyAl
         // If any new back end mark_item calls are added, also add
         // them here to use them from the staff client.
         // TODO: I didn't find any JS constants for copy status.
-        switch (markstatus) {
+        switch (markstatus.id()) {
         case 2:
             // Not implemented in the staff client, yet.
             // req = "open-ils.circ.mark_item_bindery";
@@ -1412,35 +1412,18 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,  egAddCopyAl
             break;
         }
 
-        function get_status(statusID) {
-            var deferred = $q.defer()
-            egCore.pcrud.retrieve('ccs', statusID)
-                .then(function(resp) {
-                    deferred.resolve(resp);
-                }, function(resp) {
-                    deferred.reject(resp);
-                });
-            return deferred.promise;
-        }
-
-        var newStatus;
-        return get_status(markstatus).then(function(resp) {
-            newStatus = resp;
-            return egCore.net.request(
-                'open-ils.circ',
-                req,
-                egCore.auth.token(),
-                copy.id,
-                args
-            ).then(function(resp) {
-                if (resp == 1) {
-                    console.debug(req + ' succeeded for ' + copy.barcode);
-                } else if (evt = egCore.evt.parse(resp)) {
-                    console.error(req + ' failed for ' + copy.barcode + ': ' + resp.textcode);
-                }
-            });
-        }, function(resp) {
-            /* noop */
+        return egCore.net.request(
+            'open-ils.circ',
+            req,
+            egCore.auth.token(),
+            copy.id,
+            args
+        ).then(function(resp) {
+            if (resp == 1) {
+                console.debug(req + ' succeeded for ' + copy.barcode);
+            } else if (evt = egCore.evt.parse(resp)) {
+                console.error(req + ' failed for ' + copy.barcode + ': ' + resp.textcode);
+            }
         });
     }
 
@@ -1453,11 +1436,14 @@ function($uibModal , $q , egCore , egAlertDialog , egConfirmDialog,  egAddCopyAl
                 cancel : function() {}
             }
         ).result.then(function() {
-            var promises = [];
-            angular.forEach(copies, function(copy) {
-                promises.push(service.mark_item(copy, 13, {}))
-            });
-            return $q.all(promises);
+            egCore.pcrud.retrieve('ccs', 13)
+                .then(function(resp) {
+                    var promises = [];
+                    angular.forEach(copies, function(copy) {
+                        promises.push(service.mark_item(copy, resp, {}))
+                    });
+                    return $q.all(promises);
+                });
         });
     }