blob: 9b900dedf444200d1df08eaf42d3e506d69aa534 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
import {Component, Input, OnChanges, SimpleChanges} from "@angular/core";
import {FormGroup} from "@angular/forms";
import {MultiselectFormControl} from "../../../../models/formControlModels/multiselectFormControl.model";
import {MultiselectFormControlService} from "./multiselect.formControl.service";
import {MultiSelectItem} from "./multiselect.model";
@Component({
selector: 'multiselect-form-control',
templateUrl: './multiselect.formControl.component.html'
})
export class MultiselectFormControlComponent implements OnChanges{
@Input() data: MultiselectFormControl = null;
@Input() multiselectOptions: [] = null;
@Input() selectedItems = [];
@Input() form: FormGroup = null;
multiselectFormControlService : MultiselectFormControlService;
constructor(private _multiselectFormControlService : MultiselectFormControlService){
this.multiselectFormControlService = _multiselectFormControlService;
}
dropdownSettings = {
singleSelection : false
};
options : MultiSelectItem[];
async ngOnChanges(changes: SimpleChanges) {
if(this.data.options$){
this._multiselectFormControlService.convertOriginalItems(this.data).then((options)=>{
this.options = options;
this._multiselectFormControlService.convertSelectedItems(this.data).then((res)=> {
this.selectedItems = res;
this.form.controls[this.data.controlName].setValue(this.selectedItems);
})
});
}
if (changes["data"] !== undefined && changes["data"].currentValue !== changes["data"].previousValue && changes["data"].firstChange) {
if (this.data.onInit) {
this.data.onInit(this.data, this.form);
}
}
}
onItemSelect(item:any){
this.data.onChange(this.selectedItems ,this.form);
}
OnItemDeSelect(item:any){
this.data.onChange(this.selectedItems ,this.form);
}
onSelectAll(items: any){
this.data.onChange(this.selectedItems ,this.form);
}
onDeSelectAll(items: any){
this.data.onChange(this.selectedItems ,this.form);
}
}
|