1 import { Component, OnDestroy, OnInit, TemplateRef } from '@angular/core';
2 import { UntypedFormGroup } from '@angular/forms';
4 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
7 selector: 'cd-confirmation-modal',
8 templateUrl: './confirmation-modal.component.html',
9 styleUrls: ['./confirmation-modal.component.scss']
11 export class ConfirmationModalComponent implements OnInit, OnDestroy {
17 // One of them is needed
18 bodyTpl?: TemplateRef<any>;
19 description?: TemplateRef<any>;
30 boundCancel = this.cancel.bind(this);
31 confirmationForm: UntypedFormGroup;
32 private canceled = false;
34 constructor(public activeModal: NgbActiveModal) {
35 this.confirmationForm = new UntypedFormGroup({});
39 this.bodyContext = this.bodyContext || {};
40 this.bodyContext['$implicit'] = this.bodyData;
42 throw new Error('No submit action defined');
43 } else if (!this.buttonText) {
44 throw new Error('No action name defined');
45 } else if (!this.titleText) {
46 throw new Error('No title defined');
47 } else if (!this.bodyTpl && !this.description) {
48 throw new Error('No description defined');
53 if (this.onCancel && this.canceled) {
60 this.activeModal.close();
63 stopLoadingSpinner() {
64 this.confirmationForm.setErrors({ cdSubmitButton: true });