1 import { Component, OnDestroy, OnInit, TemplateRef } from '@angular/core';
2 import { FormGroup } 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>;
27 boundCancel = this.cancel.bind(this);
28 confirmationForm: FormGroup;
29 private canceled = false;
31 constructor(public activeModal: NgbActiveModal) {
32 this.confirmationForm = new FormGroup({});
36 this.bodyContext = this.bodyContext || {};
37 this.bodyContext['$implicit'] = this.bodyData;
39 throw new Error('No submit action defined');
40 } else if (!this.buttonText) {
41 throw new Error('No action name defined');
42 } else if (!this.titleText) {
43 throw new Error('No title defined');
44 } else if (!this.bodyTpl && !this.description) {
45 throw new Error('No description defined');
50 if (this.onCancel && this.canceled) {
57 this.activeModal.close();
60 stopLoadingSpinner() {
61 this.confirmationForm.setErrors({ cdSubmitButton: true });