import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { OrderServiceProxy, EditOrdeContactDetail } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; declare var $: any; @Component({ selector: 'editOrderContactDetailModal', templateUrl: './edit-order-contact-detail-modal.component.html' }) export class EditOrderContactDetailModalComponent extends AppComponentBase { @ViewChild('editOrderContactDetailModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; input: any; inputValue: EditOrdeContactDetail = new EditOrdeContactDetail(); phone: any; email: any; constructor( injector: Injector, private _orderAppService: OrderServiceProxy ) { super(injector); } show(contact): void { this.input = contact; console.log(this.input); if(this.input.phones != undefined) { this.phone = this.input.phones.value; this.inputValue.phoneId = this.input.phones.id; } else { this.inputValue.phoneId = null; } if(this.input.emails != undefined) { this.email = this.input.emails.value; this.inputValue.emailId = this.input.emails.id; } else { this.inputValue.emailId = null; } this.active = true; this.modal.show(); } save(): void { //console.log(this.input); this.saving = true; this.inputValue.id = this.input.id; this.inputValue.firstName = this.input.firstName; this.inputValue.lastName = this.input.lastName; this.inputValue.email = this.email; this.inputValue.phone = this.phone; this._orderAppService.editOrderContactDetail(this.inputValue) .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(); } }