paperless-ngx/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.ts

63 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Component, EventEmitter, Input, Output } from '@angular/core'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { Subject } from 'rxjs'
2020-10-27 01:10:18 +01:00
@Component({
selector: 'app-confirm-dialog',
templateUrl: './confirm-dialog.component.html',
styleUrls: ['./confirm-dialog.component.scss'],
2020-10-27 01:10:18 +01:00
})
2022-02-15 23:43:02 -08:00
export class ConfirmDialogComponent {
constructor(public activeModal: NgbActiveModal) {}
2021-01-25 23:32:02 -08:00
2020-10-27 01:10:18 +01:00
@Output()
public confirmClicked = new EventEmitter()
2020-10-27 01:10:18 +01:00
@Input()
2020-12-28 15:39:53 +01:00
title = $localize`Confirmation`
2020-10-27 01:10:18 +01:00
@Input()
messageBold
2020-10-27 01:10:18 +01:00
@Input()
message
2020-10-27 01:10:18 +01:00
@Input()
btnClass = 'btn-primary'
@Input()
2020-12-28 15:39:53 +01:00
btnCaption = $localize`Confirm`
2021-01-03 21:44:53 +01:00
@Input()
buttonsEnabled = true
2021-01-25 22:44:26 -08:00
confirmButtonEnabled = true
seconds = 0
2022-02-15 23:43:02 -08:00
confirmSubject: Subject<boolean>
2021-01-25 22:44:26 -08:00
delayConfirm(seconds: number) {
this.confirmButtonEnabled = false
this.seconds = seconds
setTimeout(() => {
if (this.seconds <= 1) {
this.confirmButtonEnabled = true
} else {
this.delayConfirm(seconds - 1)
}
}, 1000)
}
2021-01-25 22:44:26 -08:00
cancel() {
2022-02-15 23:43:02 -08:00
this.confirmSubject?.next(false)
this.confirmSubject?.complete()
2020-10-27 01:10:18 +01:00
this.activeModal.close()
}
2021-01-25 22:44:26 -08:00
confirm() {
2021-01-25 23:32:02 -08:00
this.confirmClicked.emit()
2022-02-15 23:43:02 -08:00
this.confirmSubject?.next(true)
this.confirmSubject?.complete()
2021-01-25 22:44:26 -08:00
}
2020-10-27 01:10:18 +01:00
}