import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { RouteSchedulesServiceProxy, CreateOrEditRouteScheduleDto } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; import { RouteScheduleClinicLookupTableModalComponent } from './routeSchedule-clinic-lookup-table-modal.component'; @Component({ selector: 'createOrEditRouteScheduleModal', templateUrl: './create-or-edit-routeSchedule-modal.component.html' }) export class CreateOrEditRouteScheduleModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @ViewChild('routeScheduleClinicLookupTableModal', { static: true }) routeScheduleClinicLookupTableModal: RouteScheduleClinicLookupTableModalComponent; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; routeSchedule: CreateOrEditRouteScheduleDto = new CreateOrEditRouteScheduleDto(); clinicClinicAccountNumber = ''; constructor( injector: Injector, private _routeSchedulesServiceProxy: RouteSchedulesServiceProxy ) { super(injector); } show(routeScheduleId?: number): void { if (!routeScheduleId) { this.routeSchedule = new CreateOrEditRouteScheduleDto(); this.routeSchedule.id = routeScheduleId; this.clinicClinicAccountNumber = ''; this.active = true; this.modal.show(); } else { this._routeSchedulesServiceProxy.getRouteScheduleForEdit(routeScheduleId).subscribe(result => { this.routeSchedule = result.routeSchedule; this.clinicClinicAccountNumber = result.clinicClinicAccountNumber; this.active = true; this.modal.show(); }); } } save(): void { this.saving = true; this._routeSchedulesServiceProxy.createOrEdit(this.routeSchedule) .pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } openSelectClinicModal() { this.routeScheduleClinicLookupTableModal.id = this.routeSchedule.clinicId; this.routeScheduleClinicLookupTableModal.displayName = this.clinicClinicAccountNumber; this.routeScheduleClinicLookupTableModal.show(); } setClinicIdNull() { this.routeSchedule.clinicId = null; this.clinicClinicAccountNumber = ''; } getNewClinicId() { this.routeSchedule.clinicId = this.routeScheduleClinicLookupTableModal.id; this.clinicClinicAccountNumber = this.routeScheduleClinicLookupTableModal.displayName; } close(): void { this.active = false; this.modal.hide(); } }