* 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>'
// called in the overridding method.
onOpen$ = new EventEmitter<any>();
+ // null if the dialog has never been opened.
+ // true if the most recent instance was dismissed by the user,
+ // false otherwise.
+ dismissed: boolean = null;
+
// The modalRef allows direct control of the modal instance.
private modalRef: NgbModalRef = null;
open(options?: NgbModalOptions): Promise<any> {
if (this.modalRef !== null) {
- console.warn('Dismissing existing dialog');
- this.dismiss();
+ this.dismiss(new Error('Dialog was replaced'));
}
+ this.dismissed = null;
this.modalRef = this.modalService.open(this.dialogContent, options);
if (this.onOpen$) {
return new Promise( (resolve, reject) => {
this.modalRef.result.then(
+
(result) => {
+ this.dismissed = false;
resolve(result);
this.modalRef = null;
},
// 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);
-
- const dismissed = (
+ this.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
- };
+ if (this.dismissed) {
+ resolve(null);
+ } else {
+ console.error('Dialog rejection occurred', result);
+ reject(result);
+ }
- reject(rejection);
this.modalRef = null;
}
);
private handleCollision(): Promise<number> {
return new Promise((resolve, reject) => {
- this.wsExistsDialog.open()
- .then(
- confirmed => {
+ this.wsExistsDialog.open().then(override => {
+ if (override) {
this.registerWorkstationApi(true).then(
wsId => resolve(wsId),
notOk => reject(notOk)
);
- },
- dismissed => reject(dismissed)
- );
+ }
+ });
});
}
this.createNew = () => {
this.editDialog.mode = 'create';
- this.editDialog.open({size: 'lg'}).then(
- ok => this.grid.reload(),
- err => {}
- );
+ this.editDialog.open({size: 'lg'})
+ .then(ok => this.grid.reload());
};
this.deleteSelected = (matchSets: IdlObject[]) => {
(matchSet: IdlObject) => {
this.editDialog.mode = 'update';
this.editDialog.recId = matchSet.id();
- this.editDialog.open({size: 'lg'}).then(
- ok => this.grid.reload(),
- err => {}
- );
+ this.editDialog.open({size: 'lg'})
+ .then(ok => this.grid.reload());
}
);
}
}
deleteQueue() {
- this.confirmDelDlg.open().then(
- yes => {
- this.progressDlg.open();
- return this.net.request(
- 'open-ils.vandelay',
- `open-ils.vandelay.${this.qtypeShort()}_queue.delete`,
- this.auth.token(), this.queueId
- ).toPromise();
- },
- no => {
- this.progressDlg.close();
- return Promise.reject('delete failed');
- }
- ).then(
- resp => {
- this.progressDlg.close();
- const e = this.evt.parse(resp);
- if (e) {
- console.error(e);
- alert(e);
- } else {
+
+ this.confirmDelDlg.open().then(confirmed => {
+ if (!confirmed) { return; }
+
+ this.progressDlg.open();
+ this.net.request(
+ 'open-ils.vandelay',
+ `open-ils.vandelay.${this.qtypeShort()}_queue.delete`,
+ this.auth.token(), this.queueId
+ ).toPromise().then(
+ resp => {
+ const e = this.evt.parse(resp);
+ if (e) { return new Error(e.toString()); }
+
// Jump back to the main queue page.
this.router.navigate(['/staff/cat/vandelay/queue']);
- }
- },
- err => {
- this.progressDlg.close();
- }
- );
+ },
+ err => console.error('queue deletion failed!', err)
+ ).finally(() => this.progressDlg.close());
+ });
}
exportNonImported() {
(part: IdlObject) => {
this.editDialog.mode = 'update';
this.editDialog.recId = part.id();
- this.editDialog.open().then(
- ok => this.partsGrid.reload(),
- err => {}
- );
+ this.editDialog.open().then(ok => this.partsGrid.reload());
}
);
this.editDialog.record = part;
this.editDialog.mode = 'create';
- this.editDialog.open().then(
- ok => this.partsGrid.reload(),
- err => {}
- );
+ this.editDialog.open().then(ok => this.partsGrid.reload());
};
this.deleteSelected = (parts: IdlObject[]) => {
this.mergeSelected = (parts: IdlObject[]) => {
if (parts.length < 2) { return; }
this.mergeDialog.parts = parts;
- this.mergeDialog.open().then(
- ok => this.partsGrid.reload(),
- err => console.debug('Dialog dismissed')
- );
+ this.mergeDialog.open().then(ok => this.partsGrid.reload());
};
}
}
}
openEditor() {
- this.fmRecordEditor.open({size: 'lg'}).then(
- ok => { console.debug(ok); },
- err => {
- if (err && err.dismissed) {
- console.debug('dialog was dismissed');
- } else {
- console.error(err);
- }
+ this.fmRecordEditor.open({size: 'lg'}).then(ok => {
+ if (this.fmRecordEditor.dismissed) {
+ console.debug('fm editor dialog dismissed');
+ } else {
+ console.debug(ok);
}
- );
+ });
}
btGridRowClassCallback(row: any): string {
this.editDialog.record = null;
this.editDialog.open({size: this.dialogSize}).then(
ok => {
- this.createString.current()
- .then(str => this.toast.success(str));
- this.grid.reload();
+ if (this.editDialog.dismissed) {
+ console.debug('create action was dismissed');
+ } else {
+ this.createString.current()
+ .then(str => this.toast.success(str));
+ this.grid.reload();
+ }
},
rejection => {
- if (!rejection.dismissed) {
- this.createErrString.current()
- .then(str => this.toast.danger(str));
- }
+ this.createErrString.current()
+ .then(str => this.toast.danger(str));
}
);
};
this.editDialog.recId = idlThing[this.pkeyField]();
return this.editDialog.open({size: this.dialogSize}).then(
ok => {
- this.successString.current()
- .then(str => this.toast.success(str));
- this.grid.reload();
+ if (this.editDialog.dismissed) {
+ console.debug('Edit dialog dismissed');
+ } else {
+ this.successString.current()
+ .then(str => this.toast.success(str));
+ this.grid.reload();
+ }
},
rejection => {
- if (!rejection.dismissed) {
- this.updateFailedString.current()
- .then(str => this.toast.danger(str));
- }
+ this.updateFailedString.current()
+ .then(str => this.toast.danger(str));
}
);
}
],
"lib": [
"es2017",
- "dom"
+ "dom",
+ "es2018.promise"
]
}
}