]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/confirm/confirm.component.ts
Add bulk comment actions on account dropdown
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / confirm / confirm.component.ts
CommitLineData
63347a0f 1import { Component, ElementRef, HostListener, OnInit, ViewChild } from '@angular/core'
457bb213 2import { ConfirmService } from '@app/core/confirm/confirm.service'
b1d40cff 3import { I18n } from '@ngx-translate/i18n-polyfill'
63347a0f
C
4import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
5import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
60c2bc80 6import { POP_STATE_MODAL_DISMISS } from '@app/shared/misc/constants'
5769e1db 7
5769e1db
C
8@Component({
9 selector: 'my-confirm',
59aa1e5e 10 templateUrl: './confirm.component.html',
1f30a185 11 styleUrls: [ './confirm.component.scss' ]
5769e1db
C
12})
13export class ConfirmComponent implements OnInit {
f36da21e 14 @ViewChild('confirmModal', { static: true }) confirmModal: ElementRef
5769e1db 15
df98563e
C
16 title = ''
17 message = ''
1f30a185
C
18 expectedInputValue = ''
19 inputLabel = ''
20
21 inputValue = ''
22b59e80 22 confirmButtonText = ''
5769e1db 23
63347a0f
C
24 private openedModal: NgbModalRef
25
b1d40cff 26 constructor (
63347a0f 27 private modalService: NgbModal,
b1d40cff
C
28 private confirmService: ConfirmService,
29 private i18n: I18n
23db998f 30 ) { }
5769e1db 31
df98563e 32 ngOnInit () {
5769e1db 33 this.confirmService.showConfirm.subscribe(
22b59e80 34 ({ title, message, expectedInputValue, inputLabel, confirmButtonText }) => {
df98563e
C
35 this.title = title
36 this.message = message
5769e1db 37
1f30a185
C
38 this.inputLabel = inputLabel
39 this.expectedInputValue = expectedInputValue
40
b1d40cff 41 this.confirmButtonText = confirmButtonText || this.i18n('Confirm')
22b59e80 42
df98563e 43 this.showModal()
5769e1db 44 }
df98563e 45 )
5769e1db
C
46 }
47
df98563e 48 confirm () {
63347a0f 49 if (this.openedModal) this.openedModal.close()
5769e1db
C
50 }
51
1f30a185
C
52 isConfirmationDisabled () {
53 // No input validation
54 if (!this.inputLabel || !this.expectedInputValue) return false
55
56 return this.expectedInputValue !== this.inputValue
57 }
58
df98563e 59 showModal () {
a7dbc7df 60 this.inputValue = ''
5769e1db 61
54e78847 62 this.openedModal = this.modalService.open(this.confirmModal, { centered: true })
63347a0f
C
63
64 this.openedModal.result
65 .then(() => this.confirmService.confirmResponse.next(true))
60c2bc80
C
66 .catch((reason: string) => {
67 // If the reason was that the user used the back button, we don't care about the confirm dialog result
68 if (!reason || reason !== POP_STATE_MODAL_DISMISS) {
69 this.confirmService.confirmResponse.next(false)
70 }
71 })
5769e1db
C
72 }
73}