]>
Commit | Line | Data |
---|---|---|
f91f0fd5 TL |
1 | import { AfterViewInit, Directive, ElementRef, Optional } from '@angular/core'; |
2 | ||
3 | import { Permissions } from '../models/permissions'; | |
4 | import { AuthStorageService } from '../services/auth-storage.service'; | |
5 | import { FormScopeDirective } from './form-scope.directive'; | |
6 | ||
7 | @Directive({ | |
8 | selector: | |
f67539c2 | 9 | 'input:not([cdNoFormInputDisable]), select:not([cdNoFormInputDisable]), button:not([cdNoFormInputDisable]), [cdFormInputDisable]' |
f91f0fd5 TL |
10 | }) |
11 | export class FormInputDisableDirective implements AfterViewInit { | |
12 | permissions: Permissions; | |
f91f0fd5 TL |
13 | |
14 | constructor( | |
15 | @Optional() private formScope: FormScopeDirective, | |
16 | private authStorageService: AuthStorageService, | |
17 | private elementRef: ElementRef | |
18 | ) {} | |
19 | ||
20 | ngAfterViewInit() { | |
21 | this.permissions = this.authStorageService.getPermissions(); | |
f67539c2 TL |
22 | const service_name = this.formScope?.cdFormScope; |
23 | if (service_name && !this.permissions?.[service_name]?.update) { | |
f91f0fd5 TL |
24 | this.elementRef.nativeElement.disabled = true; |
25 | } | |
26 | } | |
27 | } |