LPXXX editor continued
authorBill Erickson <berickxx@gmail.com>
Mon, 25 Nov 2019 21:22:16 +0000 (16:22 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 6 Dec 2019 15:37:03 +0000 (10:37 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/editor-context.ts
Open-ILS/src/eg2/src/app/staff/share/marc-edit/tagtable.service.ts

index d1f7082..62ed01e 100644 (file)
@@ -200,10 +200,57 @@ export class EditableContentComponent implements OnInit, AfterViewInit {
         if (this.fieldType === 'ldr') { return; }
 
         switch (evt.key) {
-            case 'Enter': return this.keyEnter(evt);
-            case 'Delete': return this.keyDelete(evt);
-            case 'ArrowDown': return this.keyArrowDown(evt);
-            case 'ArrowUp': return this.keyArrowUp(evt);
+
+            case 'Enter': 
+                if (evt.ctrlKey) {
+                    // ctrl+enter == insert stub field after focused field
+                    // ctrl+shift+enter == insert stub field before focused field
+                    this.insertField(evt.shiftKey);
+                }
+
+                evt.preventDefault(); // Bare newlines not allowed.
+                break;
+
+            case 'Delete':
+
+                if (evt.ctrlKey) { 
+                    // ctrl+delete == delete whole field
+                    this.deleteField();
+                    evt.preventDefault();
+
+                } else if (evt.shiftKey && this.subfield) {
+                    // shift+delete == delete subfield
+
+                    this.deleteSubfield();
+                    evt.preventDefault();
+                }
+
+                break;
+
+            case 'ArrowDown': 
+                if (evt.ctrlKey) {
+                    // ctrl+down == copy current field down one
+                    this.record.insertFieldsAfter(
+                        this.field, this.record.cloneField(this.field));
+                }
+
+                // down == move focus to tag of previous field
+                this.context.focusNextTag(this.field);
+                evt.preventDefault();
+                break;
+
+            case 'ArrowUp':
+                if (evt.ctrlKey) {
+                    // ctrl+up == copy current field up one
+                    this.record.insertFieldsBefore(
+                        this.field, this.record.cloneField(this.field));
+                }
+
+                // up == move focus to tag of previous field
+                this.context.focusPreviousTag(this.field);
+                evt.preventDefault();
+                break;
+
 
             case 'F6': 
                 if (evt.shiftKey) {
@@ -245,103 +292,44 @@ export class EditableContentComponent implements OnInit, AfterViewInit {
         }
     }
 
-    // ctrl+enter == insert stub field after focused field
-    // ctrl+shift+enter == insert stub field before focused field
-    keyEnter(evt: KeyboardEvent) {
+    insertField(before: boolean) {
 
-        if (evt.ctrlKey) {
+        const newField = this.record.newField(
+            {tag: '999', subfields: [[' ', '', 0]]});
 
-            const newField = this.record.newField(
-                {tag: '999', subfields: [[' ', '', 0]]});
-
-            if (evt.shiftKey) {
-                this.record.insertFieldsBefore(this.field, newField);
-            } else {
-                this.record.insertFieldsAfter(this.field, newField);
-            }
-
-            this.context.requestFieldFocus(
-                {fieldId: newField.fieldId, target: 'tag'});
+        if (before) {
+            this.record.insertFieldsBefore(this.field, newField);
+        } else {
+            this.record.insertFieldsAfter(this.field, newField);
         }
 
-        evt.preventDefault(); // Bare newlines not allowed.
+        this.context.requestFieldFocus(
+            {fieldId: newField.fieldId, target: 'tag'});
     }
 
-    // ctrl+delete == delete whole field
-    // shift+delete == delete subfield
-    keyDelete(evt: KeyboardEvent) {
-
-        if (evt.ctrlKey) { 
-            const field = 
-                this.record.getNextField(this.field.fieldId) ||
-                this.record.getPreviousField(this.field.fieldId);
-
-            if (field) {
-                this.context.requestFieldFocus(
-                    {fieldId: field.fieldId, target: 'tag'});
-            }
+    deleteField() {
+        this.context.focusNextTag(this.field) || 
+            this.context.focusPreviousTag(this.field);
 
-            this.record.deleteFields(this.field);
-            evt.preventDefault();
-
-        } else if (evt.shiftKey && this.subfield) {
-
-            // If subfields remain, focus the previous subfield.
-            // otherwise focus our tag.
-            const sfpos = this.subfield[2] - 1;
-
-            this.field.deleteExactSubfields(this.subfield);
-
-            const focus: FieldFocusRequest = 
-                {fieldId: this.field.fieldId, target: 'tag'};
-
-            if (sfpos >= 0) { 
-                focus.target = 'sfv';
-                focus.sfOffset = sfpos; 
-            }
-
-            this.context.requestFieldFocus(focus);
-
-            evt.preventDefault();
-        }
-    }
-
-    // down == move focus to tag of next field
-    // ctrl+down == copy current field down one
-    keyArrowDown(evt: KeyboardEvent) {
-
-        if (evt.ctrlKey) { // Copy field down
-
-            this.record.insertFieldsAfter(
-                this.field, this.record.cloneField(this.field));
-        }
-
-        const field = this.record.getNextField(this.field.fieldId);
-        if (field) {
-            this.context.requestFieldFocus(
-                {fieldId: field.fieldId, target: 'tag'});
-        }
-
-        evt.preventDefault();
+        this.record.deleteFields(this.field);
     }
 
-    // up == move focus to tag of previou field
-    // ctrl+up == copy current field up one
-    keyArrowUp(evt: KeyboardEvent) {
+    deleteSubfield() {
+        // If subfields remain, focus the previous subfield.
+        // otherwise focus our tag.
+        const sfpos = this.subfield[2] - 1;
 
-        if (evt.ctrlKey) {
+        this.field.deleteExactSubfields(this.subfield);
 
-            this.record.insertFieldsBefore(
-                this.field, this.record.cloneField(this.field));
-        }
+        const focus: FieldFocusRequest = 
+            {fieldId: this.field.fieldId, target: 'tag'};
 
-        const field = this.record.getPreviousField(this.field.fieldId);
-        if (field) {
-            this.context.requestFieldFocus(
-                {fieldId: field.fieldId, target: 'tag'});
+        if (sfpos >= 0) { 
+            focus.target = 'sfv';
+            focus.sfOffset = sfpos; 
         }
 
-        evt.preventDefault();
+        this.context.requestFieldFocus(focus);
     }
 
     contextMenuChange(value: string) {
index 1861b34..56655f0 100644 (file)
@@ -96,5 +96,29 @@ export class MarcEditContext {
             sfOffset: position
         });
     }
+
+    // Returns true if the field has a next tag to focus
+    focusNextTag(field: MarcField) {
+        const nextField = this.record.getNextField(field.fieldId);
+        if (nextField) {
+            this.requestFieldFocus(
+                {fieldId: nextField.fieldId, target: 'tag'});
+            return true;
+        }
+        return false;
+    }
+
+    // Returns true if the field has a previous tag to focus
+    focusPreviousTag(field: MarcField): boolean {
+        const prevField = this.record.getPreviousField(field.fieldId);
+        if (prevField) {
+            this.requestFieldFocus(
+                {fieldId: prevField.fieldId, target: 'tag'});
+            return true;
+        }
+        return false;
+    }
+
+
 }
 
index 9918739..8e206c8 100644 (file)
@@ -39,10 +39,13 @@ export class TagTableService {
         private pcrud: PcrudService,
         private evt: EventService
     ) {
-        this.extractedValuesCache.fieldtags = {};
-        this.extractedValuesCache.indicators = {};
-        this.extractedValuesCache.sfcodes = {};
-        this.extractedValuesCache.sfvalues = {};
+
+        this.extractedValuesCache = {
+            fieldtags: {},
+            indicators: {},
+            sfcodes: {},
+            sfvalues: {}
+        };
     }
 
     // Various data needs munging for display.  Cached the modified