import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { SupportTicketStatusServiceProxy, TicketStatusList, CreateTicketStatusDto, UpdateTicketStatusDto } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; declare var $: any; @Component({ selector: 'createOrEditTicketStatusModal', templateUrl: './create-or-edit-status.component.html' }) export class CreateOrEditTicketStatusModalComponent extends AppComponentBase { @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; isActive = false; selectedStartDay:string; selectedEndDay:string; //createTicketType: CreateTicketStatusDto = new CreateTicketStatusDto(); ticketStatus: UpdateTicketStatusDto = new UpdateTicketStatusDto(); constructor( injector: Injector, private _statusServiceProxy: SupportTicketStatusServiceProxy ) { super(injector); } show(ticketStatus?: any): void { if (!ticketStatus) { this.ticketStatus = new CreateTicketStatusDto(); this.active = true; this.modal.show(); } else { this.ticketStatus = ticketStatus; if(this.ticketStatus.inactive == false) { this.isActive = true; } this.active = true; this.modal.show(); } } save(): void { this.saving = true; if(this.isActive == true) { this.ticketStatus.inactive = false; } else { this.ticketStatus.inactive = true; } if(this.ticketStatus.id) { this._statusServiceProxy.updateTicketStatus(this.ticketStatus) .pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } else { this._statusServiceProxy.createTicketStatus(this.ticketStatus) .pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } } close(): void { this.active = false; this.isActive = false; this.modal.hide(); } }