/** Angular Imports */ import { Component , OnInit } from '@angular/core' ; import { FormBuilder , FormGroup , Validators } from '@angular/forms' ; import { Router , ActivatedRoute } from '@angular/router' ; /** Custom Services */ import { SystemService } from '../../system.service' ; /**
 * Create Account Number Preference Component.
 */ @ Component ( { selector : 'mifosx-create-account-number-preference' , templateUrl : './create-account-number-preference.component.html' , styleUrls : [ './create-account-number-preference.component.scss' ] } ) export class CreateAccountNumberPreferenceComponent implements OnInit { /** Account Number Preferences Form */ accountNumberPreferenceForm : FormGroup ; /** Account Number Preferences Template Data */ accountNumberPreferencesTemplateData : any ; /** Prefix Type Data */ prefixTypeData : any [ ] ; param { FormBuilder } formBuilder param { SystemService } systemService param { ActivatedRoute } route param { Router } router constructor ( private formBuilder , private systemService , private route , private router ) { this . route . data . subscribe ( ( data ) => { this . accountNumberPreferencesTemplateData = data . accountNumberPreferencesTemplate ; } ) ; } /**
     * Creates the account number preference form.
     * Subscribe on Form Controls to change Prefix Type data.
     */ ngOnInit ( ) { this . createAccountNumberPreferenceForm ( ) ; this . getPrefixTypeValue ( ) ; } /**
     * Subscribes on Form Controls to change Prefix Type data.
     */ getPrefixTypeValue ( ) { this . accountNumberPreferenceForm . get ( 'accountType' ) . valueChanges . subscribe ( accountId => { this . prefixTypeData = this . accountNumberPreferencesTemplateData . prefixTypeOptions [ `accountType.${ this . accountNumberPreferencesTemplateData . accountTypeOptions . find ( ( accountType ) => accountType . id === accountId ) . value . toLowerCase ( ) }` ] ; } ) ; } /**
     * Creates the account number preference form.
     */ createAccountNumberPreferenceForm ( ) { this . accountNumberPreferenceForm = this . formBuilder . group ( { 'accountType' : [ '' , Validators . required ] , 'prefixType' : [ '' ] } ) ; } /**
     * Submits the account number preference form and creates a account number preference,
     * if successful redirects to view created account number preference.
     */ submit ( ) { const accountNumberPreference = this . accountNumberPreferenceForm . value ; if ( accountNumberPreference . prefixType === '' ) { accountNumberPreference . prefixType = undefined ; } this . systemService . createAccountNumberPreference ( accountNumberPreference ) . subscribe ( ( response ) => { this . router . navigate ( [ '../' , response . resourceId ] , { relativeTo : this . route } ) ; } ) ; } }