]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/share/marc-edit/rich-editor.component.ts
LP1852782 MARC editable content aria-labels
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / share / marc-edit / rich-editor.component.ts
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';
8
9
10 /**
11  * MARC Record rich editor interface.
12  */
13
14 @Component({
15   selector: 'eg-marc-rich-editor',
16   templateUrl: './rich-editor.component.html',
17   styleUrls: ['rich-editor.component.css']
18 })
19
20 export class MarcRichEditorComponent implements OnInit {
21
22     @Input() context: MarcEditContext;
23     get record(): MarcRecord { return this.context.record; }
24
25     dataLoaded: boolean;
26     showHelp: boolean;
27     randId = Math.floor(Math.random() * 100000);
28     stackSubfields: boolean;
29
30     constructor(
31         private idl: IdlService,
32         private org: OrgService,
33         private tagTable: TagTableService
34     ) {}
35
36     ngOnInit() {
37         this.init().then(_ =>
38             this.context.recordChange.subscribe(__ => this.init()));
39     }
40
41     init(): Promise<any> {
42         this.dataLoaded = false;
43
44         if (!this.record) { return Promise.resolve(); }
45
46         return Promise.all([
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);
51     }
52
53     undoCount(): number {
54         return this.context.undoStack.length;
55     }
56
57     redoCount(): number {
58         return this.context.redoStack.length;
59     }
60
61     undo() {
62         this.context.requestUndo();
63     }
64
65     redo() {
66         this.context.requestRedo();
67     }
68
69     controlFields(): MarcField[] {
70         return this.record.fields.filter(f => f.isControlfield());
71     }
72
73     dataFields(): MarcField[] {
74         return this.record.fields.filter(f => !f.isControlfield());
75     }
76 }
77
78
79