aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/config/shared/batch-domains-modal.component.ts
blob: 620f2726b8e30a558c6546dc6d11e6ef5fd6bc87 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Component, OnInit, ViewChild, Input, Output, EventEmitter } from '@angular/core'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
import { FormReactive } from '@app/shared/forms'
import { BatchDomainsValidatorsService } from './batch-domains-validators.service'

@Component({
  selector: 'my-batch-domains-modal',
  templateUrl: './batch-domains-modal.component.html',
  styleUrls: [ './batch-domains-modal.component.scss' ]
})
export class BatchDomainsModalComponent extends FormReactive implements OnInit {
  @ViewChild('modal', { static: true }) modal: NgbModal
  @Input() placeholder = 'example.com'
  @Input() action: string
  @Output() domains = new EventEmitter<string[]>()

  private openedModal: NgbModalRef

  constructor (
    protected formValidatorService: FormValidatorService,
    private modalService: NgbModal,
    private batchDomainsValidatorsService: BatchDomainsValidatorsService,
    private i18n: I18n
  ) {
    super()
  }

  ngOnInit () {
    if (!this.action) this.action = this.i18n('Process domains')

    this.buildForm({
      domains: this.batchDomainsValidatorsService.DOMAINS
    })
  }

  openModal () {
    this.openedModal = this.modalService.open(this.modal, { centered: true })
  }

  hide () {
    this.openedModal.close()
  }

  submit () {
    this.domains.emit(
      this.batchDomainsValidatorsService.getNotEmptyHosts(this.form.controls['domains'].value)
    )
    this.form.reset()
    this.hide()
  }
}