import { Component, ViewChild, Injector, Output, EventEmitter } from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { SupportTicketStatusServiceProxy, TicketStatusList, CreateTicketStatusDto, UpdateTicketStatusDto, TicketStatusCodeDto } 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; isPublic = false; selectedStartDay: string; selectedEndDay: string; //createTicketType: CreateTicketStatusDto = new CreateTicketStatusDto(); ticketStatus: UpdateTicketStatusDto = new UpdateTicketStatusDto(); parentStatusType: TicketStatusCodeDto[]; constructor( injector: Injector, private _statusServiceProxy: SupportTicketStatusServiceProxy ) { super(injector); } show(ticketStatus?: any): void { this.getParentStatusType(); if (!ticketStatus) { this.ticketStatus = new CreateTicketStatusDto(); this.ticketStatus.color = '#000000'; this.active = true; this.modal.show(); } else { this.ticketStatus = ticketStatus; if (this.ticketStatus.inactive == false) { this.isActive = true; } this.active = true; this.isPublic = this.ticketStatus.isPublic; this.modal.show(); } } onShown() { $('.kt-select2').select2(); } save(): void { this.saving = true; if (this.isActive == true) { this.ticketStatus.inactive = false; } else { this.ticketStatus.inactive = true; } this.ticketStatus.isPublic = this.isPublic; if (this.ticketStatus.id) { this.ticketStatus.parentStatusTypeId = Number($('#parentStatusId').val()); if (this.ticketStatus.parentStatusTypeId == 0) { (document.getElementById('parentStatusDiv')).style.color = "#fd397a"; this.saving = false; } else { 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.ticketStatus.parentStatusTypeId = Number($('#parentStatusId').val()); if (this.ticketStatus.parentStatusTypeId == 0) { (document.getElementById('parentStatusDiv')).style.color = "#fd397a"; this.saving = false; } 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.isPublic = false; this.modal.hide(); } getParentStatusType() { this._statusServiceProxy.getParentTicketStatusType().subscribe(result => { this.parentStatusType = result; }); } }