]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | import { Location } from '@angular/common'; |
2 | import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; | |
3 | import { FormGroup, NgForm } from '@angular/forms'; | |
4 | ||
5 | import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; | |
6 | import { ModalService } from '~/app/shared/services/modal.service'; | |
7 | import { SubmitButtonComponent } from '../submit-button/submit-button.component'; | |
8 | ||
9 | @Component({ | |
10 | selector: 'cd-form-button-panel', | |
11 | templateUrl: './form-button-panel.component.html', | |
12 | styleUrls: ['./form-button-panel.component.scss'] | |
13 | }) | |
14 | export class FormButtonPanelComponent { | |
15 | @ViewChild(SubmitButtonComponent) | |
16 | submitButton: SubmitButtonComponent; | |
17 | ||
18 | @Output() | |
19 | submitActionEvent = new EventEmitter(); | |
20 | @Output() | |
21 | backActionEvent = new EventEmitter(); | |
22 | ||
23 | @Input() | |
24 | form: FormGroup | NgForm; | |
25 | @Input() | |
26 | showSubmit = true; | |
27 | @Input() | |
28 | wrappingClass = ''; | |
29 | @Input() | |
30 | btnClass = ''; | |
31 | @Input() | |
32 | submitText: string = this.actionLabels.CREATE; | |
33 | @Input() | |
34 | cancelText: string = this.actionLabels.CANCEL; | |
35 | @Input() | |
36 | disabled = false; | |
37 | ||
38 | constructor( | |
39 | private location: Location, | |
40 | private actionLabels: ActionLabelsI18n, | |
41 | private modalService: ModalService | |
42 | ) {} | |
43 | ||
44 | submitAction() { | |
45 | this.submitActionEvent.emit(); | |
46 | } | |
47 | ||
48 | backAction() { | |
49 | if (this.backActionEvent.observers.length === 0) { | |
50 | if (this.modalService.hasOpenModals()) { | |
51 | this.modalService.dismissAll(); | |
52 | } else { | |
53 | this.location.back(); | |
54 | } | |
55 | } else { | |
56 | this.backActionEvent.emit(); | |
57 | } | |
58 | } | |
59 | } |