+<eg-confirm-dialog #confirmDelete
+ i18n-dialogTitle dialogTitle="Confirm Delete"
+ i18n-dialogBody dialogBody="Delete Record ID {{record ? record.id : ''}}?">
+</eg-confirm-dialog>
+
+<eg-confirm-dialog #confirmUndelete
+ i18n-dialogTitle dialogTitle="Confirm Undelete"
+ i18n-dialogBody dialogBody="Undelete Record ID {{record ? record.id : ''}}?">
+</eg-confirm-dialog>
+
+<eg-alert-dialog #cannotDelete
+ i18n-dialogBody
+ dialogBody="Records with holdings attached cannot be deleted.">
+</eg-alert-dialog>
<div class="row d-flex p-2 m-2">
<div class="flex-1"></div>
i18n-placeholder>
</eg-combobox>
</div>
- <button class="btn btn-success" (click)="saveRecord()" i18n>
- Save Changes</button>
+
+ <ng-container *ngIf="record && record.id">
+ <button *ngIf="!record.deleted" class="btn btn-warning"
+ (click)="deleteRecord()" i18n>Delete Record</button>
+ <button *ngIf="record.deleted" class="btn btn-info"
+ (click)="undeleteRecord()" i18n>Undelete Record</button>
+ </ng-container>
+
+ <button class="btn btn-success ml-2" (click)="saveRecord()"
+ [disabled]="record && record.deleted" i18n>Save Changes</button>
</div>
<div class="row">
</div>
<div class="row d-flex p-2 m-2 flex-row-reverse">
- <button class="btn btn-success" (click)="saveRecord()" i18n>
- Save Changes</button>
+ <button class="btn btn-success" (click)="saveRecord()"
+ [disabled]="record && record.deleted" i18n>Save Changes</button>
</div>
import {MarcRecord} from './marcrecord';
import {ComboboxEntry, ComboboxComponent
} from '@eg/share/combobox/combobox.component';
+import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
+
/**
* MARC Record editor main interface.
@Output() recordSaved: EventEmitter<string>;
@ViewChild('sourceSelector') sourceSelector: ComboboxComponent;
+ @ViewChild('confirmDelete') confirmDelete: ConfirmDialogComponent;
+ @ViewChild('confirmUndelete') confirmUndelete: ConfirmDialogComponent;
+ @ViewChild('cannotDelete') cannotDelete: ConfirmDialogComponent;
constructor(
private evt: EventService,
.toPromise().then(bib => {
this.record = new MarcRecord(bib.marc());
this.record.id = id;
+ this.record.deleted = bib.deleted() === 't';
if (bib.source()) {
this.sourceSelector.applyEntryId(+bib.source());
}
this.record = new MarcRecord(xml);
this.record.id = null;
}
-}
+ deleteRecord(): Promise<any> {
+
+ return this.confirmDelete.open().toPromise()
+ .then(yes => {
+ if (!yes) { return; }
+
+ return this.net.request('open-ils.cat',
+ 'open-ils.cat.biblio.record_entry.delete',
+ this.auth.token(), this.record.id).toPromise()
+
+ .then(resp => {
+
+ const evt = this.evt.parse(resp);
+ if (evt) {
+ if (evt.textcode === 'RECORD_NOT_EMPTY') {
+ return this.cannotDelete.open().toPromise();
+ } else {
+ console.error(evt);
+ return alert(evt);
+ }
+ }
+ return this.fromId(this.record.id)
+ .then(_ => this.recordSaved.emit(this.record.toXml()));
+ });
+ });
+ }
+ undeleteRecord(): Promise<any> {
+
+ return this.confirmUndelete.open().toPromise()
+ .then(yes => {
+ if (!yes) { return; }
+
+ return this.net.request('open-ils.cat',
+ 'open-ils.cat.biblio.record_entry.undelete',
+ this.auth.token(), this.record.id).toPromise()
+
+ .then(resp => {
+
+ const evt = this.evt.parse(resp);
+ if (evt) { console.error(evt); return alert(evt); }
+
+ return this.fromId(this.record.id)
+ .then(_ => this.recordSaved.emit(this.record.toXml()));
+ });
+ });
+ }
+}