import { Component, OnInit } from '@angular/core'; import { DialogService } from 'primeng/api'; import { JobplanServicesService } from '../../../shared/services/jobplan-services.service'; import { IAccessRights } from '../../../shared/core/IAccessRights'; @Component({ selector: 'app-add-staff', templateUrl: './add-staff.component.html', styleUrls: ['./add-staff.component.css'] }) export class AddStaffComponent implements OnInit { FirstName: any; LastName: any; clientPhone: any; JobTitle: any; Email: any; disableSaveButton: boolean; AccessRights: any = []; Phone: any; selectedAccessRights: IAccessRights[]; // saving icon showLoading: boolean = false; constructor(private jobplanServices: JobplanServicesService, public dialogService: DialogService) { } ngOnInit() { this.getAccessRights(); } validateFields() { if (this.FirstName !== '' && this.LastName !== '' && this.clientPhone !== '' && this.JobTitle !== '' && this.Email !== '') { this.disableSaveButton = false; } else { this.disableSaveButton = true; } } getAccessRights() { this.jobplanServices.getAccessRights() .subscribe(res => { this.AccessRights = res; console.log('access rights', res); }, error => { console.log('Error', error); } ); } saveStaff() { const newStaff = { FirstName: this.FirstName, LastName: this.LastName, JobTitle: this.JobTitle, Phone: this.Phone, Email: this.Email, AccessRights: this.selectedAccessRights }; this.showLoading = true; this.jobplanServices.addNewStaff(newStaff) .subscribe(res => { // console.log('access rights', res); this.showLoading = false; this.dialogService.dialogComponentRef.instance.close(); this.dialogService.dialogComponentRef.destroy(); }, error => { console.log('Error', error); } ); } // Close the current popup cancelOrganisation() { this.dialogService.dialogComponentRef.instance.close(); this.dialogService.dialogComponentRef.destroy(); } // Allow only numbers allow_numbers_char(event) { let k; k = event.charCode; return (k >= 48 && k < 58); } // Charactor validation omit_special_char(event) { let k; k = event.charCode; // k = event.keyCode; (Both can be used) // return((k > 64 && k < 91) || (k > 96 && k < 123) || k === 8 || k === 32 || (k >= 48 && k <= 57)); // Special Charactor validation return (!(k >= 27 && k <= 31) && !(k >= 33 && k <= 47) && !(k >= 48 && k <= 64) && !(k >= 91 && k <= 96) && !(k >= 123 && k <= 127)); } }