|
|
|
@ -3,6 +3,9 @@ import {Businessunit} from "../../../interfaces/businessunit"; |
|
|
|
|
import {ActivatedRoute} from "@angular/router"; |
|
|
|
|
import {BusinessunitService} from "../../../services/businessunit.service"; |
|
|
|
|
import {Location} from "@angular/common"; |
|
|
|
|
import {FormBuilder, FormGroup, Validators} from "@angular/forms"; |
|
|
|
|
import {Agence} from "../../../interfaces/agence"; |
|
|
|
|
import {AgenceService} from "../../../services/agence.service"; |
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
|
selector: 'app-businessunit-edit', |
|
|
|
@ -11,16 +14,34 @@ import {Location} from "@angular/common"; |
|
|
|
|
}) |
|
|
|
|
export class BusinessunitEditComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
businessunit : Businessunit | undefined; |
|
|
|
|
businessunit = {} as Businessunit ; |
|
|
|
|
agences : Agence[] = []; |
|
|
|
|
agence = {} as Agence ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registerForm!: FormGroup; |
|
|
|
|
submitted = false; |
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
private route: ActivatedRoute, |
|
|
|
|
private businessunitService: BusinessunitService, |
|
|
|
|
private location: Location |
|
|
|
|
private agenceService: AgenceService, |
|
|
|
|
private location: Location, |
|
|
|
|
private formBuilder: FormBuilder |
|
|
|
|
) { } |
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
this.getBusinessunit() |
|
|
|
|
this.getBusinessunit(); |
|
|
|
|
this.getAgences(); |
|
|
|
|
this.registerForm = this.formBuilder.group({ |
|
|
|
|
name: ['', Validators.required], |
|
|
|
|
agenceId: ['',Validators.required] |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getAgences():void { |
|
|
|
|
this.agenceService.getAgences() |
|
|
|
|
.subscribe(agences => this.agences = agences); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getBusinessunit(): void { |
|
|
|
@ -47,4 +68,22 @@ export class BusinessunitEditComponent implements OnInit { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onSubmit() { |
|
|
|
|
this.submitted = true; |
|
|
|
|
|
|
|
|
|
if (this.registerForm.invalid) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.businessunit.name = this.registerForm.value.name |
|
|
|
|
this.businessunit.agenceId = this.registerForm.value.agenceId |
|
|
|
|
this.save() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
get f() { return this.registerForm.controls; } |
|
|
|
|
|
|
|
|
|
onReset() { |
|
|
|
|
this.submitted = false; |
|
|
|
|
this.registerForm.reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|