71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
/** Angular Imports */
|
|
import { Component, OnInit } from '@angular/core';
|
|
import { UntypedFormBuilder, UntypedFormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
|
|
import { Router, ActivatedRoute, RouterLink } from '@angular/router';
|
|
|
|
/** Custom Services */
|
|
import { SystemService } from '../../system.service';
|
|
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
|
|
|
/**
|
|
* Add Role Component.
|
|
*/
|
|
@Component({
|
|
selector: 'mifosx-add-role',
|
|
templateUrl: './add-role.component.html',
|
|
styleUrls: ['./add-role.component.scss'],
|
|
imports: [
|
|
...STANDALONE_SHARED_IMPORTS
|
|
]
|
|
})
|
|
export class AddRoleComponent implements OnInit {
|
|
/** Role form. */
|
|
roleForm: UntypedFormGroup;
|
|
|
|
/**
|
|
* @param {FormBuilder} formBuilder Form Builder.
|
|
* @param {SystemService} systemService System Service.
|
|
* @param {ActivatedRoute} route Activated Route.
|
|
* @param {Router} router Router for navigation.
|
|
*/
|
|
constructor(
|
|
private formBuilder: UntypedFormBuilder,
|
|
private systemService: SystemService,
|
|
private route: ActivatedRoute,
|
|
private router: Router
|
|
) {}
|
|
|
|
/**
|
|
* Creates the role form.
|
|
*/
|
|
ngOnInit() {
|
|
this.createRoleForm();
|
|
}
|
|
|
|
/**
|
|
* Creates the create role form.
|
|
*/
|
|
createRoleForm() {
|
|
this.roleForm = this.formBuilder.group({
|
|
name: [
|
|
'',
|
|
Validators.required
|
|
],
|
|
description: [
|
|
'',
|
|
Validators.required
|
|
]
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Submits the role form and creates a role,
|
|
* if successful redirects back to roles and permission.
|
|
*/
|
|
submit() {
|
|
this.systemService.createRole(this.roleForm.value).subscribe((response: any) => {
|
|
this.router.navigate(['../'], { relativeTo: this.route });
|
|
});
|
|
}
|
|
}
|