LP1807461 Admin page avoid errors on dialog dismissal
[evergreen-equinox.git] / Open-ILS / src / eg2 / src / app / share / dialog / dialog.component.ts
index 3ffd5db..b7531a2 100644 (file)
@@ -7,6 +7,13 @@ import {NgbModal, NgbModalRef, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap
  * at the root of the template (see ConfirmDialogComponent).
  */
 
+export interface DialogRejectionResponse {
+    // Did the user simply close the dialog without performing an action.
+    dismissed?: boolean;
+    // Relays error, etc. messages from the dialog handler to the caller.
+    message?: string;
+}
+
 @Component({
     selector: 'eg-dialog',
     template: '<ng-template></ng-template>'
@@ -55,9 +62,26 @@ export class DialogComponent implements OnInit {
                     resolve(result);
                     this.modalRef = null;
                 },
+
                 (result) => {
+                    // NgbModal creates some result values for us, which
+                    // are outside of our control.  Other dismissal
+                    // reasons are agreed upon by implementing subclasses.
                     console.debug('dialog closed with ' + result);
-                    reject(result);
+
+                    const dismissed = (
+                           result === 0 // body click
+                        || result === 1 // Esc key
+                        || result === 'canceled' // Cancel button
+                        || result === 'cross_click' // modal top-right X
+                    );
+
+                    const rejection: DialogRejectionResponse = {
+                        dismissed: dismissed,
+                        message: result
+                    };
+
+                    reject(rejection);
                     this.modalRef = null;
                 }
             );