]>
Commit | Line | Data |
---|---|---|
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 { splitAndGetNotEmpty, UNIQUE_HOSTS_VALIDATOR } from '../form-validators/host-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 | hosts: UNIQUE_HOSTS_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(splitAndGetNotEmpty(this.form.controls['hosts'].value)) | |
45 | this.form.reset() | |
46 | this.hide() | |
47 | } | |
48 | } |