argos/dmp-frontend/src/app/shared/components/external-items/external-item-listing/external-item-listing.compo...

68 lines
1.6 KiB
TypeScript
Raw Normal View History

2018-10-05 17:00:54 +02:00
import { Component, OnInit, Input, ContentChild, TemplateRef, ViewChild, Output, EventEmitter } from '@angular/core';
import { FormGroup, FormControl, FormArray, AbstractControl } from '@angular/forms';
import { ExternalSourcesUrlModel } from '../../../../models/external-sources/ExternalSourcesUrlModel';
import { AutoCompleteConfiguration } from '../../auto-complete/AutoCompleteConfiguration';
2018-05-28 11:50:42 +02:00
@Component({
selector: 'app-external-item-listing',
templateUrl: './external-item-listing.component.html',
styleUrls: ['./external-item-listing.component.scss']
2018-05-28 11:50:42 +02:00
})
export class ExternalItemListingComponent implements OnInit {
@Input()
public placeholder: string;
2018-05-28 11:50:42 +02:00
@Input()
public formGroup: AbstractControl;
2018-05-28 11:50:42 +02:00
@Input()
public autoCompleteConfiguration: AutoCompleteConfiguration;
2018-05-28 11:50:42 +02:00
@Input()
public displayFunction: Function;
2018-05-28 11:50:42 +02:00
@Input()
public subtitleFunction: Function;
2018-07-11 15:47:36 +02:00
@Input()
public disabled = true;
2018-05-28 11:50:42 +02:00
@Input()
public viewOnly = false;
2018-08-31 10:14:56 +02:00
@Input()
public titleKey: string;
2018-05-28 11:50:42 +02:00
@Input()
parentTemplate;
2018-05-28 11:50:42 +02:00
@Input()
public options: Array<ExternalSourcesUrlModel>;
2018-05-28 11:50:42 +02:00
@Output()
public onItemChange = new EventEmitter<any>();
2018-05-28 11:50:42 +02:00
public choice: string;
public formControl = new FormControl();
enabled = true;
2018-05-28 11:50:42 +02:00
ngOnInit() {
if (this.disabled) { this.formControl.disable(); }
}
2018-06-05 10:18:01 +02:00
onItemChangeFunc(event) {
if (event) { this.onItemChange.emit(event); }
}
2018-05-28 11:50:42 +02:00
selectionChange(event) {
if (this.formControl.disabled) { this.formControl.enable(); }
this.autoCompleteConfiguration.requestItem.criteria['type'] = event.value;
this.autoCompleteConfiguration.refreshEvent.next(true);
}
2018-05-28 11:50:42 +02:00
deleteItem(name: number) {
(<FormArray>this.formGroup).removeAt(name);
}
2018-05-28 11:50:42 +02:00
}