@@ -0,0 +1,61 @@
|
||||
/** 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';
|
||||
|
||||
/**
|
||||
* Add Role Component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-add-role',
|
||||
templateUrl: './add-role.component.html',
|
||||
styleUrls: ['./add-role.component.scss']
|
||||
})
|
||||
export class AddRoleComponent implements OnInit {
|
||||
|
||||
/** Role form. */
|
||||
roleForm: FormGroup;
|
||||
|
||||
/**
|
||||
* @param {FormBuilder} formBuilder Form Builder.
|
||||
* @param {SystemService} systemService System Service.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {Router} router Router for navigation.
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
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 });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user