feature-libs/organization/administration/components/unit/links/users/roles/unit-user-roles-form.service.ts
Properties |
|
Methods |
|
constructor(userService: B2BUserService)
|
||||||
|
Parameters :
|
| Protected build |
build()
|
|
Inherited from
FormService
|
|
Defined in
FormService:24
|
|
Returns :
void
|
| getForm | ||||||
getForm(item?: B2BUser)
|
||||||
|
Inherited from
FormService
|
||||||
|
Defined in
FormService:17
|
||||||
|
Parameters :
Returns :
FormGroup
|
| Protected patchData | ||||||
patchData(item: B2BUser)
|
||||||
|
Inherited from
FormService
|
||||||
|
Defined in
FormService:32
|
||||||
|
Parameters :
Returns :
void
|
| Private toggleFreeze | ||||||
toggleFreeze(item?: T)
|
||||||
|
Inherited from
FormService
|
||||||
|
Defined in
FormService:38
|
||||||
|
Parameters :
Returns :
void
|
| availableRoles |
Type : B2BUserRole[]
|
Default value : this.userService.getAllRoles()
|
| Protected form |
Type : FormGroup
|
|
Inherited from
FormService
|
|
Defined in
FormService:7
|
import { Injectable } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { B2BUser, B2BUserRole } from '@spartacus/core';
import { B2BUserService } from '@spartacus/organization/administration/core';
import { FormService } from '../../../../shared/form/form.service';
@Injectable({
providedIn: 'root',
})
export class UnitUserRolesFormService extends FormService<B2BUser> {
availableRoles: B2BUserRole[] = this.userService.getAllRoles();
constructor(protected userService: B2BUserService) {
super();
}
getForm(item?: B2BUser): FormGroup {
// if form already exist, while switching between users
// it didn't patchData again, so used force rebuild
this.form = null;
return super.getForm(item);
}
protected build() {
const form = new FormGroup({});
this.availableRoles.forEach((role) =>
form.addControl(role, new FormControl())
);
this.form = form;
}
protected patchData(item: B2BUser) {
super.patchData(item);
if (item) {
item.roles?.forEach((role) => {
this.form.get(role).setValue(true);
});
}
}
}