LP#1932203: serialize requests on Edit Due Date in Items Out tab
[evergreen-equinox.git] / Open-ILS / web / js / ui / default / staff / circ / patron / items_out.js
index ed0f0f5..b2988c5 100644 (file)
@@ -7,10 +7,10 @@ angular.module('egPatronApp')
 .controller('PatronItemsOutCtrl',
        ['$scope','$q','$routeParams','$timeout','egCore','egUser','patronSvc',
         '$location','egGridDataProvider','$uibModal','egCirc','egConfirmDialog',
-        'egBilling','$window','egBibDisplay',
+        'egProgressDialog','egBilling','$window','egBibDisplay',
 function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc , 
          $location , egGridDataProvider , $uibModal , egCirc , egConfirmDialog , 
-         egBilling , $window , egBibDisplay) {
+         egProgressDialog , egBilling , $window , egBibDisplay) {
 
     // list of noncatatloged circulations. Define before initTab to 
     // avoid any possibility of race condition, since they are loaded
@@ -118,6 +118,8 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
         var deferred = $q.defer();
         var rendered = 0;
 
+        egProgressDialog.open();
+
         // fetch the lot of circs and stream the results back via notify
         egCore.pcrud.search('circ', {id : id_list},
             {   flesh : 4,
@@ -182,6 +184,7 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
                 }
 
                 if (rendered++ >= offset && rendered <= count) {
+                    egProgressDialog.close();
                     deferred.notify(circ);
                 };
             });
@@ -351,11 +354,12 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
                     $scope.ok = function(args) {
                         var due = $scope.args.due_date.toISOString();
                         console.debug("applying due date of " + due);
+                        egProgressDialog.open();
 
-                        var promises = [];
+                        var promise = $q.when();
                         angular.forEach(items, function(circ) {
-                            promises.push(
-                                egCore.net.request(
+                            promise = promise.then(function() {
+                                return egCore.net.request(
                                     'open-ils.circ',
                                     'open-ils.circ.circulation.due_date.update',
                                     egCore.auth.token(), circ.id(), due
@@ -365,10 +369,11 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
                                     // date from the modified circulation.
                                     circ.due_date(new_circ.due_date());
                                 })
-                            );
+                            });
                         });
 
-                        $q.all(promises).then(function() {
+                        promise.finally(function() {
+                            egProgressDialog.close();
                             $uibModalInstance.close();
                             provider.refresh();
                         });
@@ -413,7 +418,8 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
             expire_date : cusr.expire_date(),
             alias : cusr.alias(),
             has_email : Boolean(patronSvc.current.email() && patronSvc.current.email().match(/.*@.*/)),
-            has_phone : Boolean(cusr.day_phone() || cusr.evening_phone() || cusr.other_phone())
+            has_phone : Boolean(cusr.day_phone() || cusr.evening_phone() || cusr.other_phone()),
+            juvenile : cusr.juvenile()
         };
 
         return egCore.print.print({
@@ -473,11 +479,10 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
     $scope.show_triggered_events = function(items) {
         var focus = items.length == 1;
         angular.forEach(items, function(item) {
-            var url = egCore.env.basePath +
-                      '/cat/item/' +
-                      item.target_copy().id() +
-                      '/triggered_events';
+            var url = '/eg2/staff/circ/item/event-log/' +
+                      item.target_copy().id();
             $timeout(function() { var x = $window.open(url, '_blank'); if (focus) x.focus() });
+
         });
     }
 
@@ -490,11 +495,35 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
 
         return egConfirmDialog.open(msg, barcodes.join(' '), {}).result
         .then(function() {
+            window.oils_cancel_batch = false;
+            window.oils_inside_batch = true;
+            function batch_cleanup() {
+                if (window.oils_inside_batch && window.oils_op_change_within_batch) {
+                    window.oils_op_change_undo_func();
+                }
+                window.oils_inside_batch = false;
+                window.oils_op_change_within_batch = false;
+                reset_page();
+            }
             function do_one() {
                 var bc = barcodes.pop();
-                if (!bc) { reset_page(); return }
+                if (!bc) {
+                    batch_cleanup();
+                    return;
+                }
+                if (window.oils_op_change_within_batch) {
+                    window.oils_op_change_toast_func();
+                }
                 // finally -> continue even when one fails
-                egCirc.renew({copy_barcode : bc}).finally(do_one);
+                egCirc.renew({copy_barcode : bc}).finally(function() {
+                    if (!window.oils_cancel_batch) {
+                        do_one();
+                    } else {
+                        console.log('batch cancelled');
+                        batch_cleanup();
+                        return;
+                    }
+                });
             }
             do_one();
         });