adrema/resources/js/views/group/Index.vue

132 lines
5.9 KiB
Vue
Raw Normal View History

2023-08-25 00:23:38 +02:00
<template>
<page-layout>
<template #right>
2023-12-30 22:21:08 +01:00
<f-save-button form="groupform"></f-save-button>
2023-08-25 00:23:38 +02:00
</template>
2023-12-30 22:21:08 +01:00
<ui-popup v-if="editing !== null" heading="Untergruppen bearbeiten" inner-width="max-w-5xl" @close="editing = null">
<template #actions>
<a href="#" @click.prevent="store">
<ui-sprite src="save" class="text-zinc-400 w-6 h-6"></ui-sprite>
</a>
</template>
2023-08-25 00:23:38 +02:00
<div class="flex space-x-3">
2023-12-30 22:21:08 +01:00
<f-text id="parent-inner_name" v-model="editing.parent.inner_name" label="Interner Name" name="parent-inner_name"></f-text>
<f-select id="parent-level" v-model="editing.parent.level" label="Ebene" name="parent-level" :options="meta.levels"></f-select>
2023-08-25 00:23:38 +02:00
</div>
2023-12-30 22:21:08 +01:00
<div>
<table cellspacing="0" cellpadding="0" border="0" class="custom-table custom-table-sm table">
<thead>
<th>NaMi-Name</th>
<th>Interner Name</th>
<th>Ebene</th>
</thead>
<tr v-for="child in editing.children" :key="child.id">
<td>
<span v-text="child.name"></span>
</td>
<td>
<f-text :id="`inner_name-${child.id}`" v-model="child.inner_name" label="" size="sm" :name="`inner_name-${child.id}`"></f-text>
</td>
<td>
<f-select :id="`level-${child.id}`" v-model="child.level" label="" size="sm" :name="`level-${child.id}`" :options="meta.levels"></f-select>
</td>
</tr>
</table>
2023-08-25 00:23:38 +02:00
</div>
2023-12-30 22:21:08 +01:00
</ui-popup>
<form id="groupform" class="grow p-3" @submit.prevent="submit">
<table cellspacing="0" cellpadding="0" border="0" class="custom-table custom-table-sm table">
<thead>
<th>NaMi-Name</th>
<th>Interner Name</th>
<th>Ebene</th>
<th></th>
</thead>
<template v-for="child in childrenOf('null')" :key="child.id">
<tr>
<td>
2024-06-19 22:36:24 +02:00
<ui-table-toggle-button :value="child" :text="child.name" :level="0" :active="isOpen(child.id)" @toggle="toggle(child)"></ui-table-toggle-button>
2023-12-30 22:21:08 +01:00
</td>
<td v-text="child.inner_name"></td>
<td v-text="child.level"></td>
<td>
<a v-tooltip="`Bearbeiten`" href="#" class="inline-flex btn btn-warning btn-sm" @click.prevent="edit(child)"><ui-sprite src="pencil"></ui-sprite></a>
2023-12-30 22:21:08 +01:00
</td>
</tr>
<template v-for="subchild in childrenOf(child.id)" :key="subchild.id">
<tr>
2024-06-19 22:00:18 +02:00
<td>
2024-06-19 22:36:24 +02:00
<ui-table-toggle-button :value="subchild" :text="subchild.name" :level="1" :active="isOpen(subchild.id)" @toggle="toggle(subchild)"></ui-table-toggle-button>
2024-06-19 22:00:18 +02:00
</td>
2023-12-30 22:21:08 +01:00
<td v-text="subchild.inner_name"></td>
<td v-text="subchild.level"></td>
<td>
<a v-if="subchild.children_count" v-tooltip="`Bearbeiten`" href="#" class="inline-flex btn btn-warning btn-sm" @click.prevent="edit(subchild)"
><ui-sprite src="pencil"></ui-sprite
></a>
</td>
</tr>
<template v-for="subsubchild in childrenOf(subchild.id)" :key="subchild.id">
<tr>
2024-06-19 22:00:18 +02:00
<td>
2024-06-19 22:36:24 +02:00
<ui-table-toggle-button :value="subsubchild" :text="subsubchild.name" :level="2" :active="isOpen(subsubchild.id)"></ui-table-toggle-button>
2024-06-19 22:00:18 +02:00
</td>
2023-12-30 23:02:08 +01:00
<td v-text="subsubchild.inner_name"></td>
<td v-text="subsubchild.level"></td>
2023-12-30 22:21:08 +01:00
<td>
<a v-if="subsubchild.children_count" v-tooltip="`Bearbeiten`" href="#" class="inline-flex btn btn-warning btn-sm" @click.prevent="edit(subsubchild)"
><ui-sprite src="pencil"></ui-sprite
></a>
</td>
</tr>
</template>
</template>
</template>
</table>
2023-08-25 00:23:38 +02:00
</form>
</page-layout>
</template>
2023-12-30 22:21:08 +01:00
<script setup>
2024-06-19 22:36:24 +02:00
import {ref, reactive} from 'vue';
2023-12-30 22:21:08 +01:00
import {indexProps, useIndex} from '../../composables/useInertiaApiIndex.js';
const props = defineProps(indexProps);
var {axios, meta, data} = useIndex(props.data, 'invoice');
2023-08-25 00:23:38 +02:00
2023-12-30 22:21:08 +01:00
const children = reactive({
null: data.value,
2023-08-25 00:23:38 +02:00
});
2023-12-30 22:21:08 +01:00
var editing = ref(null);
2023-08-25 00:23:38 +02:00
2024-06-19 21:33:59 +02:00
async function toggle(parent) {
if (isOpen(parent.id)) {
delete children[parent.id];
} else {
children[parent.id] = (await axios.get(parent.links.children)).data.data;
}
2023-12-30 22:21:08 +01:00
}
2023-08-25 00:23:38 +02:00
2023-12-30 22:21:08 +01:00
async function edit(parent) {
editing.value = {
parent: parent,
children: (await axios.get(parent.links.children)).data.data,
};
2023-08-25 00:23:38 +02:00
}
2023-12-30 22:21:08 +01:00
function isOpen(child) {
return child in children;
2023-08-25 00:23:38 +02:00
}
2023-12-30 22:21:08 +01:00
function childrenOf(parent) {
return children[parent] ? children[parent] : [];
2023-08-25 00:23:38 +02:00
}
2023-12-30 22:21:08 +01:00
async function store() {
await axios.post(meta.value.links.bulkstore, [editing.value.parent, ...editing.value.children]);
children[editing.value.parent.id] = (await axios.get(editing.value.parent.links.children)).data.data;
editing.value = null;
2023-08-25 00:23:38 +02:00
}
</script>