]>
Commit | Line | Data |
---|---|---|
67ed6552 C |
1 | import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
2 | import { BatchDomainsValidatorsService, FormReactive, FormValidatorService } 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' | |
67ed6552 | 5 | import { I18n } from '@ngx-translate/i18n-polyfill' |
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 ( | |
21 | protected formValidatorService: FormValidatorService, | |
22 | private modalService: NgbModal, | |
23 | private batchDomainsValidatorsService: BatchDomainsValidatorsService, | |
24 | private i18n: I18n | |
25 | ) { | |
26 | super() | |
27 | } | |
28 | ||
29 | ngOnInit () { | |
30 | if (!this.action) this.action = this.i18n('Process domains') | |
31 | ||
32 | this.buildForm({ | |
33 | domains: this.batchDomainsValidatorsService.DOMAINS | |
34 | }) | |
35 | } | |
36 | ||
37 | openModal () { | |
38 | this.openedModal = this.modalService.open(this.modal, { centered: true }) | |
39 | } | |
40 | ||
41 | hide () { | |
42 | this.openedModal.close() | |
43 | } | |
44 | ||
45 | submit () { | |
46 | this.domains.emit( | |
47 | this.batchDomainsValidatorsService.getNotEmptyHosts(this.form.controls['domains'].value) | |
48 | ) | |
49 | this.form.reset() | |
50 | this.hide() | |
51 | } | |
52 | } |