Projekt

Obecné

Profil

Stáhnout (1.71 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { Component, Inject } from '@angular/core';
2
import { MAT_DIALOG_DATA, MatDialogRef, MatSnackBar } from '@angular/material';
3
import {VacationType} from '../enums/common.enum';
4

    
5
@Component({
6
  selector: 'app-add-days-off-dialog',
7
  templateUrl: './add-vacation-dialog.component.html',
8
  styleUrls: ['./add-vacation-dialog.component.sass']
9
})
10
export class AddVacationDialogComponent {
11
  MINUTE_STEP = 15;
12

    
13
  vacationType = VacationType;
14

    
15
  selectedVacationType: VacationType;
16

    
17
  constructor(
18
    public dialogRef: MatDialogRef<AddVacationDialogComponent>,
19
    @Inject(MAT_DIALOG_DATA) public data: AddVacationDialogData,
20
    private snackBar: MatSnackBar
21
  ) {
22
    if (this.data.toDate == null) {
23
      this.data.toDate = this.data.fromDate;
24
    }
25
    if (this.data.fromTime == null) {
26
      this.data.fromTime = '08:00';
27
    }
28
    if (data.toTime == null) {
29
      this.data.toTime = '16:00';
30
    }
31
  }
32

    
33
  onConfirmClick(): void {
34
    if (this.selectedVacationType == null) {
35
      this.snackBar.open('Nevybrán typ volna', 'Zavřít', { duration: 5000 });
36
    } else if (this.data.fromDate > this.data.toDate) {
37
      this.snackBar.open('Datum "od" nemůže být větší než "do"', 'Zavřít', { duration: 5000 });
38
    } else {
39
      this.dialogRef.close({
40
        isConfirmed: true,
41
        vacationType: this.selectedVacationType,
42
        fromDate: this.data.fromDate,
43
        fromTime: this.data.fromTime,
44
        toDate: this.data.toDate,
45
        toTime: this.data.toTime
46
      });
47
    }
48
  }
49

    
50
  onCloseClick(): void {
51
    this.dialogRef.close({
52
      isConfirmed: false
53
    });
54
  }
55

    
56
}
57

    
58
export interface AddVacationDialogData {
59
  fromDate: Date;
60
  toDate: Date;
61
  fromTime: string; // 'HH:mm' format
62
  toTime: string; // 'HH:mm' format
63
}
(3-3/4)