//Angular libraries import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core'; import { CookieService } from 'ngx-cookie-service'; //Services import { NotesService } from '../../../shared/service/notes.service'; import { AutomationService } from '../../../shared/service/automation.service'; //Models import { INotesTypes } from '../../../shared/core/INotesTypes'; import { INotes } from '../../../shared/core/automation/INotes'; import { IStaff } from '../../../shared/core/automation/IStaff'; import { IToDetails } from '../../../shared/core/automation/IToDetails'; import { INotification } from '../../../shared/core/automation/INotification'; import { IEmail } from '../../../shared/core/automation/IEmail'; import { IDelayTime } from '../../../shared/core/automation/IDelayTime'; import { ICreateTask } from '../../../shared/core/automation/ICreateTask'; import { MessageService, SelectItem } from 'primeng/api'; import { IOptions } from '../../../shared/core/IOptions'; import { DashboardService } from '../../../shared/service/dashboard.service'; @Component({ selector: 'app-steps-popup', templateUrl: './steps-popup.component.html', styleUrls: ['./steps-popup.component.css'] }) export class StepsPopupComponent implements OnInit { //Inputs @Input() Heading: string = ""; @Input() companyId: number; //Outputs @Output() bindCloseStep: EventEmitter = new EventEmitter(); //Global variables NoteCreatedPlaces: any = []; noteCreatedUnder: string[] = []; INotesTypes: INotesTypes[]; associatedStaffs: IStaff[]; internalNotificationToDetails: IToDetails[]; internalNotificationSubjectDetails: IToDetails[]; emailNotificationToDetails: IToDetails[]; emailNotificationFromDetails: IToDetails[]; emailNotificationSubjectDetails: IToDetails[]; stepDelayTime: IDelayTime = {}; createtask: ICreateTask = {} createNote: INotes = {} sendEmailNotification: IEmail = {} sendInternalNotification: INotification = {} selectedEmailNotificationFromDetails: string = ""; selectedEmailNotificationFromEmailDetails: string = ""; selectedEmailNotificationToDetails: string[] = []; selectedEmailNotificationSubjectDetails: string = ""; selectedInternalNotificationToDetails: string[] = []; selectedInternalNotificationSubjectDetails: string = ""; noteContentTxt: string = ""; notificationContentTxt: string = ""; selectedStaff: IStaff[] = []; selectedStaffId: number[] = []; selectedLog: any; bussinessDates: number; notesTypeId: number = 0; showCreateNote: boolean = false; showInternalNotification: boolean = false; showEmailNotification: boolean = false; showSetDelayDuration: boolean = false; showCreateTask: boolean = false; TaskCreate: boolean = false; isToDetails: boolean = false; isSubjectDetails: boolean = false; isIncludeWordDocument: boolean = false; isIncludePDFDocument: boolean = false; stepId: number = 0; lognote: SelectItem[]; selectedLogNote: any = { id: 1, name: 'Email', code: 'Email' }; followUpdayList: SelectItem[]; followUpDay: any = { id: 1, name: '1 business day', code: '1BD' }; customFollowUpDay: number = 1; /** For contact options */ contactOptions: IOptions; //logged person id LoggedId: number = 1; contactList: any[] = []; // noteCreatedUnderIds:any = [{contact:{ContactDetails:{FirstName:''}}}]; noteCreatedUnderIds: any = []; internalNotiTo: any = []; internalNotiToIds: any = []; show: boolean = false; showIcon:boolean=true; isCustomBDay:boolean=false; //Constructor of the component constructor(private notesService: NotesService, private automationService: AutomationService, private cookieService: CookieService, private messageService: MessageService, private dashboardService: DashboardService) { } //Component Initial method ngOnInit() { this.GetNoteLogs(); this.lognote = [ // {label:'Select City', value:null}, { label: 'Email', value: { id: 1, name: 'Email', code: 'Email' } }, { label: 'Call', value: { id: 2, name: 'Call', code: 'Call' } }, { label: 'Meeting', value: { id: 3, name: 'Meeting', code: 'Meeting' } } ]; this.followUpdayList = [ { label: '1 business day', value: { id: 1, name: '1 business day', code: '1BD' } }, { label: '2 business day', value: { id: 2, name: '2 business day', code: '2BD' } }, { label: '3 business day', value: { id: 3, name: '3 business day', code: '3BD' } }, { label: '4 business day', value: { id: 4, name: '4 business day', code: '4BD' } }, { label: '5 business day', value: { id: 5, name: '5 business day', code: '5BD' } }, { label: 'Custom', value: { id: 0, name: 'Custom', code: 'CUS' } }, ]; // get contact list this.GetContacts(); this.createtask.contactsUnderTask = []; this.createtask.contactsUnderTask = []; } ifCustomSelected(event){ if(event.id == 0){ this.isCustomBDay = true; }else{ this.isCustomBDay = false; this.customFollowUpDay = event.id; } } cancelStep() { this.bindCloseStep.emit(false); } SaveStep() { if (this.showCreateNote) { this.SaveNotes(); } else if (this.showInternalNotification) { this.SaveInternalNotification(); } else if (this.showSetDelayDuration) { this.SaveSetDelayTimeTemp(); } else if (this.showCreateTask) { this.SaveCreateTaskTemp(); } else if (this.showEmailNotification) { this.SaveEmailNotification(); } } //#region Send Email Notification getEmailToDetails() { this.isToDetails = true; this.isSubjectDetails = false; this.GetEmailNotificationStaffs(); this.GetEmailNotificationRoles(); } getEmailSubjectDetails() { this.isSubjectDetails = true; this.isToDetails = false; this.GetEmailNotificationStaffs(); this.GetEmailNotificationRoles(); } GetEmailNotificationStaffs() { this.automationService.getStaffList('0').subscribe( staffs => { var count = 1; if (this.isToDetails) { this.emailNotificationToDetails = []; staffs.forEach(x => { this.emailNotificationToDetails.push({ Id: count, Name: x.FirstName + ' ' + x.LastName, Type: 'Staff', Email: '' }) count++; }); } else if (this.isSubjectDetails) { this.emailNotificationSubjectDetails = []; staffs.forEach(x => { this.emailNotificationSubjectDetails.push({ Id: count, Name: x.FirstName + ' ' + x.LastName, Type: 'Staff', Email: '' }) count++; }); } } ) } GetEmailNotificationRoles() { this.automationService.getRoleList(0).subscribe( roles => { if (this.isToDetails) { var count = this.internalNotificationToDetails != undefined ? this.internalNotificationToDetails.length + 1 : 0; roles.forEach(x => { this.internalNotificationToDetails.push({ Id: count, Name: x.RoleName, Type: 'Role', Email: '' }) count++; }); } else if (this.isSubjectDetails) { var count = this.internalNotificationSubjectDetails != undefined ? this.internalNotificationSubjectDetails.length + 1 : 0; roles.forEach(x => { this.internalNotificationSubjectDetails.push({ Id: count, Name: x.RoleName, Type: 'Role', Email: '' }) count++; }); } } ) } selectEmailNotificationToDetail() { // this.selectedEmailNotificationToDetails += " "; // this.selectedEmailNotificationToDetails += emailNotificationToDetail.Name; } selectEmailNotificationSubjectDetail(emailNotificationSubjectDetail: IToDetails) { this.selectedEmailNotificationSubjectDetails += " "; this.selectedEmailNotificationSubjectDetails += emailNotificationSubjectDetail.Name; } selectEmailNotificationFromDetail(emailNotificationFromDetail: IToDetails) { this.selectedEmailNotificationFromDetails += " "; this.selectedEmailNotificationFromDetails += emailNotificationFromDetail.Name; } selectEmailNotificationFromEmailDetail() { // this.selectedEmailNotificationFromEmailDetails += " "; // this.selectedEmailNotificationFromEmailDetails += emailNotificationFromEmailDetail.Email; } checkIsIncludeWordDocument(event) { this.isIncludeWordDocument = event; } checkIsIncludePDFDocument(event) { this.isIncludePDFDocument = event; } SaveEmailNotification() { const notificationObject = {} as IEmail; // Assign values notificationObject.Id = 0; notificationObject.FromDetails = this.selectedEmailNotificationFromDetails; notificationObject.FromEmailDetails = this.selectedEmailNotificationFromEmailDetails; notificationObject.ToDetails = this.selectedEmailNotificationToDetails.join(","); notificationObject.SubjectDetails = this.selectedEmailNotificationSubjectDetails; notificationObject.IsIncludePDFDocument = this.isIncludePDFDocument; notificationObject.IsIncludeWordDocument = this.isIncludeWordDocument; notificationObject.Content = this.notificationContentTxt; notificationObject.LoginStaffId = +this.cookieService.get('LoggedUserId'); this.sendEmailNotification = notificationObject; this.sendEmailNotification.StepId = this.stepId; if (this.selectedEmailNotificationFromDetails == "") { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Textbox Field Empty', detail: 'Please Enter From Details to Continue' }); } else if (this.selectedEmailNotificationFromEmailDetails == "") { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Textbox Field Empty', detail: 'Please Enter From Email to Continue' }); } else if (this.selectedEmailNotificationToDetails.length < 1) { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Textbox Field Empty', detail: 'Please select at least one participant to send email' }); } else if (this.selectedEmailNotificationSubjectDetails == "") { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Textbox Field Empty', detail: 'Please Enter a Subject to Continue' }); } else if (this.notificationContentTxt == "") { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Content Field Empty', detail: 'Please Compose a message to Continue' }); } else { this.bindCloseStep.emit(true); } } //#endregion //#region Send internal notification getToDetails() { this.isToDetails = true; this.isSubjectDetails = false; this.GetInternalNotificationRoles(); this.GetInternalNotificationStaffs(); } getSubjectDetails() { this.isSubjectDetails = true; this.isToDetails = false; this.GetInternalNotificationRoles(); this.GetInternalNotificationStaffs(); } selectinternalNotificationToDetail() { // this.selectedInternalNotificationToDetails += " "; // this.selectedInternalNotificationToDetails += internalNotificationToDetail.Name; } selectInternalNotificationSubjectDetail(internalNotificationSubjectDetail: IToDetails) { this.selectedInternalNotificationSubjectDetails += " "; this.selectedInternalNotificationSubjectDetails += internalNotificationSubjectDetail.Name; } GetInternalNotificationStaffs() { this.automationService.getStaffList('0').subscribe( staffs => { var count = 1; if (this.isToDetails) { this.internalNotificationToDetails = []; staffs.forEach(x => { this.internalNotificationToDetails.push({ Id: count, Name: x.FirstName + ' ' + x.LastName, Type: 'Staff', Email: '' }) count++; }); } else if (this.isSubjectDetails) { this.internalNotificationSubjectDetails = []; staffs.forEach(x => { this.internalNotificationSubjectDetails.push({ Id: count, Name: x.FirstName + ' ' + x.LastName, Type: 'Staff', Email: '' }) count++; }); } } ) } GetInternalNotificationRoles() { this.automationService.getRoleList(0).subscribe( roles => { if (this.isToDetails) { var count = this.internalNotificationToDetails != undefined ? this.internalNotificationToDetails.length + 1 : 0; roles.forEach(x => { this.internalNotificationToDetails.push({ Id: count, Name: x.RoleName, Type: 'Role', Email: '' }) count++; }); } else if (this.isSubjectDetails) { var count = this.internalNotificationSubjectDetails != undefined ? this.internalNotificationSubjectDetails.length + 1 : 0; roles.forEach(x => { this.internalNotificationSubjectDetails.push({ Id: count, Name: x.RoleName, Type: 'Role', Email: '' }) count++; }); } } ) } SaveInternalNotification() { const notificationObject = {} as INotification; // Assign values notificationObject.NotiicationId = 0; this.internalNotiToIds = []; this.internalNotiTo.forEach(element => { this.internalNotiToIds.push(element.ContactDetails.ContactDetailsId); }); notificationObject.NotiicationToDetails = this.internalNotiToIds.join(","); notificationObject.SubjectDetails = this.selectedInternalNotificationSubjectDetails; notificationObject.NotificationContent = this.notificationContentTxt; notificationObject.LoginStaffId = +this.cookieService.get('LoggedUserId'); this.sendInternalNotification = notificationObject; this.sendInternalNotification.StepId = this.stepId; if (this.internalNotiToIds.length < 1) { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Field Empty', detail: 'Please select at least one participant to send email' }); } else if (this.selectedInternalNotificationSubjectDetails == "") { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Text Field Empty', detail: 'Please Enter a Subject to Continue' }); } else if (this.notificationContentTxt == "") { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Content Field Empty', detail: 'Please Compose a message to Continue' }); } else this.bindCloseStep.emit(true); } //#endregion SaveSetDelayTimeTemp() { if (this.stepDelayTime.DelayDay == null || this.stepDelayTime.DelayDay == 0) { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Textbox Field Empty', detail: 'Please Enter a Delay Duration to Continue' }); } else { this.stepDelayTime.StepId = this.stepId; this.bindCloseStep.emit(true); } } SaveCreateTaskTemp() { if (this.createtask.contactsUnderTask == null || this.createtask.contactsUnderTask.length < 1) { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Textbox Field Empty', detail: 'Please Enter a Task Under Name to Continue' }); } else if (this.createtask.DueDay == null || this.createtask.DueDay == 0) { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Textbox Field Empty', detail: 'Please Enter a Due Day to Continue' }); } else if (this.createtask.Reminder == null || this.createtask.Reminder == 0) { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Textbox Field Empty', detail: 'Please Enter a Reminder to Continue' }); } else if (this.createtask.TaskContent == null || this.createtask.TaskContent == "") { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Content Field Empty', detail: 'Please Enter the Content to Continue' }); } else { this.createtask.StepId = this.stepId; this.createtask.contactsUnderTaskIds = []; this.createtask.contactsUnderTask.forEach(element => { this.createtask.contactsUnderTaskIds.push(element.ContactDetails.ContactDetailsId); }); this.createtask.TaskUnder = this.createtask.contactsUnderTaskIds.join(","); this.bindCloseStep.emit(true); } } //#region Create Note GetNoteLogs() { this.notesService.GetAllNotesTypes().subscribe( result => { if (result != null) { this.INotesTypes = result; } else { } } ); } GetAssosiateStaffs() { this.automationService.getStaffList('0').subscribe( staffs => { this.associatedStaffs = staffs; } ) } selectAssociatedStaff(staff: IStaff) { this.selectedStaff.push(staff); this.selectedStaffId.push(staff.Id); } checkValue(event) { this.TaskCreate = event; if (this.TaskCreate) { this.GetAssosiateStaffs(); } } GetContacts() { /** preparing parameters and options to retrieve contact list, this collection is the one accepts as the parameter in API */ this.contactOptions = { Params: [ { 'key': 'id', 'value': this.LoggedId }, { 'key': 'contactopt', 'value': "ME" } ], FilterValue: [{ 'key': '', 'value': null }], SearchValue: "", RecordCount: 50, CurrentPage: 1 } this.dashboardService.getContactList(this.contactOptions, +this.cookieService.get('CompanyId')).subscribe(res => { this.contactList = []; this.contactList = res; }); } showSelectedStaff(Ids: string) { var staffIds = Ids.split(','); if (staffIds.length > 0) { this.automationService.getStaffList('0').subscribe( staffs => { this.associatedStaffs = staffs; staffIds.forEach(staffId => { this.selectAssociatedStaff(this.associatedStaffs.find(x => x.Id == +staffId)) }) } ) } } onChangeNoteType() { } // Business Days onChangeBusinessDays(event) { this.bussinessDates = event.target.value; } // Save notes SaveNotes() { const notesObject = {} as INotes; // Assign values notesObject.Id = 0; notesObject.NotesTypesId = this.selectedLogNote.id; notesObject.Description = this.noteContentTxt; notesObject.CreatedDate = new Date(); notesObject.LoginStaffId = +this.cookieService.get('LoggedUserId'); this.noteCreatedUnder = []; this.noteCreatedUnderIds.forEach(element => { this.noteCreatedUnder.push(element.ContactDetails.ContactDetailsId); }); notesObject.noteCreateUnder = this.noteCreatedUnder.join(","); notesObject.FollowUpDay = this.customFollowUpDay; notesObject.IsFollowUp = this.TaskCreate; notesObject.AssociateCount = this.selectedStaffId.join(","); this.bussinessDates = this.bussinessDates == undefined ? 0 : this.bussinessDates; this.createNote = notesObject; this.createNote.StepId = this.stepId; if (this.noteCreatedUnder.length < 1) { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Textbox Field Empty', detail: 'Please select at least participant for \'Note created under\'' }); } else if (this.noteContentTxt == "") { this.messageService.add({ key: 'toastKey', severity: 'warn', summary: 'Content Field Empty', detail: 'Please Compose a message to Continue' }); } else this.bindCloseStep.emit(true); } //#endregion ResetAllFields(){ this.NoteCreatedPlaces = []; this.noteCreatedUnder = []; this.INotesTypes = []; this.associatedStaffs = []; this.internalNotificationToDetails = []; this.internalNotificationSubjectDetails = []; this.emailNotificationToDetails = []; this.emailNotificationFromDetails = []; this.emailNotificationSubjectDetails = []; this.stepDelayTime = {}; this.createtask = {} this.createNote = {} this.sendEmailNotification = {} this.sendInternalNotification = {} this.selectedEmailNotificationFromDetails = ""; this.selectedEmailNotificationFromEmailDetails = ""; this.selectedEmailNotificationToDetails = []; this.selectedEmailNotificationSubjectDetails = ""; this.selectedInternalNotificationToDetails = []; this.selectedInternalNotificationSubjectDetails = ""; this.noteContentTxt = ""; this.notificationContentTxt = ""; this.selectedStaff = []; this.selectedStaffId = []; this.selectedLog = undefined; this.bussinessDates = undefined; this.notesTypeId = 0; this.showCreateNote = false; this.showInternalNotification = false; this.showEmailNotification = false; this.showSetDelayDuration = false; this.showCreateTask = false; this.TaskCreate = false; this.isToDetails = false; this.isSubjectDetails = false; this.isIncludeWordDocument = false; this.isIncludePDFDocument = false; this.stepId = 0; this.lognote = []; this.selectedLogNote = { id: 1, name: 'Email', code: 'Email' }; this.followUpdayList = []; this.followUpDay = { id: 1, name: '1 business day', code: '1BD' }; this.customFollowUpDay = this.followUpDay.id; /** For contact options */ this.contactOptions = {}; //logged person id this.LoggedId = 1; this.contactList = []; // noteCreatedUnderIds:any = [{contact:{ContactDetails:{FirstName:''}}}]; this.noteCreatedUnderIds = []; this.internalNotiTo = []; this.internalNotiToIds = []; this.ngOnInit(); } //#region RTE Configs //---------------------------------------------------- RTE Configs ----------------------------------------------------// editor; txtArea = document.createElement('textarea'); myEditor = document.querySelector('#editor'); onEditorBlured() { } onEditorFocused(quill) { this.editor = quill; } onEditorCreated(quill) { this.editor = quill; this.txtArea.style.cssText = "width: 100%;margin: 0px;background: rgb(29, 29, 29);box-sizing: border-box;color: rgb(204, 204, 204);font-size: 15px;outline: none;padding: 20px;line-height: 24px;font-family: Consolas, Menlo, Monaco, "Courier New", monospace;position: absolute;top: 0;bottom: 0;border: none;display:none"; } onContentChanged() { } selectContactForNote(contact: any) { if (!this.noteCreatedUnderIds.find(x => x == contact)) { this.noteCreatedUnderIds.push(contact); // this.noteCreatedUnderIds.push(contact.ContactDetails.ContactDetailsId); } } showSelectedContactForNote(Ids: string) { var contactIds = Ids.split(','); contactIds.forEach(contactId => { var contact = this.contactList.find(x => x.ContactDetails.ContactDetailsId.toString() == contactId) if (contact != undefined && contact != null) { this.noteCreatedUnderIds.push(contact); this.noteCreatedUnder.push(contactId); } }) } selectContactForTask(contact: any) { if (!this.createtask.contactsUnderTask.find(x => x == contact)) { this.createtask.contactsUnderTask.push(contact); // this.noteCreatedUnderIds.push(contact.ContactDetails.ContactDetailsId); } } showSelectedContactForTask(Ids: string) { var contactIds = Ids.split(','); contactIds.forEach(contactId => { var contact = this.contactList.find(x => x.ContactDetails.ContactDetailsId.toString() == contactId) if (contact != undefined && contact != null) { this.createtask.contactsUnderTask.push(contact); this.createtask.contactsUnderTaskIds.push(contactId); } }) } selectContactForInternatNotify(contact: any) { if (!this.internalNotiTo.find(x => x == contact)) { this.internalNotiTo.push(contact); } } showSelectedContactForInternalNotify(Ids: string) { var contactIds = Ids.split(','); contactIds.forEach(contactId => { var contact = this.contactList.find(x => x.ContactDetails.ContactDetailsId.toString() == contactId) if (contact != undefined && contact != null) { this.internalNotiTo.push(contact); this.internalNotiToIds.push(contactId); } }) } //#endregion displayOptions() { this.show = (this.show == true) ? false : true; this.showIcon = (this.showIcon == false) ? true : false; } }