LP1852782 Prevents data fields swapping to control fields
authorBill Erickson <berickxx@gmail.com>
Wed, 11 Dec 2019 20:28:04 +0000 (15:28 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 21 Feb 2020 16:44:38 +0000 (11:44 -0500)
Prevent an existing data field from swapping to a control field while
editing the tag.  This way if a tag is cleared the field won't jump from
the data fields section up to the control fields section mid-edit.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/share/marc-edit/marcrecord.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/rich-editor.component.ts

index 69e0955..cdc99aa 100644 (file)
@@ -19,6 +19,11 @@ export interface MarcField {
     ind2?: string;
     subfields?: MarcSubfield[];
 
+    // Fields are immutable when it comes to controlfield vs.
+    // data field.  Stamp the value when stamping field IDs.
+    isCtrlField: boolean;
+
+    // Pass-through to marcrecord.js
     isControlfield(): boolean;
 
     deleteExactSubfields(...subfield: MarcSubfield[]): number;
@@ -89,10 +94,15 @@ export class MarcRecord {
         this.fields.forEach(f => this.stampFieldId(f));
     }
 
+    // Stamp field IDs the the initial isCtrlField state.
     stampFieldId(field: MarcField) {
         if (!field.fieldId) {
             field.fieldId = Math.floor(Math.random() * 10000000);
         }
+
+        if (field.isCtrlField === undefined) {
+            field.isCtrlField = field.isControlfield();
+        }
     }
 
     field(spec: string, wantArray?: boolean): MarcField | MarcField[] {
index 6b79fe2..a1a7d55 100644 (file)
@@ -93,11 +93,11 @@ export class MarcRichEditorComponent implements OnInit {
     }
 
     controlFields(): MarcField[] {
-        return this.record.fields.filter(f => f.isControlfield());
+        return this.record.fields.filter(f => f.isCtrlField);
     }
 
     dataFields(): MarcField[] {
-        return this.record.fields.filter(f => !f.isControlfield());
+        return this.record.fields.filter(f => !f.isCtrlField);
     }
 }