angular flat marc edit
authorBill Erickson <berickxx@gmail.com>
Fri, 28 Jun 2019 15:22:17 +0000 (11:22 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 28 Jun 2019 15:22:17 +0000 (11:22 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.html
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor.component.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/marcrecord.ts

index 5b8de51..fdaf7e5 100644 (file)
@@ -1,4 +1,18 @@
 
+<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>
@@ -9,8 +23,16 @@
       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">
@@ -44,8 +66,8 @@
 </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>
 
 
index b0addac..88d5a30 100644 (file)
@@ -8,6 +8,8 @@ import {PcrudService} from '@eg/core/pcrud.service';
 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.
@@ -45,6 +47,9 @@ export class MarcEditorComponent implements OnInit {
     @Output() recordSaved: EventEmitter<string>;
 
     @ViewChild('sourceSelector') sourceSelector: ComboboxComponent;
+    @ViewChild('confirmDelete') confirmDelete: ConfirmDialogComponent;
+    @ViewChild('confirmUndelete') confirmUndelete: ConfirmDialogComponent;
+    @ViewChild('cannotDelete') cannotDelete: ConfirmDialogComponent;
 
     constructor(
         private evt: EventService,
@@ -114,6 +119,7 @@ export class MarcEditorComponent implements OnInit {
         .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());
             }
@@ -124,7 +130,53 @@ export class MarcEditorComponent implements OnInit {
         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()));
+            });
+        });
+    }
+}
 
index bb815f7..1b0c488 100644 (file)
@@ -7,6 +7,7 @@ declare var MARC21;
 export class MarcRecord {
 
     id: number; // Database ID when known.
+    deleted: boolean;
     record: any; // MARC21.Record object
     breakerText: string;