import { Component, ViewChild, Injector, Output, EventEmitter, OnInit } from '@angular/core'; import { ModalDirective, TabsetComponent } from 'ngx-bootstrap'; import { finalize } from 'rxjs/operators'; import { RouteHandOffDefinitionsServiceProxy, CreateOrEditRouteHandOffDefinitionDto, GetManagerListDto, RouteStopsServiceProxy, GetRouteStopForViewDto, LocationServiceProxy, LocationListDto, LocationNameDto, DriversServiceProxy, OrderIncidentsServiceProxy, GetAllRouteStopsInput, UserListDto, OrganizationUnitDto, RouteNotificationRecipientDto, OrderNotificationsServiceProxy, StopTypeCode } from '@shared/service-proxies/service-proxies'; import { AppComponentBase } from '@shared/common/app-component-base'; import * as moment from 'moment'; import { RouteHandOffDefinitionRouteTemplateLookupTableModalComponent } from './routeHandOffDefinition-routeTemplate-lookup-table-modal.component'; import { RouteHandOffDefinitionRouteTypeLookupTableModalComponent } from './routeHandOffDefinition-routeType-lookup-table-modal.component'; import { AppSessionService } from '@shared/common/session/app-session.service'; import { CommonLookupModalComponent } from '@app/shared/common/lookup/common-lookup-modal.component'; declare let $: any; @Component({ selector: 'createOrEditRouteHandOffDefinitionModal', templateUrl: './create-or-edit-routeHandOffDefinition-modal.component.html' }) export class CreateOrEditRouteHandOffDefinitionModalComponent extends AppComponentBase implements OnInit { @ViewChild('routeHandOffDefinitionTab', { static: false }) staticTabs: TabsetComponent; @ViewChild('createOrEditModal', { static: true }) modal: ModalDirective; @ViewChild('routeStartList', {static: true}) routeStartList: CommonLookupModalComponent; @ViewChild('routeStopList', {static: true}) routeStopList: CommonLookupModalComponent; @ViewChild('routeHandOffDefinitionRouteTemplateLookupTableModal', { static: true }) routeHandOffDefinitionRouteTemplateLookupTableModal: RouteHandOffDefinitionRouteTemplateLookupTableModalComponent; @ViewChild('routeHandOffDefinitionRouteTypeLookupTableModal', { static: true }) routeHandOffDefinitionRouteTypeLookupTableModal: RouteHandOffDefinitionRouteTypeLookupTableModalComponent; @ViewChild('driverList', {static: true}) driverList: CommonLookupModalComponent; @ViewChild('managerList', {static: true}) managerList: CommonLookupModalComponent; @Output() modalSave: EventEmitter = new EventEmitter(); active = false; saving = false; routeHandOffDefinition: CreateOrEditRouteHandOffDefinitionDto = new CreateOrEditRouteHandOffDefinitionDto(); maxcount = 1000; routeTemplateName = ''; routeTypeRouteTypeCode = ''; getManagersListDto: GetManagerListDto[]; getRouteStops: GetRouteStopForViewDto[] = []; locations: LocationNameDto[]; currentDate: Date; routeTypes: any; drivers: Array; managers: Array; activeStatus: boolean; eta: any; cutOff: any; toSave: true; startTime: any; onDemand: boolean; endTime: any; showSearchOnRouteStop : boolean; showSearchOnRouteStart : boolean; showSearchOnRouteCode : boolean routeStart : string; routeStop : string; searchRouteStop : boolean; routeStopId : number; routeStartId : number; allUsers: UserListDto[]; allOrganizationUnits: OrganizationUnitDto[]; supervisors: RouteNotificationRecipientDto[] = []; addSupervisors: any; delete: any; supervisorList: Array = []; searchDay : string userField : string mondayDriverFilter tuesdayDriverFilter wednesdayDriverFilter thursdayDriverFilter fridayDriverFilter saturdayDriverFilter sundayDriverFilter sundayManagerFilter mondayManagerFilter tuesdayManagerFilter wednesdayManagerFilter thursdayManagerFilter fridayManagerFilter saturdayManagerFilter sundaySupervisorFilter mondaySupervisorFilter tuesdaySupervisorFilter wednesdaySupervisorFilter thursdaySupervisorFilter fridaySupervisorFilter saturdaySupervisorFilter constructor( injector: Injector, private _routeHandOffDefinitionsServiceProxy: RouteHandOffDefinitionsServiceProxy, private _routeStopsServiceProxy: RouteStopsServiceProxy, private _locationServiceProxy: LocationServiceProxy, private _driverServiceProxy: DriversServiceProxy, private _orderIncidentAppService: OrderIncidentsServiceProxy, private _appSessionService: AppSessionService, private _orderNotificationsServiceProxy: OrderNotificationsServiceProxy ) { super(injector); } ngOnInit(): void { this.routeStopModalInit(); this.driverListModalInit(); } routeStopModalInit() { this.routeStartList.configure({ title: this.l('Select Stop'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = new GetAllRouteStopsInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.stopType = StopTypeCode.StartPoint; return this._routeStopsServiceProxy.showPagedRouteStop(input); } }); this.routeStopList.configure({ title: this.l('Select Stop'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = new GetAllRouteStopsInput(); input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; input.stopType = StopTypeCode.EndPoint; return this._routeStopsServiceProxy.showPagedRouteStop(input); } }); } driverListModalInit(){ this.driverList.configure({ title: this.l('Select driver'), dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = {filter,maxResultCount,skipCount}; input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; return this._driverServiceProxy.getPagedDriverList( input.filter,undefined,input.skipCount,input.maxResultCount); } }); } managerListModalInit(){ this.managerList.configure({ title: this.l('Select ') + this.userField, dataSource: (skipCount: number, maxResultCount: number, filter: string, tenantId?: number, locationId?:number) => { let input = {filter,maxResultCount,skipCount}; input.filter = filter; input.maxResultCount = maxResultCount; input.skipCount = skipCount; return this._orderIncidentAppService.getPagedManagerList(input.filter, 0, undefined ,input.skipCount, input.maxResultCount); } }); } onShow(){ let toggleStartActive = (bool) => { return this.routeStartActiveToggle(bool) } $('#routeStartOption').on('select2:select', function (e) { if($('#routeStartOption').val() == '0'){ toggleStartActive(false) } else{ toggleStartActive(true) } }); } getRouteStop(routeStopFilter : any){ this.searchRouteStop = true; this.routeStopList.show(); this.routeStopList.filterText = routeStopFilter; } getRouteStart(routeStartFilter : any){ this.searchRouteStop = false; this.routeStartList.show(); this.routeStartList.filterText = routeStartFilter; } clearRouteStop(){ this.routeStop = ''; this.routeStopId = null; this.showSearchOnRouteStop = true; } clearRouteStart(){ this.routeStart = ''; this.routeStartId = null; this.showSearchOnRouteStart = true; } selectRouteStop(item){ var resultId = item.value; var name = item.name if(this.searchRouteStop){ this.routeStopId = resultId; this.routeStop = name; this.searchRouteStop = false; this.showSearchOnRouteStop = false; } else{ this.routeStartId = resultId; this.routeStart = name; this.showSearchOnRouteStart = false; } } show(routeHandOffDefinitionId?: number): void { this.showSearchOnRouteStop = true; this.showSearchOnRouteStart = true; this.showSearchOnRouteCode = true; this.routeStartId = null; this.routeStopId = null; this.supervisors = []; this.allOrganizationUnits = []; this.allUsers = []; this._orderNotificationsServiceProxy.getAllUserForTableDropdown().subscribe(result => { this.allUsers = result; }); this._orderNotificationsServiceProxy.getAllOrgUnitsForTableDropdown().subscribe(result => { this.allOrganizationUnits = result; }); if (!routeHandOffDefinitionId) { this.routeHandOffDefinition = new CreateOrEditRouteHandOffDefinitionDto(); this.getAllDropDowns(); this.initDriverFields(); this.initManagerFields() this.routeHandOffDefinition.id = routeHandOffDefinitionId; this.routeHandOffDefinition.assignedDate = moment().startOf('day'); this.routeTemplateName = ''; this.routeTypeRouteTypeCode = ''; this.eta = ''; this.startTime = ''; this.endTime = ''; this.onDemand = false; this.routeStart = ''; this.routeStop = ''; this.active = true; this.modal.show(); } else { this._routeHandOffDefinitionsServiceProxy.getRouteHandOffDefinitionForEdit(routeHandOffDefinitionId).subscribe(result => { this.getAllDropDowns(); this.routeHandOffDefinition = result.routeHandOffDefinition; this.routeHandOffDefinition.routeCode = result.routeTemplateName; this.routeTypeRouteTypeCode = result.routeTypeRouteTypeCode; this.routeHandOffDefinition.routeTypeId = result.routeHandOffDefinition.routeTypeId; this.eta = result.routeHandOffDefinition.eta.toDate(); this.cutOff = result.routeHandOffDefinition.cutOff.toDate(); this.activeStatus = !this.routeHandOffDefinition.inactive; this.startTime = moment(moment(this.currentDate).format('ddd MMM DD YYYY') + ' ' + result.routeHandOffDefinition.startTime + ':00').toDate(); this.endTime = moment(moment(this.currentDate).format('ddd MMM DD YYYY') + ' ' + result.routeHandOffDefinition.endTime + ':00').toDate(); this.onDemand = result.routeHandOffDefinition.isOnDemand; this.showSearchOnRouteCode = false; this.initDriverFields(); this.initManagerFields() if(result.routeHandOffDefinition.routeNotificationRecipients != undefined) { this.supervisors = result.routeHandOffDefinition.routeNotificationRecipients; let s = this; setTimeout(() => { $('.organization-unit').on('select2:select', function (e) { s.updateUnits($(e.currentTarget).attr('id'), $(e.currentTarget).val()); }); $('.user').on('select2:select', function (e) { s.updateUsers($(e.currentTarget).attr('id'), $(e.currentTarget).val()); }); }, 100); } if(result.routeHandOffDefinition.routeStartContactId != null){ this._routeStopsServiceProxy.getRouteStop(result.routeHandOffDefinition.routeStartContactId) .subscribe(res => { if (res.routeStop != undefined) { this.showSearchOnRouteStart = false; this.routeStartId = result.routeHandOffDefinition.routeStartContactId; this.routeStart = res.routeStop.company + ' - ' + res.contactAddress } else { this.routeStartId = null; } }); } this._routeStopsServiceProxy.getRouteStop(result.routeHandOffDefinition.defaultContactId) .subscribe(res => { if (res.routeStop != undefined){ this.showSearchOnRouteStop = false; this.routeStopId = result.routeHandOffDefinition.defaultContactId; this.routeStop = res.routeStop.company + ' - ' + res.contactAddress } else { this.routeStopId = null; } }); this.active = true; this.modal.show(); }); } } save(): void { let drivers = []; this.saving = true; this.routeHandOffDefinition.locationId = Number((document.getElementById('txtLocation')).value); this.routeHandOffDefinition.routeStartContactId = this.routeStartId == null ? null :this.routeStartId ; this.routeHandOffDefinition.defaultContactId = this.routeStopId; this.routeHandOffDefinition.managerId = Number((document.getElementById('selectedManager')).value) == 0 ? null : Number((document.getElementById('selectedManager')).value); this.routeHandOffDefinition.assignedById = this._appSessionService.userId; this.routeHandOffDefinition.defaultUserId = this.routeHandOffDefinition.sundayDriverId != null && this.routeHandOffDefinition.sundayDriverId != 0 ? this.routeHandOffDefinition.sundayDriverId : this.routeHandOffDefinition.mondayDriverId != null && this.routeHandOffDefinition.mondayDriverId != 0 ? this.routeHandOffDefinition.mondayDriverId : this.routeHandOffDefinition.tuesdayDriverId != null && this.routeHandOffDefinition.tuesdayDriverId != 0 ? this.routeHandOffDefinition.tuesdayDriverId : this.routeHandOffDefinition.wednesdayDriverId != null && this.routeHandOffDefinition.wednesdayDriverId != 0 ? this.routeHandOffDefinition.wednesdayDriverId : this.routeHandOffDefinition.thursdayDriverId != null && this.routeHandOffDefinition.thursdayDriverId != 0 ? this.routeHandOffDefinition.thursdayDriverId : this.routeHandOffDefinition.fridayDriverId != null && this.routeHandOffDefinition.fridayDriverId != 0 ? this.routeHandOffDefinition.fridayDriverId : this.routeHandOffDefinition.saturdayDriverId != null && this.routeHandOffDefinition.saturdayDriverId != 0 ? this.routeHandOffDefinition.saturdayDriverId : 0; this.routeHandOffDefinition.inactive = !this.activeStatus; this.routeHandOffDefinition.isOnDemand = this.onDemand; this.routeHandOffDefinition.routeTemplateTypeId = 1; this.routeHandOffDefinition.routeTypeId = Number((document.getElementById('routeType')).value); this.routeHandOffDefinition.eta = this.eta; this.routeHandOffDefinition.cutOff = this.cutOff; this.routeHandOffDefinition.endTime = new Date(this.endTime).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; this.routeHandOffDefinition.startTime = new Date(this.startTime).toLocaleTimeString('en-US', { hour12: true, hour: "numeric", minute: "numeric", second: "numeric" }) as any; if (this.routeHandOffDefinition.routeTypeId === 0) { this.saving = false; (document.getElementById('routeTypeDiv')).style.color = '#FF3300'; } if (this.routeHandOffDefinition.defaultContactId === 0) { this.saving = false; (document.getElementById('routeStopDiv')).style.color = '#FF3300'; } if (this.routeHandOffDefinition.locationId === 0) { this.saving = false; (document.getElementById('locationDiv')).style.color = '#FF3300'; } if(this.supervisors.length != 0) { //this.routeDefinition.supervisors = this.supervisors; for (var i = 0; i < this.supervisors.length; i++) { let a = new RouteNotificationRecipientDto({ isEmail: this.supervisors[i].isEmail, tenantId: null, isActive: this.supervisors[i].isActive, emailAddress: this.supervisors[i].emailAddress, code: this.supervisors[i].code, organizationUnitId: this.supervisors[i].organizationUnitId, userId: this.supervisors[i].userId, routeTemplateId: this.supervisors[i].routeTemplateId, id: this.supervisors[i].id, isSMS:this.supervisors[i].isSMS }); this.supervisorList.push(a); } this.routeHandOffDefinition.routeNotificationRecipients = this.supervisorList; } if (this.saving == true) { this._routeHandOffDefinitionsServiceProxy.createOrEdit(this.routeHandOffDefinition) .pipe( finalize(() => { this.saving = false; }) ) .subscribe(() => { this.notify.info(this.l('SavedSuccessfully')); this.close(); this.modalSave.emit(null); }); } } openSelectRouteTemplateModal() { this.routeHandOffDefinitionRouteTemplateLookupTableModal.filterText = this.routeHandOffDefinition.routeCode; this.routeHandOffDefinitionRouteTemplateLookupTableModal.id = this.routeHandOffDefinition.routeTemplateId; this.routeHandOffDefinitionRouteTemplateLookupTableModal.displayName = this.routeHandOffDefinition.routeCode; this.routeHandOffDefinitionRouteTemplateLookupTableModal.displayName = this.routeTemplateName; this.routeHandOffDefinitionRouteTemplateLookupTableModal.show(); } openSelectRouteTypeModal() { this.routeHandOffDefinitionRouteTypeLookupTableModal.id = this.routeHandOffDefinition.routeTypeId; this.routeHandOffDefinitionRouteTypeLookupTableModal.displayName = this.routeTypeRouteTypeCode; this.routeHandOffDefinitionRouteTypeLookupTableModal.show(); } setRouteTemplateIdNull() { this.showSearchOnRouteCode = true; this.routeHandOffDefinition.routeTemplateId = null; this.routeHandOffDefinition.routeCode = ''; this.routeTemplateName = ''; } setRouteTypeIdNull() { this.routeHandOffDefinition.routeTypeId = null; this.routeTypeRouteTypeCode = ''; } getNewRouteTemplateId() { this.showSearchOnRouteCode = false; this.routeHandOffDefinition.routeTemplateId = this.routeHandOffDefinitionRouteTemplateLookupTableModal.id; this.routeHandOffDefinition.routeCode = this.routeHandOffDefinitionRouteTemplateLookupTableModal.displayName; this.routeTemplateName = this.routeHandOffDefinitionRouteTemplateLookupTableModal.displayName; } getNewRouteTypeId() { this.routeHandOffDefinition.routeTypeId = this.routeHandOffDefinitionRouteTypeLookupTableModal.id; this.routeTypeRouteTypeCode = this.routeHandOffDefinitionRouteTypeLookupTableModal.displayName; } close(): void { this.active = false; this.modal.hide(); } getAllDropDowns() { jQuery(document).ready(function() { $('.kt-select2').select2(); // $('.select2-container').css('width', '100%'); $('.route-driver').on('select2:select', function (e) { for (let index = 0; index < $('.route-driver').length; index++) { if ($('.route-driver').eq(index).val() == '') { $('.route-driver').eq(index).val(this.value); } } $('.route-driver').trigger('change'); }); }); //this.getFilterRouteManagers(); this.getManagers(); // this.getStops(); this.getLocations(); //this.getDrivers(); this.getRouteTypes(); } getManagers() { this._routeHandOffDefinitionsServiceProxy.getManagersList().subscribe(result => { this.getManagersListDto = result; }); } getFilterRouteManagers() { this._orderIncidentAppService.getManagers().subscribe(result => { this.managers = result; }); } getStops() { this._routeStopsServiceProxy.getRouteStopForDropDown().subscribe(result => { this.getRouteStops = result.items; }); } routeStartActiveToggle(status){ this.routeHandOffDefinition.routeStartInactive = status; } getLocations() { this._locationServiceProxy.getLocationNames(undefined, undefined, undefined, undefined, undefined, undefined).subscribe(result => { this.locations = result; }); } getDrivers() { this._driverServiceProxy.getDriverList().subscribe(result => { this.drivers = result; }); } getRouteTypes() { this._routeHandOffDefinitionsServiceProxy.getAllRouteTypeForLookupTable('', 1, undefined, undefined, this.maxcount).subscribe(result => { this.routeTypes = result.items; }); } searchDriver(day : string){ this.searchDay = day; let filterText = ''; switch (this.searchDay){ case 'monday': filterText = this.mondayDriverFilter; break; case 'tuesday': filterText = this.tuesdayDriverFilter; break; case 'wednesday': filterText = this.wednesdayDriverFilter; break; case 'thursday': filterText = this.thursdayDriverFilter; break; case 'friday': filterText = this.fridayDriverFilter; break; case 'saturday': filterText = this.saturdayDriverFilter; break; case 'sunday': filterText = this.sundayDriverFilter; break; } this.driverList.show(); this.driverList.filterText = filterText; } clearDriver(day){ switch (day){ case 'monday': this.routeHandOffDefinition.mondayDriverId = 0; this.mondayDriverFilter = ''; break; case 'tuesday': this.routeHandOffDefinition.tuesdayDriverId = 0; this.tuesdayDriverFilter = ''; break; case 'wednesday': this.routeHandOffDefinition.wednesdayDriverId = 0; this.wednesdayDriverFilter = ''; break; case 'thursday': this.routeHandOffDefinition.thursdayDriverId = 0; this.thursdayDriverFilter = ''; break; case 'friday': this.routeHandOffDefinition.fridayDriverId = 0; this.fridayDriverFilter = ''; break; case 'saturday': this.routeHandOffDefinition.saturdayDriverId = 0; this.saturdayDriverFilter = ''; break; case 'sunday': this.routeHandOffDefinition.sundayDriverId = 0; this.sundayDriverFilter = ''; break; } } setDriver(item){ var resultId = item.value var name = item.name switch (this.searchDay){ case 'monday': this.routeHandOffDefinition.mondayDriverId = resultId; this.mondayDriverFilter = name; break; case 'tuesday': this.routeHandOffDefinition.tuesdayDriverId = resultId; this.tuesdayDriverFilter = name; break; case 'wednesday': this.routeHandOffDefinition.wednesdayDriverId = resultId; this.wednesdayDriverFilter = name; break; case 'thursday': this.routeHandOffDefinition.thursdayDriverId = resultId; this.thursdayDriverFilter = name; break; case 'friday': this.routeHandOffDefinition.fridayDriverId = resultId; this.fridayDriverFilter = name; break; case 'saturday': this.routeHandOffDefinition.saturdayDriverId = resultId; this.saturdayDriverFilter = name; break; case 'sunday': this.routeHandOffDefinition.sundayDriverId = resultId; this.sundayDriverFilter = name; break; } console.log(this.routeHandOffDefinition.sundayDriverId) } initDriverFields(){ this._driverServiceProxy.getDriverList().subscribe((result) => { this.drivers = result; this.sundayDriverFilter = this.routeHandOffDefinition.sundayDriverId != null && this.routeHandOffDefinition.sundayDriverId != 0? this.drivers.filter(c => c.id == this.routeHandOffDefinition.sundayDriverId)[0].fullName : ''; this.mondayDriverFilter = this.routeHandOffDefinition.mondayDriverId != null && this.routeHandOffDefinition.mondayDriverId != 0? this.drivers.filter(c => c.id == this.routeHandOffDefinition.mondayDriverId)[0].fullName : ''; this.tuesdayDriverFilter = this.routeHandOffDefinition.tuesdayDriverId != null && this.routeHandOffDefinition.tuesdayDriverId != 0? this.drivers.filter(c => c.id == this.routeHandOffDefinition.tuesdayDriverId)[0].fullName : ''; this.wednesdayDriverFilter = this.routeHandOffDefinition.wednesdayDriverId != null && this.routeHandOffDefinition.wednesdayDriverId != 0? this.drivers.filter(c => c.id == this.routeHandOffDefinition.wednesdayDriverId)[0].fullName : ''; this.thursdayDriverFilter = this.routeHandOffDefinition.thursdayDriverId != null && this.routeHandOffDefinition.thursdayDriverId != 0? this.drivers.filter(c => c.id == this.routeHandOffDefinition.thursdayDriverId)[0].fullName : ''; this.fridayDriverFilter = this.routeHandOffDefinition.fridayDriverId != null && this.routeHandOffDefinition.fridayDriverId != 0? this.drivers.filter(c => c.id == this.routeHandOffDefinition.fridayDriverId)[0].fullName : ''; this.saturdayDriverFilter = this.routeHandOffDefinition.saturdayDriverId != null && this.routeHandOffDefinition.saturdayDriverId != 0? this.drivers.filter(c => c.id == this.routeHandOffDefinition.saturdayDriverId)[0].fullName : ''; }); } searchManager(day : string, field : string){ let filterText = ''; this.searchDay = day; this.userField = field; this.managerListModalInit(); if(field == 'manager'){ switch (this.searchDay){ case 'monday': filterText = this.mondayManagerFilter; break; case 'tuesday': filterText = this.tuesdayManagerFilter; break; case 'wednesday': filterText = this.wednesdayManagerFilter; break; case 'thursday': filterText = this.thursdayManagerFilter; break; case 'friday': filterText = this.fridayManagerFilter; break; case 'saturday': filterText = this.saturdayManagerFilter; break; case 'sunday': filterText = this.sundayManagerFilter; break; } } if(field == 'supervisor'){ switch (this.searchDay){ case 'monday': filterText = this.mondaySupervisorFilter; break; case 'tuesday': filterText = this.tuesdaySupervisorFilter; break; case 'wednesday': filterText = this.wednesdaySupervisorFilter; break; case 'thursday': filterText = this.thursdaySupervisorFilter; break; case 'friday': filterText = this.fridaySupervisorFilter; break; case 'saturday': filterText = this.saturdaySupervisorFilter; break; case 'sunday': filterText = this.sundaySupervisorFilter; break; } } this.managerList.show(); this.managerList.filterText = filterText; } setManager(item){ var resultId = item.value var name = item.name if(this.userField == 'manager'){ switch (this.searchDay) { case 'monday': this.routeHandOffDefinition.mondayManagerId = resultId; this.mondayManagerFilter = name; break; case 'tuesday': this.routeHandOffDefinition.tuesdayManagerId = resultId; this.tuesdayManagerFilter = name; break; case 'wednesday': this.routeHandOffDefinition.wednesdayManagerId = resultId; this.wednesdayManagerFilter = name; break; case 'thursday': this.routeHandOffDefinition.thursdayManagerId = resultId; this.thursdayManagerFilter = name; break; case 'friday': this.routeHandOffDefinition.fridayManagerId = resultId; this.fridayManagerFilter = name; break; case 'saturday': this.routeHandOffDefinition.saturdayManagerId = resultId; this.saturdayManagerFilter = name; break; case 'sunday': this.routeHandOffDefinition.sundayManagerId = resultId; this.sundayManagerFilter = name; break; } } else if(this.userField == 'supervisor'){ switch (this.searchDay){ case 'monday': this.routeHandOffDefinition.mondaySupervisorId = resultId; this.mondaySupervisorFilter = name; break; case 'tuesday': this.routeHandOffDefinition.tuesdaySupervisorId = resultId; this.tuesdaySupervisorFilter = name; break; case 'wednesday': this.routeHandOffDefinition.wednesdaySupervisorId = resultId; this.wednesdaySupervisorFilter = name; break; case 'thursday': this.routeHandOffDefinition.thursdaySupervisorId = resultId; this.thursdaySupervisorFilter = name; break; case 'friday': this.routeHandOffDefinition.fridaySupervisorId = resultId; this.fridaySupervisorFilter = name; break; case 'saturday': this.routeHandOffDefinition.saturdaySupervisorId = resultId; this.saturdaySupervisorFilter = name; break; case 'sunday': this.routeHandOffDefinition.sundaySupervisorId = resultId; this.sundaySupervisorFilter = name; break; } } } clearManager(day : string, field : string){ if(field == 'manager'){ switch (day){ case 'monday': this.routeHandOffDefinition.mondayManagerId = null; this.mondayManagerFilter = ''; break; case 'tuesday': this.routeHandOffDefinition.tuesdayManagerId = null; this.tuesdayManagerFilter = ''; break; case 'wednesday': this.routeHandOffDefinition.wednesdayManagerId = null; this.wednesdayManagerFilter = ''; break; case 'thursday': this.routeHandOffDefinition.thursdayManagerId = null; this.thursdayManagerFilter = ''; break; case 'friday': this.routeHandOffDefinition.fridayManagerId = null; this.fridayManagerFilter = ''; break; case 'saturday': this.routeHandOffDefinition.saturdayManagerId = null; this.saturdayManagerFilter = ''; break; case 'sunday': this.routeHandOffDefinition.sundayManagerId = null; this.sundayManagerFilter = ''; break; } } else if(field == 'supervisor'){ switch (day){ case 'monday': this.routeHandOffDefinition.mondaySupervisorId = null; this.mondaySupervisorFilter = ''; break; case 'tuesday': this.routeHandOffDefinition.tuesdaySupervisorId = null; this.tuesdaySupervisorFilter = ''; break; case 'wednesday': this.routeHandOffDefinition.wednesdaySupervisorId = null; this.wednesdaySupervisorFilter = ''; break; case 'thursday': this.routeHandOffDefinition.thursdaySupervisorId = null; this.thursdaySupervisorFilter = ''; break; case 'friday': this.routeHandOffDefinition.fridaySupervisorId = null; this.fridaySupervisorFilter = ''; break; case 'saturday': this.routeHandOffDefinition.saturdaySupervisorId = null; this.saturdaySupervisorFilter = ''; break; case 'sunday': this.routeHandOffDefinition.sundaySupervisorId = null; this.sundaySupervisorFilter = ''; break; } } } initManagerFields(){ this._orderIncidentAppService.getManagers().subscribe(result => { this.managers = result; this.sundayManagerFilter = this.routeHandOffDefinition.sundayManagerId != null && this.routeHandOffDefinition.sundayManagerId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.sundayManagerId)[0].managerFullName : ''; this.mondayManagerFilter = this.routeHandOffDefinition.mondayManagerId != null && this.routeHandOffDefinition.mondayManagerId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.mondayManagerId)[0].managerFullName : ''; this.tuesdayManagerFilter = this.routeHandOffDefinition.tuesdayManagerId != null && this.routeHandOffDefinition.tuesdayManagerId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.tuesdayManagerId)[0].managerFullName : ''; this.wednesdayManagerFilter = this.routeHandOffDefinition.wednesdayManagerId != null && this.routeHandOffDefinition.wednesdayManagerId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.wednesdayManagerId)[0].managerFullName : ''; this.thursdayManagerFilter = this.routeHandOffDefinition.thursdayManagerId != null && this.routeHandOffDefinition.thursdayManagerId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.thursdayManagerId)[0].managerFullName : ''; this.fridayManagerFilter = this.routeHandOffDefinition.fridayManagerId != null && this.routeHandOffDefinition.fridayManagerId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.fridayManagerId)[0].managerFullName : ''; this.saturdayManagerFilter = this.routeHandOffDefinition.saturdayManagerId != null && this.routeHandOffDefinition.saturdayManagerId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.saturdayManagerId)[0].managerFullName : ''; this.sundaySupervisorFilter = this.routeHandOffDefinition.sundaySupervisorId != null && this.routeHandOffDefinition.sundaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.sundaySupervisorId)[0].managerFullName : ''; this.mondaySupervisorFilter = this.routeHandOffDefinition.mondaySupervisorId != null && this.routeHandOffDefinition.mondaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.mondaySupervisorId)[0].managerFullName : ''; this.tuesdaySupervisorFilter = this.routeHandOffDefinition.tuesdaySupervisorId != null && this.routeHandOffDefinition.tuesdaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.tuesdaySupervisorId)[0].managerFullName : ''; this.wednesdaySupervisorFilter = this.routeHandOffDefinition.wednesdaySupervisorId != null && this.routeHandOffDefinition.wednesdaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.wednesdaySupervisorId)[0].managerFullName : ''; this.thursdaySupervisorFilter = this.routeHandOffDefinition.thursdaySupervisorId != null && this.routeHandOffDefinition.thursdaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.thursdaySupervisorId)[0].managerFullName : ''; this.fridaySupervisorFilter = this.routeHandOffDefinition.fridaySupervisorId != null && this.routeHandOffDefinition.fridaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.fridaySupervisorId)[0].managerFullName : ''; this.saturdaySupervisorFilter = this.routeHandOffDefinition.saturdaySupervisorId != null && this.routeHandOffDefinition.saturdaySupervisorId != 0? this.managers.filter(c => c.managerId == this.routeHandOffDefinition.saturdaySupervisorId)[0].managerFullName : ''; }) } updateEmail(id, data): void { this.supervisors[id].isEmail = data; } updateSMS(id, data): void { this.supervisors[id].isSMS = data; } deleteRecipient(id: number): void { this.delete = this.supervisors[id]; this._routeHandOffDefinitionsServiceProxy.deleteSupervisor(this.delete.id) .subscribe(() => { this.notify.success(this.l('SuccessfullyDeleted')); }); this.supervisors.splice(id, 1); } updateUnits(id, data): void { this.supervisors[id].organizationUnitId = data; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); }, 100); } updateUsers(id, data): void { this.supervisors[id].userId = data; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); }, 100); } updateRecipientType(id, data): void { let s = this; this.supervisors[id].code = data; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); $('.organization-unit').on('select2:select', function (e) { s.updateUnits($(e.currentTarget).attr('id'), $(e.currentTarget).val()); }); $('.user').on('select2:select', function (e) { s.updateUsers($(e.currentTarget).attr('id'), $(e.currentTarget).val()); }); }, 100); } addRecipient(): void { let s = this; this.addSupervisors = []; this.addSupervisors.isEmail = false; this.addSupervisors.isSMS = false; this.addSupervisors.isActive = false; this.addSupervisors.organizationUnitId = null; this.addSupervisors.emailAddress = ""; this.addSupervisors.code = ""; this.addSupervisors.userId = null; this.addSupervisors.routeTemplateId = null; this.supervisors.push(this.addSupervisors); //console.log(this.supervisors); //this.supervisors = this.addSupervisors; setTimeout(() => { $('.organization-unit').select2(); $('.user').select2(); }, 10); } }