import { Injectable } from '@angular/core'; import { NbDialogService } from '@nebular/theme'; import { AlertDlgComponent } from '../ui/alert-dlg/alert-dlg.component'; import { first, map, mergeMap } from 'rxjs/operators'; import { Observable } from 'rxjs'; import { MultiRecordPickerDlgComponent } from '../ui/fancy-table/multi-record-picker-dlg/multi-record-picker-dlg.component'; import { ObjectUtils } from '../utilities/object-utils'; import { MessageBoxConfig, ADIcon, ADButtons } from '../ui/alert-dlg/alert-dlg.model'; @Injectable({ providedIn: 'root' }) export class MsgBoxService { constructor( public dlgService: NbDialogService ) { } /** * Shows msg box * @param title * @param [text] * @param [config] Partial * @returns Ok,Yes:true, No,Close:false, Cancel:null */ show(title: string, config: Partial = {}): Observable { let defaultConfig = { buttons: ADButtons.OK } as Partial; Object.assign(defaultConfig, config); defaultConfig.title = title; return this.dlgService.open(AlertDlgComponent, { context: { config: new MessageBoxConfig(defaultConfig) }, closeOnBackdropClick: false, }).onClose.pipe(first()) } showMsg(config: Partial): Observable { return this.dlgService.open(AlertDlgComponent, { context: { config: new MessageBoxConfig(config) }, closeOnBackdropClick: false, }).onClose.pipe(first()) } showInputbox(title: string, text = '', config: Partial = { inputType: 'string', icon: ADIcon.QUESTION }): Observable { config.title = title; config.text = text; if (config.inputType === undefined) { config.inputType = 'string'; } if (config.icon === undefined) { config.icon = ADIcon.QUESTION; } if (config.buttons === undefined) { config.buttons = ADButtons.OKCancel; } return this.dlgService.open(AlertDlgComponent, { context: { config: new MessageBoxConfig(config) }, closeOnBackdropClick: false, }).onClose.pipe(first()); } showConfirmDeleteBox(config: Partial = { title: 'Delete This Record?', text: `Are you sure you want to delete it?`, icon: ADIcon.QUESTION, buttons: ADButtons.YesNo, confirmButtonText: 'Delete', cancelButtonText: "Cancel" }) { return this.show(config.title, config); } }