0638ec5751f8a70e1b97e61ab899ed196b80882c
[working/Evergreen.git] /
1 import {Component, Host, Input, OnInit, Output, ViewChildren, QueryList, AfterViewInit} from '@angular/core';
2 import {MarcSimplifiedEditorComponent} from './simplified-editor.component';
3 import {MarcField, MarcSubfield} from '../marcrecord';
4 import { MarcSimplifiedEditorSubfieldComponent } from './simplified-editor-subfield.component';
5
6 /**
7  * A field that a user can edit, which will later be
8  * compiled into MARC
9  */
10
11 @Component({
12   selector: 'eg-marc-simplified-editor-field',
13   template: '<ng-template></ng-template>'
14 })
15 export class MarcSimplifiedEditorFieldComponent implements OnInit, AfterViewInit {
16
17   @Input() tag = 'a';
18   @Input() ind1 = ' ';
19   @Input() ind2 = ' ';
20
21   @ViewChildren(MarcSimplifiedEditorSubfieldComponent)
22     subfields: QueryList<MarcSimplifiedEditorSubfieldComponent>;
23
24   marcVersion: MarcField;
25
26   addSubfield: (subfield: MarcSubfield) => void;
27
28   constructor(@Host() private editor: MarcSimplifiedEditorComponent) {}
29
30   ngOnInit() {
31     this.marcVersion = {
32       tag: this.tag,
33       authValid: false,
34       authChecked: false,
35       isCtrlField: false,
36       isControlfield: () => false,
37       indicator: (ind: number) => (ind === 1) ? this.ind1 : this.ind2,
38       deleteExactSubfields: (...subfield: MarcSubfield[]) => 0, // not used by the simplified editor
39     };
40   }
41
42   ngAfterViewInit() {
43     this.subfields.forEach((subfield: MarcSimplifiedEditorSubfieldComponent, index: number) => {
44       this.marcVersion.subfields.push(
45         [
46           subfield.code,
47           subfield.defaultValue ? subfield.defaultValue : '',
48           index
49         ]
50       );
51     });
52     this.editor.addField(this.marcVersion);
53   }
54
55 }
56
57
58