<h4 class="modal-title" i18n>Record Editor: {{recordLabel}}</h4>
<ng-container *ngIf="isDialog()">
<button type="button" class="close"
- i18n-aria-label aria-label="Close" (click)="close()">
+ i18n-aria-label aria-label="Close" (click)="closeEditor()">
<span aria-hidden="true">×</span>
</button>
</ng-container>
<div class="modal-footer">
<ng-container *ngIf="isDialog()">
<button type="button" class="btn btn-success" *ngIf="mode == 'view'"
- (click)="close()" i18n>Close</button>
+ (click)="closeEditor()" i18n>Close</button>
<button type="button" class="btn btn-warning ml-2" *ngIf="mode != 'view'"
(click)="cancel()" i18n>Cancel</button>
</ng-container>
import {DialogComponent} from '@eg/share/dialog/dialog.component';
import {ToastService} from '@eg/share/toast/toast.service';
import {StringComponent} from '@eg/share/string/string.component';
-import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
+import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
import {TranslateComponent} from '@eg/staff/share/translate/translate.component';
if (id) { this.recId = id; }
}
+ // custom function for munging the record before it gets saved;
+ // will get passed mode and the record itself
+ @Input() preSave: Function;
+
constructor(
private modal: NgbModal, // required for passing to parent
private idl: IdlService,
}
}
+ open(args?: NgbModalOptions): Observable<any> {
+ if (!args) {
+ args = {};
+ }
+ // ensure we don't hang on to our copy of the record
+ // if the user dismisses the dialog
+ args.beforeDismiss = () => {
+ this.record = undefined;
+ return true;
+ };
+ return super.open(args);
+ }
+
isDialog(): boolean {
return this.displayMode === 'dialog';
}
save() {
const recToSave = this.idl.clone(this.record);
+ if (this.preSave) {
+ this.preSave(this.mode, recToSave);
+ }
this.convertDatatypesToIdl(recToSave);
this.pcrud[this.mode]([recToSave]).toPromise().then(
result => {
this.onSave$.emit(result);
this.successStr.current().then(msg => this.toast.success(msg));
- if (this.isDialog()) { this.close(result); }
+ if (this.isDialog()) { this.record = undefined; this.close(result); }
},
error => {
this.onError$.emit(error);
cancel() {
this.onCancel$.emit(this.record);
+ this.record = undefined;
+ this.close();
+ }
+
+ closeEditor() {
+ this.record = undefined;
this.close();
}