]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
17f6001146f0361db2515a4af5ff0dc7a6fe95c0
[ceph-ci.git] /
1 import { Location } from '@angular/common';
2 import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
3 import { UntypedFormGroup, 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 implements OnInit {
15   @ViewChild(SubmitButtonComponent)
16   submitButton: SubmitButtonComponent;
17
18   @Output()
19   submitActionEvent = new EventEmitter();
20   @Output()
21   backActionEvent = new EventEmitter();
22
23   @Input()
24   form: UntypedFormGroup | NgForm;
25   @Input()
26   showSubmit = true;
27   @Input()
28   showCancel = true;
29   @Input()
30   wrappingClass = '';
31   @Input()
32   btnClass = '';
33   @Input()
34   submitText?: string;
35   @Input()
36   cancelText?: string;
37   @Input()
38   disabled = false;
39
40   constructor(
41     private location: Location,
42     private actionLabels: ActionLabelsI18n,
43     private modalService: ModalService
44   ) {}
45
46   ngOnInit() {
47     this.submitText = this.submitText || this.actionLabels.CREATE;
48     this.cancelText = this.cancelText || this.actionLabels.CANCEL;
49   }
50
51   submitAction() {
52     this.submitActionEvent.emit();
53   }
54
55   backAction() {
56     if (this.backActionEvent.observers.length === 0) {
57       if (this.modalService.hasOpenModals()) {
58         this.modalService.dismissAll();
59       } else {
60         this.location.back();
61       }
62     } else {
63       this.backActionEvent.emit();
64     }
65   }
66 }