Projekt

Obecné

Profil

Stáhnout (1.63 KB) Statistiky
| Větev: | Tag: | Revize:
1 bb7795cd hlavja
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2 a3ae1cab hlavja
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
3
import {ManagementService} from '../../../shared/api/endpoints/services/management.service';
4 6ea14224 hlavja
import {ToastService} from '../../../shared/services/toast.service';
5 bb7795cd hlavja
6
@Component({
7 25a20eec hlavja
  selector: 'app-unit-popup',
8 bb7795cd hlavja
  templateUrl: './unit-popup.component.html',
9
  styleUrls: ['./unit-popup.component.scss']
10
})
11
export class UnitPopupComponent implements OnInit {
12
13 a3ae1cab hlavja
  insertForm: FormGroup;
14
15 bb7795cd hlavja
  @Input() isVisible;
16
  @Input() unit;
17
  @Output() isVisibleChange: EventEmitter<boolean> = new EventEmitter<boolean>();
18 a3ae1cab hlavja
19
  constructor(
20
    private formBuilder: FormBuilder,
21 6ea14224 hlavja
    private managementService: ManagementService,
22
    private toastService: ToastService
23 a3ae1cab hlavja
  ) {
24
    this.initForm();
25
  }
26
27
  initForm() {
28
    this.insertForm = this.formBuilder.group({
29 abe9aea2 hlavja
      unitDescription: ['', Validators.required]
30 a3ae1cab hlavja
    });
31 6ea14224 hlavja
    setTimeout(() => {
32
      this.insertForm.controls.unitDescription.setValue(this.unit.description);
33
    }, 0);
34 a3ae1cab hlavja
  }
35 bb7795cd hlavja
36
  ngOnInit(): void {
37
  }
38
39
40 a3ae1cab hlavja
  saveUnit() {
41 abe9aea2 hlavja
    if (this.insertForm.controls.unitDescription.value && this.insertForm.controls.unitDescription.value !== this.unit.description) {
42
      this.unit.description = this.insertForm.controls.unitDescription.value;
43 6ea14224 hlavja
      /*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 abe9aea2 hlavja
    }
49 bb7795cd hlavja
  }
50
51
  close() {
52 a3ae1cab hlavja
    this.insertForm.reset();
53 bb7795cd hlavja
    this.isVisibleChange.emit(false);
54
  }
55
}