import { Directive , Input , Output , HostListener , EventEmitter , OnDestroy } from '@angular/core' ; import { PromptComponent , PromptDialogOptions } from '../prompt/prompt.component' ; import { UntilDestroy , untilDestroyed } from '@ngneat/until-destroy' ; import { NbDialogService } from '@nebular/theme' ; import { TranslationBaseComponent } from '../../language-base/translation-base.component' ; import { TranslateService } from '@ngx-translate/core' ; @ UntilDestroy ( { checkProperties : true } ) @ Directive ( { selector : '[ngxPromptDialog]' } ) export class PromptDirective extends TranslationBaseComponent implements OnDestroy { _label : string ; get label ( ) : string { return this . _label ; } @ Input ( ) set label ( value ) { this . _label = value ; } _title : string ; get title ( ) : string { return this . _title ; } @ Input ( ) set title ( value ) { this . _title = value ; } _okText : string = this . getTranslation ( 'BUTTONS.OK' ) ; get okText ( ) : string { return this . _okText ; } @ Input ( ) set okText ( value ) { this . _okText = value ; } _cancelText : string = this . getTranslation ( 'BUTTONS.CANCEL' ) ; get cancelText ( ) : string { return this . _cancelText ; } @ Input ( ) set cancelText ( value ) { this . _cancelText = value ; } _placeholder : string ; get placeholder ( ) : string { return this . _placeholder ; } @ Input ( ) set placeholder ( value ) { this . _placeholder = value ; } _inputType : PromptDialogOptions [ 'inputType' ] = 'text' ; get inputType ( ) : PromptDialogOptions [ 'inputType' ] { return this . _inputType ; } @ Input ( ) set inputType ( value ) { this . _inputType = value ; } @ Output ( ) callback = new EventEmitter < string | string [ ] > ( ) ; constructor ( private readonly dialogService , readonly translateService ) { super ( translateService ) ; } @ HostListener ( 'click' , [ '$event' ] ) onClick ( $event ) { $event . stopPropagation ( ) ; const { cancelText , inputType , label , okText , placeholder , title } = this ; const dialogRef = this . dialogService . open ( PromptComponent , { dialogClass : 'modal-lg' , context : { data : { cancelText , inputType , label , okText , placeholder , title } } } ) ; dialogRef . onClose . pipe ( untilDestroyed ( this ) ) . subscribe ( ( confirm ) => { if ( confirm ) { this . callback . emit ( confirm ) ; } } ) ; } ngOnDestroy ( ) { } }