]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/core/confirm/confirm.component.ts
Add confirm when admin use custom js/css
[github/Chocobozzz/PeerTube.git] / client / src / app / core / confirm / confirm.component.ts
CommitLineData
df98563e 1import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
5769e1db 2
df98563e 3import { ModalDirective } from 'ngx-bootstrap/modal'
5769e1db 4
df98563e 5import { ConfirmService } from './confirm.service'
5769e1db 6
5769e1db
C
7@Component({
8 selector: 'my-confirm',
59aa1e5e 9 templateUrl: './confirm.component.html',
1f30a185 10 styleUrls: [ './confirm.component.scss' ]
5769e1db
C
11})
12export class ConfirmComponent implements OnInit {
df98563e 13 @ViewChild('confirmModal') confirmModal: ModalDirective
5769e1db 14
df98563e
C
15 title = ''
16 message = ''
1f30a185
C
17 expectedInputValue = ''
18 inputLabel = ''
19
20 inputValue = ''
5769e1db
C
21
22 constructor (private confirmService: ConfirmService) {
23 // Empty
24 }
25
df98563e 26 ngOnInit () {
5769e1db
C
27 this.confirmModal.config = {
28 backdrop: 'static',
29 keyboard: false
df98563e 30 }
5769e1db
C
31
32 this.confirmService.showConfirm.subscribe(
1f30a185 33 ({ title, message, expectedInputValue, inputLabel }) => {
df98563e
C
34 this.title = title
35 this.message = message
5769e1db 36
1f30a185
C
37 this.inputLabel = inputLabel
38 this.expectedInputValue = expectedInputValue
39
df98563e 40 this.showModal()
5769e1db 41 }
df98563e 42 )
5769e1db
C
43 }
44
45 @HostListener('keydown.enter')
df98563e
C
46 confirm () {
47 this.confirmService.confirmResponse.next(true)
48 this.hideModal()
5769e1db
C
49 }
50
51 @HostListener('keydown.esc')
6599f096 52 cancel () {
df98563e
C
53 this.confirmService.confirmResponse.next(false)
54 this.hideModal()
5769e1db
C
55 }
56
1f30a185
C
57 isConfirmationDisabled () {
58 // No input validation
59 if (!this.inputLabel || !this.expectedInputValue) return false
60
61 return this.expectedInputValue !== this.inputValue
62 }
63
df98563e
C
64 showModal () {
65 this.confirmModal.show()
5769e1db
C
66 }
67
df98563e
C
68 hideModal () {
69 this.confirmModal.hide()
5769e1db
C
70 }
71}