import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { OrderSourcesServiceProxy, CreateOrEditOrderSourceDto, OrderTypesServiceProxy, GetOrderTypeForViewDto } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; @Component({ selector: 'createOrEditOrderSourceModal', templateUrl: './create-or-edit-orderSource-modal.component.html' }) export class CreateOrEditOrderSourceModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; orderTypeList : GetOrderTypeForViewDto[]; isActive : number = 1 isHeaderFixed : number = 1; orderSource: CreateOrEditOrderSourceDto = new CreateOrEditOrderSourceDto(); constructor( injector: Injector, private _orderSourcesServiceProxy: OrderSourcesServiceProxy, private _orderTypeServiceProxy: OrderTypesServiceProxy ) { super(injector); } onShown(){ $('.kt-select2').select2(); } show(orderSourceId?: number): void { this.isActive = 1; this._orderTypeServiceProxy.getAllOrderTypeForTableDropdown().subscribe(result => { this.orderTypeList = result; }) if (!orderSourceId) { this.orderSource = new CreateOrEditOrderSourceDto(); this.orderSource.id = orderSourceId; this.active = true; this.modal.show(); } else { this._orderSourcesServiceProxy.getOrderSourceForEdit(orderSourceId).subscribe(result => { this.orderSource = result.orderSource; this.isActive = result.orderSource.isActive; this.isHeaderFixed = result.orderSource.isHeaderFixed; this.active = true; this.modal.show(); }); } } save(): void { this.saving = true; this.orderSource.isActive = this.isActive ? 1 : 0; this.orderSource.isHeaderFixed = this.isHeaderFixed ? 1 : 0; this.orderSource.orderTypeId = Number((document.getElementById('OrderSource_OrderType')).value); this._orderSourcesServiceProxy.createOrEdit(this.orderSource) .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(); } }