]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-moderation/batch-domains-modal.component.ts
Fix moderation embeds
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-moderation / batch-domains-modal.component.ts
1 import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
3 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
4 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
5 import { DOMAINS_VALIDATOR, getNotEmptyHosts } from '../form-validators/batch-domains-validators'
6
7 @Component({
8 selector: 'my-batch-domains-modal',
9 templateUrl: './batch-domains-modal.component.html',
10 styleUrls: [ './batch-domains-modal.component.scss' ]
11 })
12 export class BatchDomainsModalComponent extends FormReactive implements OnInit {
13 @ViewChild('modal', { static: true }) modal: NgbModal
14 @Input() placeholder = 'example.com'
15 @Input() action: string
16 @Output() domains = new EventEmitter<string[]>()
17
18 private openedModal: NgbModalRef
19
20 constructor (
21 protected formValidatorService: FormValidatorService,
22 private modalService: NgbModal
23 ) {
24 super()
25 }
26
27 ngOnInit () {
28 if (!this.action) this.action = $localize`Process domains`
29
30 this.buildForm({
31 domains: DOMAINS_VALIDATOR
32 })
33 }
34
35 openModal () {
36 this.openedModal = this.modalService.open(this.modal, { centered: true })
37 }
38
39 hide () {
40 this.openedModal.close()
41 }
42
43 submit () {
44 this.domains.emit(
45 getNotEmptyHosts(this.form.controls['domains'].value)
46 )
47 this.form.reset()
48 this.hide()
49 }
50 }