<eg-string #successStr text="Update Succeeded" i18n-text></eg-string>
<eg-string #failStr text="Update Failed" i18n-text></eg-string>
+<eg-confirm-dialog #confirmDel
+ dialogTitle="Delete?" i18n-dialogTitle
+ dialogBody="Delete {{recordLabel}}?" i18n-dialogBody>
+</eg-confirm-dialog>
+
<ng-template #dialogContent>
<div class="modal-header bg-info" *ngIf="!hideBanner">
<h4 class="modal-title" i18n>Record Editor: {{recordLabel}}</h4>
<button type="button" class="btn btn-warning ml-2" *ngIf="mode != 'view'"
(click)="cancel()" i18n>Cancel</button>
</ng-container>
+
+ <ng-container *ngIf="showDelete && mode != 'view'">
+ <button type="button" class="btn btn-warning" (click)="remove()"
+ [disabled]="record && record.isnew()" i18n>Delete</button>
+ </ng-container>
+
<button type="button" class="btn btn-info"
[disabled]="fmEditForm.invalid" *ngIf="mode != 'view'"
(click)="save()" i18n>Save</button>
import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
import {TranslateComponent} from '@eg/share/translate/translate.component';
import {FmRecordEditorActionComponent} from './fm-editor-action.component';
+import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
interface CustomFieldTemplate {
// Emit the modified object when the save action completes.
@Output() recordSaved = new EventEmitter<IdlObject>();
+ // Emit the modified object when the save action completes.
+ @Output() recordDeleted = new EventEmitter<IdlObject>();
+
// Emit the original object when the save action is canceled.
@Output() recordCanceled = new EventEmitter<IdlObject>();
@ViewChild('translator') private translator: TranslateComponent;
@ViewChild('successStr') successStr: StringComponent;
@ViewChild('failStr') failStr: StringComponent;
+ @ViewChild('confirmDel') confirmDel: ConfirmDialogComponent;
// IDL info for the the selected IDL class
idlDef: any;
// will be rendered alphabetically by label after the named fields.
@Input() fieldOrder: string;
+ // When true, show a delete button and support delete operations.
+ @Input() showDelete: boolean;
+
constructor(
private modal: NgbModal, // required for passing to parent
private idl: IdlService,
// Modifies the provided FM record in place, replacing JS values
// with IDL-compatible values.
convertDatatypesToIdl(rec: IdlObject) {
- const fields = this.idlDef.fields;
+ const fields = this.idlDef.fields.filter(f => !f.virtual);
+
fields.forEach(field => {
if (field.datatype === 'bool') {
if (rec[field.name]() === true) {
);
}
+ remove() {
+ this.confirmDel.open().subscribe(confirmed => {
+ if (!confirmed) { return; }
+ const recToRemove = this.idl.clone(this.record);
+ this.pcrud.remove(recToRemove).toPromise().then(
+ result => {
+ this.recordDeleted.emit(result);
+ this.successStr.current().then(msg => this.toast.success(msg));
+ if (this.isDialog()) { this.close(result); }
+ },
+ error => {
+ this.recordError.emit(error);
+ this.failStr.current().then(msg => this.toast.warning(msg));
+ if (this.isDialog()) { this.error(error); }
+ }
+ );
+ });
+ }
+
cancel() {
this.recordCanceled.emit(this.record);
this.close();