import {Component, ViewEncapsulation, ElementRef, EventEmitter, Output, Input} from '@angular/core'; @Component({ selector: 'modal-alert', template: ` `, encapsulation: ViewEncapsulation.None, }) /** * API to an open alert window. */ export class AlertModal { @Input() classBody: string =""; /** * Caption for the title. */ public alertTitle: string; /** * Describes if the alert contains Ok Button. * The default Ok button will close the alert and emit the callback. * Defaults to true. */ public okButton: boolean = true; /** * Caption for the OK button. * Default: Ok */ public okButtonText: string = 'Ok'; /** * Describes if the alert contains cancel Button. * The default Cancelbutton will close the alert. * Defaults to true. */ public cancelButton: boolean = true; /** * Caption for the Cancel button. * Default: Cancel */ public cancelButtonText: string = 'Cancel'; /** * if the alertMessage is true it will show the contentString inside alert body. */ public alertMessage: boolean = true; /** * Some message/content can be set in message which will be shown in alert body. */ public message: string; /** * if the value is true alert footer will be visible or else it will be hidden. */ public alertFooter: boolean = true; /** * shows alert header if the value is true. */ public alertHeader: boolean = true; /** * if the value is true alert will be visible or else it will be hidden. */ public isOpen: boolean = false; /** * if the value is true ok button align on the left, else on the right */ public okButtonLeft: boolean = true; /** * if the value is true ok button is disabled */ @Input() public okDisabled: boolean = false; @Input() public choice: boolean = false; public select: boolean = false; /** * Emitted when a ok button was clicked * or when Ok method is called. */ @Output() public alertOutput: EventEmitter = new EventEmitter(); @Output() public clickOutsideOutput: EventEmitter = new EventEmitter(); constructor(public _elementRef: ElementRef) { } /** * Opens a alert window creating backdrop. */ open() { this.isOpen = true; event.stopPropagation(); } /** * ok method closes the modal and emits modalOutput. */ ok() { this.isOpen = false; if (!this.choice) { this.alertOutput.emit(true); } else { this.alertOutput.emit({ value: true, choice: this.select }); } } /** * cancel method closes the moda. */ cancel() { this.isOpen = false; } clickOutside(event: Object) { if(event && event['value'] === true) { this.cancel(); this.clickOutsideOutput.emit( { value: true }); } } }