]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/share/marc-edit/simplified-editor/simplified-editor-field.directive.ts
a5e7e0a76f0d01b3cc6cf83fb5286dcbd19aa67f
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / share / marc-edit / simplified-editor / simplified-editor-field.directive.ts
1 import {Directive, Host, Input, OnInit, AfterViewInit} from '@angular/core';
2 import {MarcSimplifiedEditorComponent} from './simplified-editor.component';
3 import {MarcField, MarcSubfield} from '../marcrecord';
4 import {MarcSimplifiedEditorSubfieldDirective} from './simplified-editor-subfield.directive';
5
6 /**
7  * A field that a user can edit, which will later be
8  * compiled into MARC
9  */
10
11 @Directive({
12   selector: 'eg-marc-simplified-editor-field',
13 })
14 export class MarcSimplifiedEditorFieldDirective implements OnInit, AfterViewInit {
15
16   @Input() tag = 'a';
17   @Input() ind1 = ' ';
18   @Input() ind2 = ' ';
19
20   subfieldIndex = 1;
21
22   marcVersion: MarcField;
23
24   addSubfield: (code: string, defaultValue?: string) => void;
25
26   constructor(@Host() private editor: MarcSimplifiedEditorComponent) {}
27
28   ngOnInit() {
29     this.marcVersion = {
30       tag: this.tag,
31       subfields: [],
32       authValid: false,
33       authChecked: false,
34       isCtrlField: false,
35       isControlfield: () => false,
36       indicator: (ind: number) => (ind === 1) ? this.ind1 : this.ind2,
37       deleteExactSubfields: (...subfield: MarcSubfield[]) => 0, // not used by the simplified editor
38     };
39
40     this.addSubfield = (code: string, defaultValue?: string) => {
41       this.marcVersion.subfields.push(
42         [
43           code,
44           defaultValue ? defaultValue : '',
45           this.subfieldIndex
46         ]
47       );
48       this.subfieldIndex += 1;
49
50     }
51   }
52
53   ngAfterViewInit() {
54     this.editor.addField(this.marcVersion);
55   }
56
57 }
58
59
60