1 import {Component, Input, Output, OnInit, AfterViewInit, EventEmitter,
2 OnDestroy} from '@angular/core';
3 import {IdlService} from '@eg/core/idl.service';
4 import {OrgService} from '@eg/core/org.service';
5 import {TagTableService} from './tagtable.service';
6 import {MarcRecord, MarcField} from './marcrecord';
7 import {MarcEditContext} from './editor-context';
11 * MARC Record rich editor interface.
15 selector: 'eg-marc-rich-editor',
16 templateUrl: './rich-editor.component.html',
17 styleUrls: ['rich-editor.component.css']
20 export class MarcRichEditorComponent implements OnInit {
22 @Input() context: MarcEditContext;
23 get record(): MarcRecord { return this.context.record; }
27 randId = Math.floor(Math.random() * 100000);
28 stackSubfields: boolean;
31 private idl: IdlService,
32 private org: OrgService,
33 private tagTable: TagTableService
38 this.context.recordChange.subscribe(__ => this.init()));
41 init(): Promise<any> {
42 this.dataLoaded = false;
44 if (!this.record) { return Promise.resolve(); }
47 this.tagTable.loadTagTable({marcRecordType: this.context.recordType}),
48 this.tagTable.getFfPosTable(this.record.recordType()),
49 this.tagTable.getFfValueTable(this.record.recordType())
50 ]).then(_ => this.dataLoaded = true);
54 return this.context.undoStack.length;
58 return this.context.redoStack.length;
62 this.context.requestUndo();
66 this.context.requestRedo();
69 controlFields(): MarcField[] {
70 return this.record.fields.filter(f => f.isControlfield());
73 dataFields(): MarcField[] {
74 return this.record.fields.filter(f => !f.isControlfield());