LP#1717007 Improve egProgressDialog collision handling
authorBill Erickson <berickxx@gmail.com>
Wed, 27 Sep 2017 15:30:47 +0000 (11:30 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 4 Oct 2017 16:16:15 +0000 (12:16 -0400)
Resolves a race condition where egProgressDialog.open() is called twice
before the first call completes (i.e. the dialog is opened), leaving 2
open dialogs, one of which cannot be closed because its reference is
lost.

Going forward, attempts to open multiple dialogs will always result in
the most recently visible dialog taking preference.  When collisions
occur, a warning is also issued to the console.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Cesar Velez <cesar.velez@equinoxinitiative.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/web/js/ui/default/staff/services/ui.js

index 0c385fa..b33358f 100644 (file)
@@ -310,26 +310,32 @@ function($timeout , $parse) {
     var service = {};
 
     service.open = function(args) {
     var service = {};
 
     service.open = function(args) {
-        service.close(); // force-kill existing instances.
-
-        // Reset to an indeterminate progress bar, 
-        // overlay with caller values.
-        egProgressData.reset();
-        service.update(angular.extend({}, args));
-
         return $uibModal.open({
             templateUrl: './share/t_progress_dialog',
             controller: ['$scope','$uibModalInstance','egProgressData',
                 function( $scope , $uibModalInstance , egProgressData) {
         return $uibModal.open({
             templateUrl: './share/t_progress_dialog',
             controller: ['$scope','$uibModalInstance','egProgressData',
                 function( $scope , $uibModalInstance , egProgressData) {
-                  service.currentInstance = $uibModalInstance;
-                  $scope.data = egProgressData; // tiny service
+                    // Once the new modal instance is available, force-
+                    // kill any other instances
+                    service.close(true); 
+
+                    // Reset to an indeterminate progress bar, 
+                    // overlay with caller values.
+                    egProgressData.reset();
+                    service.update(angular.extend({}, args));
+
+                    service.currentInstance = $uibModalInstance;
+                    $scope.data = egProgressData; // tiny service
                 }
             ]
         });
     };
 
                 }
             ]
         });
     };
 
-    service.close = function() {
+    service.close = function(warn) {
         if (service.currentInstance) {
         if (service.currentInstance) {
+            if (warn) {
+                console.warn("egProgressDialog replacing existing instance. "
+                    + "Only one may be open at a time.");
+            }
             service.currentInstance.close();
             delete service.currentInstance;
         }
             service.currentInstance.close();
             delete service.currentInstance;
         }