]>
Commit | Line | Data |
---|---|---|
67ed6552 | 1 | import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
5c5bcea2 | 2 | import { FormReactive, FormReactiveService } from '@app/shared/shared-forms' |
bb152476 RK |
3 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
4 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
4d029ef8 | 5 | import { splitAndGetNotEmpty, UNIQUE_HOSTS_VALIDATOR } from '../form-validators/host-validators' |
bb152476 RK |
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 ( | |
5c5bcea2 | 21 | protected formReactiveService: FormReactiveService, |
7ed1edbb | 22 | private modalService: NgbModal |
bb152476 RK |
23 | ) { |
24 | super() | |
25 | } | |
26 | ||
27 | ngOnInit () { | |
66357162 | 28 | if (!this.action) this.action = $localize`Process domains` |
bb152476 RK |
29 | |
30 | this.buildForm({ | |
4d029ef8 | 31 | hosts: UNIQUE_HOSTS_VALIDATOR |
bb152476 RK |
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 () { | |
4d029ef8 | 44 | this.domains.emit(splitAndGetNotEmpty(this.form.controls['hosts'].value)) |
bb152476 RK |
45 | this.form.reset() |
46 | this.hide() | |
47 | } | |
48 | } |