1 import { Component, OnDestroy, OnInit, TemplateRef } from '@angular/core';
2 import { FormGroup } from '@angular/forms';
4 import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
5 import { Subscription } from 'rxjs';
8 selector: 'cd-confirmation-modal',
9 templateUrl: './confirmation-modal.component.html',
10 styleUrls: ['./confirmation-modal.component.scss']
12 export class ConfirmationModalComponent implements OnInit, OnDestroy {
18 // One of them is needed
19 bodyTpl?: TemplateRef<any>;
20 description?: TemplateRef<any>;
28 boundCancel = this.cancel.bind(this);
29 confirmationForm: FormGroup;
30 private onHide: Subscription;
31 private canceled = false;
33 constructor(public modalRef: BsModalRef, private modalService: BsModalService) {
34 this.confirmationForm = new FormGroup({});
35 this.onHide = this.modalService.onHide.subscribe((e: any) => {
36 if (this.onCancel && (e || this.canceled)) {
43 this.bodyContext = this.bodyContext || {};
44 this.bodyContext['$implicit'] = this.bodyData;
46 throw new Error('No submit action defined');
47 } else if (!this.buttonText) {
48 throw new Error('No action name defined');
49 } else if (!this.titleText) {
50 throw new Error('No title defined');
51 } else if (!this.bodyTpl && !this.description) {
52 throw new Error('No description defined');
57 this.onHide.unsubscribe();
65 stopLoadingSpinner() {
66 this.confirmationForm.setErrors({ cdSubmitButton: true });