import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { SmsAccountsServiceProxy, CreateOrEditSmsAccountDto } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; @Component({ selector: 'createOrEditSmsAccountModal', templateUrl: './create-or-edit-smsAccount-modal.component.html' }) export class CreateOrEditSmsAccountModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; smsAccount: CreateOrEditSmsAccountDto = new CreateOrEditSmsAccountDto(); constructor( injector: Injector, private _smsAccountsServiceProxy: SmsAccountsServiceProxy ) { super(injector); } show(smsAccountId?: number): void { if (!smsAccountId) { this.smsAccount = new CreateOrEditSmsAccountDto(); this.smsAccount.id = smsAccountId; this.active = true; this.modal.show(); } else { this._smsAccountsServiceProxy.getSmsAccountForEdit(smsAccountId).subscribe(result => { this.smsAccount = result.smsAccount; this.active = true; this.modal.show(); }); } } save(): void { this.saving = true; this._smsAccountsServiceProxy.createOrEdit(this.smsAccount) .pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } close(): void { this.active = false; this.modal.hide(); } }