aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_modals/yes-no-dialog/yes-no-dialog.component.ts
blob: a7db1e7fc35a792900e64e7c700f277c43db3537 (plain) (blame)
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
import { Component, OnInit } from '@angular/core';
import { Inject} from '@angular/core';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';

interface DialogData {
  title: string;
  message: string;
  yesFunction:Function;
}

@Component({
  selector: 'app-yes-no-dialog',
  templateUrl: './yes-no-dialog.component.html',
  styleUrls: ['./yes-no-dialog.component.css']
})
export class YesNoDialogComponent {
  
  constructor(
    public dialogRef: MatDialogRef<YesNoDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: DialogData,
    //public dialog: MatDialog
  ) {}

  onNoClick(): void {
    this.dialogRef.close();
  }

  withEnterKey(keyboardEvent: KeyboardEvent) {
      if (keyboardEvent.code == "Enter" || keyboardEvent.code == "NumpadEnter") 
        this.onYesClick();
  }
  onYesClick():void {
    this.data.yesFunction();
    this.dialogRef.close();
  }
}