/** Angular Imports */ import { Component , OnInit , Inject } from '@angular/core' ; import { MatDialogRef , MAT_DIALOG_DATA } from '@angular/material/dialog' ; import { FormGroup , FormBuilder , Validators } from '@angular/forms' ; import { DatePipe } from '@angular/common' ; /** Custom Services */ import { SettingsService } from 'app/settings/settings.service' ; /**
 * Client Family Members Dialog
 */ @ Component ( { selector : 'mifosx-client-family-member-dialog' , templateUrl : './client-family-member-dialog.component.html' , styleUrls : [ './client-family-member-dialog.component.scss' ] } ) export class ClientFamilyMemberDialogComponent implements OnInit { /** Minimum Due Date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum Due Date allowed. */ maxDate = new Date ( ) ; /** Add/Edit family member form. */ familyMemberForm : FormGroup ; param { MatDialogRef } dialogRef param { FormBuilder } formBuilder param { DatePipe } datePipe param { any } data param { SettingsService } settingsService constructor ( public dialogRef , private formBuilder , private datePipe , @ Inject ( MAT_DIALOG_DATA ) public data , private settingsService ) { } ngOnInit ( ) { this . createFamilyMemberForm ( ) ; if ( this . data . context === 'Edit' ) { this . familyMemberForm . patchValue ( { 'firstName' : this . data . member . firstName , 'middleName' : this . data . member . middleName , 'lastName' : this . data . member . lastName , 'qualification' : this . data . member . qualification , 'age' : this . data . member . age , 'isDependent' : this . data . member . isDependent , 'relationshipId' : this . data . member . relationshipId , 'genderId' : this . data . member . genderId , 'professionId' : this . data . member . professionId , 'maritalStatusId' : this . data . member . maritalStatusId , 'dateOfBirth' : this . data . member . dateOfBirth && new Date ( this . data . member . dateOfBirth ) } ) ; } } /**
     * Creates Family Member Form
     */ createFamilyMemberForm ( ) { this . familyMemberForm = this . formBuilder . group ( { 'firstName' : [ '' , Validators . required ] , 'middleName' : [ '' ] , 'lastName' : [ '' , Validators . required ] , 'qualification' : [ '' ] , 'age' : [ '' ] , 'isDependent' : [ '' ] , 'relationshipId' : [ '' , Validators . required ] , 'genderId' : [ '' ] , 'professionId' : [ '' ] , 'maritalStatusId' : [ '' ] , 'dateOfBirth' : [ '' ] } ) ; } /**
     * Returns Formatted Family Member
     */ get familyMember ( ) { const locale = this . settingsService . language . code ; const dateFormat = this . settingsService . dateFormat ; const familyMember = { ... this . familyMemberForm . value , dateFormat , locale } ; for ( const key in familyMember ) { if ( familyMember [ key ] === '' || familyMember [ key ] === undefined ) { delete familyMember [ key ] ; } } if ( familyMember . dateOfBirth ) { familyMember . dateOfBirth = this . datePipe . transform ( familyMember . dateOfBirth , dateFormat ) ; } return familyMember ; } }