Projekt

Obecné

Profil

Stáhnout (1.63 KB) Statistiky
| Větev: | Tag: | Revize:
1
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
3
import {ManagementService} from '../../../shared/api/endpoints/services/management.service';
4
import {ToastService} from '../../../shared/services/toast.service';
5

    
6
@Component({
7
  selector: 'app-unit-popup',
8
  templateUrl: './unit-popup.component.html',
9
  styleUrls: ['./unit-popup.component.scss']
10
})
11
export class UnitPopupComponent implements OnInit {
12

    
13
  insertForm: FormGroup;
14

    
15
  @Input() isVisible;
16
  @Input() unit;
17
  @Output() isVisibleChange: EventEmitter<boolean> = new EventEmitter<boolean>();
18

    
19
  constructor(
20
    private formBuilder: FormBuilder,
21
    private managementService: ManagementService,
22
    private toastService: ToastService
23
  ) {
24
    this.initForm();
25
  }
26

    
27
  initForm() {
28
    this.insertForm = this.formBuilder.group({
29
      unitDescription: ['', Validators.required]
30
    });
31
    setTimeout(() => {
32
      this.insertForm.controls.unitDescription.setValue(this.unit.description);
33
    }, 0);
34
  }
35

    
36
  ngOnInit(): void {
37
  }
38

    
39

    
40
  saveUnit() {
41
    if (this.insertForm.controls.unitDescription.value && this.insertForm.controls.unitDescription.value !== this.unit.description) {
42
      this.unit.description = this.insertForm.controls.unitDescription.value;
43
      /*TODO this.managementService.updateUnit$Response({ body: { unit: this.unit}}).toPromise().then( res => {
44
        if (res) {
45
          this.toastService.showSuccess();
46
        }
47
      }).catch(err => this.toastService.showError(err.body.message));*/
48
    }
49
  }
50

    
51
  close() {
52
    this.insertForm.reset();
53
    this.isVisibleChange.emit(false);
54
  }
55
}
(3-3/3)