Implemented permissions and user administration #2
|
|
@ -48,69 +48,6 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<table>
|
|
||||||
<colgroup>
|
|
||||||
<col class="leader2" />
|
|
||||||
<col class="form2" />
|
|
||||||
</colgroup>
|
|
||||||
|
|
||||||
<thead>
|
|
||||||
<tr><th colspan="2">Berechtigungen</th></tr>
|
|
||||||
</thead>
|
|
||||||
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td>Benutzerverwaltung</td>
|
|
||||||
<td>
|
|
||||||
<div class="permission-selector">
|
|
||||||
{#each Permissions.iterate(Permissions.USERADMIN) as permission}
|
|
||||||
<label for={permission.value}>
|
|
||||||
<input type="checkbox" id={permission.value} name="USERADMIN" value={permission.value} data-bits={Permissions.deconstruct(permission.value).join(" ")} onclick={(event) => {
|
|
||||||
const target = event.target as HTMLInputElement
|
|
||||||
const container = target.parentElement?.parentElement ?? target
|
|
||||||
|
|
||||||
const bits = target.dataset?.bits?.split(" ")
|
|
||||||
if (!bits) return
|
|
||||||
|
|
||||||
if (bits.length > 1) {
|
|
||||||
for (const bit of bits) {
|
|
||||||
const affected = container.querySelectorAll(`input[data-bits="${bit}"]`) ?? []
|
|
||||||
for (const box of affected) {
|
|
||||||
(box as HTMLInputElement).checked = target.checked
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const bit = bits[0]
|
|
||||||
|
|
||||||
const affected = container.querySelectorAll(`input[data-bits~="${bit}"]`) ?? []
|
|
||||||
for (const _box of affected) {
|
|
||||||
const box = _box as HTMLInputElement
|
|
||||||
|
|
||||||
const groupBits = box.dataset.bits?.split(" ") ?? [];
|
|
||||||
const children = groupBits.map(
|
|
||||||
b => container.querySelector(`input[data-bits="${b}"]`) as HTMLInputElement
|
|
||||||
);
|
|
||||||
|
|
||||||
const allChecked = children.every(cb => cb.checked);
|
|
||||||
const anyChecked = children.some(cb => cb.checked);
|
|
||||||
|
|
||||||
box.indeterminate = (box.indeterminate && anyChecked) || (box.checked && !allChecked && anyChecked)
|
|
||||||
box.checked = allChecked;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}} />
|
|
||||||
{permission.name}
|
|
||||||
</label>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col class="leader3" />
|
<col class="leader3" />
|
||||||
|
|
@ -133,6 +70,80 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
{#if data.user?.id == data.loggedInAs.id || Permissions.has(data.loggedInAs.permissions ?? 0, Permissions.USERADMIN.EDIT_PASSWORD)}
|
||||||
|
<table>
|
||||||
|
<colgroup>
|
||||||
|
<col class="leader2" />
|
||||||
|
<col class="form2" />
|
||||||
|
</colgroup>
|
||||||
|
|
||||||
|
<thead>
|
||||||
|
<tr><th colspan="2">Berechtigungen</th></tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>Benutzerverwaltung</td>
|
||||||
|
<td>
|
||||||
|
<div class="permission-selector">
|
||||||
|
{#each Permissions.iterate(Permissions.USERADMIN) as permission}
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id={permission.value}
|
||||||
|
name="USERADMIN"
|
||||||
|
value={permission.value}
|
||||||
|
checked={Permissions.has(data.user.permissions, permission.value)}
|
||||||
|
disabled={data.user?.id == data.loggedInAs.id}
|
||||||
|
data-bits={Permissions.deconstruct(permission.value).join(" ")}
|
||||||
|
onclick={(event) => {
|
||||||
|
const target = event.target as HTMLInputElement
|
||||||
|
const container = target.parentElement?.parentElement ?? target
|
||||||
|
|
||||||
|
const bits = target.dataset?.bits?.split(" ")
|
||||||
|
if (!bits) return
|
||||||
|
|
||||||
|
if (bits.length > 1) {
|
||||||
|
for (const bit of bits) {
|
||||||
|
const affected = container.querySelectorAll(`input[data-bits="${bit}"]`) ?? []
|
||||||
|
for (const box of affected) {
|
||||||
|
(box as HTMLInputElement).checked = target.checked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const bit = bits[0]
|
||||||
|
|
||||||
|
const affected = container.querySelectorAll(`input[data-bits~="${bit}"]`) ?? []
|
||||||
|
for (const _box of affected) {
|
||||||
|
const box = _box as HTMLInputElement
|
||||||
|
|
||||||
|
const groupBits = box.dataset.bits?.split(" ") ?? [];
|
||||||
|
const children = groupBits.map(
|
||||||
|
b => container.querySelector(`input[data-bits="${b}"]`) as HTMLInputElement
|
||||||
|
);
|
||||||
|
|
||||||
|
const allChecked = children.every(cb => cb.checked);
|
||||||
|
const anyChecked = children.some(cb => cb.checked);
|
||||||
|
|
||||||
|
box.indeterminate = (box.indeterminate && anyChecked) || (box.checked && !allChecked && anyChecked)
|
||||||
|
box.checked = allChecked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}} />
|
||||||
|
{permission.name}
|
||||||
|
</label>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
<button type="submit">Speichern</button>
|
<button type="submit">Speichern</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -182,6 +193,10 @@ input[type="text"] {
|
||||||
border-bottom: solid 1px black;
|
border-bottom: solid 1px black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label:has(input[type="checkbox"][disabled]) {
|
||||||
|
color: gray;
|
||||||
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
width: 15%;
|
width: 15%;
|
||||||
margin-left: 85%;
|
margin-left: 85%;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue