aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/components/formControls/component/multiselect/multiselect.formControl.component.ts
blob: cf062f0e0e6e02ea2a47aaba235b34e5e978473b (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
62
63
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,
    limitSelection : 1000
  };

  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.data.onChange(this.selectedItems ,this.form);
          })
      });
    }
    if (changes["data"] !== undefined && changes["data"].currentValue !== changes["data"].previousValue && changes["data"].firstChange) {
      if (this.data.onInit) {
        this.dropdownSettings.limitSelection = this.data.limitSelection;
        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);
  }
}