import { Component, ViewChild, Injector, Output, EventEmitter} from '@angular/core'; import { ModalDirective } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { SupportTicketSettingServiceProxy, SupportTicketSettingList, CreateSupportTicketSettingDto, TenantListDropDown, SupportTicketServiceProxy, UpdateSupportTicketSettingDto } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; declare var $: any; @Component({ selector: 'createOrEditTicketSettingModal', templateUrl: './create-or-edit-support-ticket-setting.component.html' }) export class CreateOrEditTicketSettingModalComponent 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(); ticketSetting: UpdateSupportTicketSettingDto = new UpdateSupportTicketSettingDto(); tenantList: TenantListDropDown[] = []; constructor( injector: Injector, private _settingServiceProxy: SupportTicketSettingServiceProxy, private _supportTicketsServiceProxy: SupportTicketServiceProxy ) { super(injector); } show(ticketSetting?: any): void { this.showAllTenant(); if (!ticketSetting) { this.ticketSetting = new CreateSupportTicketSettingDto(); this.active = true; this.modal.show(); } else { this.isActive = ticketSetting.isActive; this.ticketSetting = ticketSetting; this.active = true; this.modal.show(); } } save(): void { this.saving = true; if(this.ticketSetting.id) { this.ticketSetting.tenantId = Number($('#tenantSelect').val()); this.ticketSetting.isActive = this.isActive; this._settingServiceProxy.updateSupportTicketSetting(this.ticketSetting) .pipe(finalize(() => { this.saving = false;})) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } else { this.ticketSetting.tenantId = Number($('#tenantSelect').val()); this.ticketSetting.isActive = this.isActive; this._settingServiceProxy.createSupportTicketSetting(this.ticketSetting) .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(); } showAllTenant() : void { //this.active = true; jQuery(document).ready(function () { $('.kt-select2').select2(); $('.select2-container').css('width', '100%'); }); this._supportTicketsServiceProxy.getTenantForDropDown().subscribe((result) => { this.tenantList = result.items; }); } }