import { AfterViewInit } from '@angular/core'; import { RdComponent } from './rdComponent'; import { AppComponent } from '../app.component'; export class SweetAlertOptions { width = 300; height = 200; shading = true; shadingColor = 'rgba(0, 0, 0, 0.5)'; titleTemplate = null; position = { my: 'center', at: 'center' }; fullScreen = false; dragEnable = true; showTitle = true; showCloseButton = true; closeOnOutsideClick = true; } export abstract class RdSweetAlert extends RdComponent implements AfterViewInit { element; options = new SweetAlertOptions(); onClose = function (data) { }; private dxSweetAlertInstance; public static open() { var onloadCallback; var onCloseCallback; var promise = { onLoad: (callback: (controller) => void) => { onloadCallback = callback; return promise; }, onDismiss: (callback: (data: any) => void) => { AppComponent.instance.sweetAlertInstance.open(this, (controller) => { controller.onClose = callback; if (onloadCallback) onloadCallback(controller); }); return promise; } }; return promise; } close(data?) { this.onClose(data); AppComponent.instance.sweetAlertInstance.close(); } ngAfterViewInit() { var container = this.jQuery(this.element.nativeElement); this.dxSweetAlertInstance = container.dxPopup(this.options).dxPopup("instance"); this.dxSweetAlertInstance.show(); } }