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