lp1362743 One modal at a time during checkin user/mrisher/lp1742553-check-in-multi-popups
authorMike Risher <mrisher@catalyte.io>
Wed, 6 May 2020 17:08:33 +0000 (17:08 +0000)
committerMike Risher <mrisher@catalyte.io>
Wed, 6 May 2020 17:08:33 +0000 (17:08 +0000)
Modify batch checkins so that only one modal pops up at a time.
When each one is dismissed the next one will appear.

Signed-off-by: Mike Risher <mrisher@catalyte.io>
Changes to be committed:
modified:   Open-ILS/web/js/ui/default/staff/circ/services/item.js

Open-ILS/web/js/ui/default/staff/circ/services/item.js

index 8150f18..1afdf1b 100644 (file)
@@ -614,11 +614,19 @@ function(egCore , egOrg , egCirc , $uibModal , $q , $timeout , $window , ngToast
     }
 
     service.checkin = function (items) {
-        angular.forEach(items, function (cp) {
-            egCirc.checkin({copy_barcode:cp.barcode}).then(
-                function() { service.add_barcode_to_list(cp.barcode) }
-            );
-        });
+        // Recursive function that creates a promise for each item. Once the dialog 
+        // window for a given item is closed the next promise is started and a
+        // new dialog is opened. 
+        // This keeps multiple popups from hitting the screen at once.
+        (function checkinLoop(i) {
+            if (i < items.length) new Promise((resolve, reject) => {
+                egCirc.checkin({copy_barcode: items[i].barcode})
+                .then(function() {
+                    service.add_barcode_to_list(items[i].barcode);
+                    resolve();
+                })
+            }).then(checkinLoop.bind(null, i+1));
+        })(0);
     }
 
     service.renew = function (items) {