/** Angular Imports */ import { Component , OnInit } from '@angular/core' ; import { FormGroup , FormBuilder , Validators } from '@angular/forms' ; import { ActivatedRoute , Router } from '@angular/router' ; import { DatePipe } from '@angular/common' ; /** Custom Services */ import { OrganizationService } from 'app/organization/organization.service' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Edit Office component.
 */ @ Component ( { selector : 'mifosx-edit-office' , templateUrl : './edit-office.component.html' , styleUrls : [ './edit-office.component.scss' ] } ) export class EditOfficeComponent implements OnInit { /** Selected Data. */ officeData : any ; /** Office form. */ officeForm : FormGroup ; /** Minimum Date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum Date allowed. */ maxDate = new Date ( ) ; param { ProductsService } organizationService param { SettingsService } settingsService param { FormBuilder } formBuilder param { ActivatedRoute } route param { Router } router param { MatDialog } dialog param { DatePipe } datepipe constructor ( private organizationService , private settingsService , private formBuilder , private route , private router , private datepipe ) { this . route . data . subscribe ( ( data ) => { this . officeData = data . officeTemplate ; } ) ; } ngOnInit ( ) { this . createOfficeForm ( ) ; } /**
     * Create Edit Office Form.
     */ createOfficeForm ( ) { this . officeForm = this . formBuilder . group ( { 'name' : [ this . officeData . name , Validators . required ] , 'openingDate' : [ this . officeData . openingDate && new Date ( this . officeData . openingDate ) , Validators . required ] , 'externalId' : [ this . officeData . externalId ] , } ) ; if ( this . officeData . allowedParents . length ) { this . officeForm . addControl ( 'parentId' , this . formBuilder . control ( this . officeData . parentId , Validators . required ) ) ; } } /**
     * Submits the edit office form.
     */ submit ( ) { const openedOn = this . officeForm . value . openingDate ; const dateFormat = this . settingsService . dateFormat ; this . officeForm . patchValue ( { openingDate : this . datepipe . transform ( openedOn , dateFormat ) } ) ; const office = this . officeForm . value ; office . locale = this . settingsService . language . code ; office . dateFormat = dateFormat ; this . organizationService . updateOffice ( this . officeData . id , office ) . subscribe ( ( response ) => { this . router . navigate ( [ '../' ] , { relativeTo : this . route } ) ; } ) ; } }