]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/server/coded-value-maps/composite-new.component.ts
LP1843969 Composite Attribute Entry Defs
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / admin / server / coded-value-maps / composite-new.component.ts
1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {IdlObject} from '@eg/core/idl.service';
3 import {PcrudService} from '@eg/core/pcrud.service';
4 import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.component';
5
6 export class CompositeNewPointValues {
7     pointType: string;
8     boolOp: string;
9     typeLabel: string;
10     typeId: string;
11     valueLabel: string;
12     valueId: string;
13 }
14
15 @Component({
16   selector: 'eg-composite-new-point',
17   templateUrl: 'composite-new.component.html'
18 })
19 export class CompositeNewPointComponent implements OnInit {
20
21     public values: CompositeNewPointValues;
22
23     attrTypeDefs: IdlObject[];
24     attrValDefs: IdlObject[];
25     attrTypes: ComboboxEntry[];
26     attrVals: ComboboxEntry[];
27
28     @Input() set pointType(type_: string) {
29         this.values.pointType = type_;
30         this.values.boolOp = '';
31         this.values.valueLabel = '';
32         this.values.valueId = '';
33         this.values.typeId = '';
34         this.values.typeLabel = '';
35     }
36
37     @ViewChild('valComboBox', {static: false}) valComboBox: ComboboxComponent;
38
39     constructor(
40         private pcrud: PcrudService
41     ) {
42         this.values = new CompositeNewPointValues();
43         this.attrTypeDefs = [];
44         this.attrTypes = [];
45     }
46
47     ngOnInit() {
48         this.pcrud.retrieveAll('crad', {order_by: {crad: 'label'}})
49         .subscribe(attr => {
50             this.attrTypeDefs.push(attr);
51             this.attrTypes.push({id: attr.name(), label: attr.label()});
52         });
53     }
54
55     typeChange(evt) {
56         this.values.typeId = evt.id;
57         this.values.typeLabel = evt.label;
58         this.valComboBox.selected = null;  // reset other combobox
59         this.values.valueId = ''; // don't allow save with old valueId or valueLabel
60         this.values.valueLabel = '';
61         this.attrVals = [];
62         this.attrValDefs = [];
63         this.pcrud.search('ccvm', {'ctype': evt.id},
64             {flesh: 1, flesh_fields: {ccvm: ['composite_def', 'ctype']} }).subscribe(
65             data => {
66                 this.attrValDefs.push(data);
67                 this.attrVals.push({id: data.code(), label: data.value()});
68             },
69             err => {
70                 console.debug(err);
71                 this.attrVals = [];
72                 this.attrValDefs = [];
73             }
74         );
75     }
76
77     valueChange(evt) {
78         if (evt) {
79             this.values.valueId = evt.id;
80             this.values.valueLabel = evt.label;
81         }
82     }
83 }
84