/** Angular Imports */ import { Component , OnInit , AfterViewInit } from '@angular/core' ; import { FormGroup , FormBuilder , FormControl , Validators } from '@angular/forms' ; import { Router , ActivatedRoute } from '@angular/router' ; /** Custom Services */ import { GroupsService } from 'app/groups/groups.service' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Group Transfer Clients component.
 */ @ Component ( { selector : 'mifosx-group-transfer-clients' , templateUrl : './group-transfer-clients.component.html' , styleUrls : [ './group-transfer-clients.component.scss' ] } ) export class GroupTransferClientsComponent implements OnInit , AfterViewInit { /** Transfer Clients form. */ transferClientsForm : FormGroup ; /** Group Data */ groupData : any ; /** Group data. */ groupsData : any = [ ] ; /** Staff data. */ staffData : any ; /** Client Members. */ clientMembers : any [ ] = [ ] ; param { FormBuilder } formBuilder param { ActivatedRoute } route param { Router } router param { GroupsService } groupsService param { SettingsService } settingsService constructor ( private formBuilder , private route , private router , private groupsService , private settingsService ) { this . route . data . subscribe ( ( data ) => { this . groupData = data . groupActionData ; this . clientMembers = this . groupData . clientMembers ; } ) ; } ngOnInit ( ) { this . createTransferClientsForm ( ) ; } /**
     * Subscribes to Groups search filter:
     */ ngAfterViewInit ( ) { this . transferClientsForm . get ( 'destinationGroupId' ) . valueChanges . subscribe ( ( value ) => { if ( value . length >= 2 ) { this . groupsService . getFilteredGroups ( 'name' , 'ASC' , value , this . groupData . officeId ) . subscribe ( ( data ) => { this . groupsData = data ; } ) ; } } ) ; } /**
     * Creates the transfer clients form.
     */ createTransferClientsForm ( ) { this . transferClientsForm = this . formBuilder . group ( { 'clients' : [ '' , Validators . required ] , 'inheritDestinationGroupLoanOfficer' : [ false ] , 'destinationGroupId' : [ '' , Validators . required ] } ) ; } param { any } group returns { string } displayGroup ( group ) { return group ? group . name : undefined ; } /**
     * Submits the group form and transfers the clients,
     * if successful redirects to group.
     */ submit ( ) { const locale = this . settingsService . language . code ; const data = { ... this . transferClientsForm . value , destinationGroupId : this . transferClientsForm . get ( 'destinationGroupId' ) . value . id , locale } ; this . groupsService . executeGroupCommand ( this . groupData . id , 'transferClients' , data ) . subscribe ( ( ) => { this . router . navigate ( [ '../../' ] , { relativeTo : this . route } ) ; } ) ; } }