mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Fix dyanmic disabling checkboxes in permissions select
This commit is contained in:
		| @@ -18,7 +18,7 @@ | ||||
|       </div> | ||||
|  | ||||
|       <div *ngFor="let action of PermissionAction | keyvalue" class="col form-check form-check-inline" [ngbPopover]="inheritedWarning" [disablePopover]="!isInherited(type.key, action.key)" placement="left" triggers="mouseenter:mouseleave"> | ||||
|         <input type="checkbox" class="form-check-input" id="{{type.key}}_{{action.key}}" formControlName="{{action.key}}" [attr.disabled]="isDisabled(type.key, action.key)"> | ||||
|         <input type="checkbox" class="form-check-input" id="{{type.key}}_{{action.key}}" formControlName="{{action.key}}"> | ||||
|         <label class="form-check-label visually-hidden" for="{{type.key}}_{{action.key}}" i18n>{{action.key}}</label> | ||||
|       </div> | ||||
|     </li> | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| import { Component, forwardRef, Input, OnInit } from '@angular/core' | ||||
| import { | ||||
|   AbstractControl, | ||||
|   ControlValueAccessor, | ||||
|   FormControl, | ||||
|   FormGroup, | ||||
| @@ -54,6 +55,8 @@ export class PermissionsSelectComponent | ||||
|       this._inheritedPermissions = newInheritedPermissions | ||||
|       this.writeValue(this.permissions) // updates visual checks etc. | ||||
|     } | ||||
|  | ||||
|     this.updateDisabledStates() | ||||
|   } | ||||
|  | ||||
|   inheritedWarning: string = $localize`Inerhited from group` | ||||
| @@ -98,6 +101,8 @@ export class PermissionsSelectComponent | ||||
|         this.typesWithAllActions.delete(type) | ||||
|       } | ||||
|     }) | ||||
|  | ||||
|     this.updateDisabledStates() | ||||
|   } | ||||
|  | ||||
|   onChange = (newValue: string[]) => {} | ||||
| @@ -185,12 +190,16 @@ export class PermissionsSelectComponent | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // if checkbox is disabled either because "All", inhereted or entire component disabled | ||||
|   isDisabled(typeKey: string, actionKey: string) { | ||||
|     return this.typesWithAllActions.has(typeKey) || | ||||
|       this.isInherited(typeKey, actionKey) || | ||||
|       this.disabled | ||||
|       ? true | ||||
|       : null | ||||
|   updateDisabledStates() { | ||||
|     for (const type in PermissionType) { | ||||
|       const control = this.form.get(type) | ||||
|       let actionControl: AbstractControl | ||||
|       for (const action in PermissionAction) { | ||||
|         actionControl = control.get(action) | ||||
|         this.isInherited(type, action) || this.disabled | ||||
|           ? actionControl.disable() | ||||
|           : actionControl.enable() | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 shamoon
					shamoon