]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/core/confirm/confirm.component.ts
Register service worker
[github/Chocobozzz/PeerTube.git] / client / src / app / core / confirm / confirm.component.ts
1 import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
2
3 import { ModalDirective } from 'ngx-bootstrap/modal'
4
5 import { ConfirmService } from './confirm.service'
6
7 export interface ConfigChangedEvent {
8 columns: { [id: string]: { isDisplayed: boolean } }
9 config: { resultsPerPage: number }
10 }
11
12 @Component({
13 selector: 'my-confirm',
14 templateUrl: './confirm.component.html',
15 styles: [ '.button { padding: 0 13px; }' ]
16 })
17 export class ConfirmComponent implements OnInit {
18 @ViewChild('confirmModal') confirmModal: ModalDirective
19
20 title = ''
21 message = ''
22
23 constructor (private confirmService: ConfirmService) {
24 // Empty
25 }
26
27 ngOnInit () {
28 this.confirmModal.config = {
29 backdrop: 'static',
30 keyboard: false
31 }
32
33 this.confirmService.showConfirm.subscribe(
34 ({ title, message }) => {
35 this.title = title
36 this.message = message
37
38 this.showModal()
39 }
40 )
41 }
42
43 @HostListener('keydown.enter')
44 confirm () {
45 this.confirmService.confirmResponse.next(true)
46 this.hideModal()
47 }
48
49 @HostListener('keydown.esc')
50 cancel () {
51 this.confirmService.confirmResponse.next(false)
52 this.hideModal()
53 }
54
55 showModal () {
56 this.confirmModal.show()
57 }
58
59 hideModal () {
60 this.confirmModal.hide()
61 }
62 }