adrema/resources/js/views/member/MemberMemberships.vue

95 lines
3.7 KiB
Vue
Raw Normal View History

2021-08-22 22:23:17 +02:00
<template>
2023-05-20 01:45:43 +02:00
<div class="sidebar flex flex-col group is-bright">
2023-09-05 16:29:22 +02:00
<page-header title="Mitgliedschaften" @close="$emit('close')">
2023-05-20 02:38:38 +02:00
<template #toolbar>
2023-09-12 16:54:13 +02:00
<page-toolbar-button v-if="single === null" color="primary" icon="plus" @click.prevent="create">Neue Mitgliedschaft</page-toolbar-button>
<page-toolbar-button v-if="single !== null" color="primary" icon="undo" @click.prevent="single = null">Zurück</page-toolbar-button>
2023-05-20 02:38:38 +02:00
</template>
2023-05-20 01:45:43 +02:00
</page-header>
2021-08-22 22:23:17 +02:00
<form v-if="single" class="p-6 grid gap-4 justify-start" @submit.prevent="submit">
2023-09-12 16:54:13 +02:00
<f-select id="group_id" v-model="single.group_id" name="group_id" :options="data.meta.groups" label="Gruppierung" required></f-select>
<f-select id="activity_id" v-model="single.activity_id" name="activity_id" :options="data.meta.activities" label="Tätigkeit" required></f-select>
<f-select
v-if="single.activity_id"
id="subactivity_id"
v-model="single.subactivity_id"
name="subactivity_id"
:options="data.meta.subactivities[single.activity_id]"
label="Untertätigkeit"
></f-select>
<f-switch id="has_promise" :model-value="single.promised_at !== null" label="Hat Versprechen" @update:modelValue="single.promised_at = $event ? '2000-02-02' : null"></f-switch>
<f-text v-show="single.promised_at !== null" id="promised_at" v-model="single.promised_at" type="date" label="Versprechensdatum" size="sm"></f-text>
2021-08-22 22:23:17 +02:00
<button type="submit" class="btn btn-primary">Absenden</button>
</form>
2023-09-05 16:29:22 +02:00
<div v-else class="grow">
2022-02-10 02:18:57 +01:00
<table class="custom-table custom-table-light custom-table-sm text-sm">
<thead>
<th>Tätigkeit</th>
<th>Untertätigkeit</th>
<th>Datum</th>
2023-09-05 16:29:22 +02:00
<th>Aktiv</th>
2022-02-10 02:18:57 +01:00
<th></th>
</thead>
2021-08-22 22:23:17 +02:00
2023-09-12 16:54:13 +02:00
<tr v-for="(membership, index) in data.data" :key="index">
2022-02-10 02:18:57 +01:00
<td v-text="membership.activity_name"></td>
<td v-text="membership.subactivity_name"></td>
<td v-text="membership.human_date"></td>
2023-09-05 16:29:22 +02:00
<td><ui-boolean-display :value="membership.is_active" dark></ui-boolean-display></td>
2023-09-12 16:54:13 +02:00
<td class="flex space-x-1">
<a href="#" class="inline-flex btn btn-warning btn-sm" @click.prevent="edit(membership)"><ui-sprite src="pencil"></ui-sprite></a>
<a href="#" class="inline-flex btn btn-danger btn-sm" @click.prevent="remove(membership)"><ui-sprite src="trash"></ui-sprite></a>
2022-02-10 02:18:57 +01:00
</td>
</tr>
</table>
</div>
2021-08-22 22:23:17 +02:00
</div>
</template>
2023-09-12 16:54:13 +02:00
<script setup>
import {ref, inject, onBeforeMount} from 'vue';
const axios = inject('axios');
2021-08-22 22:23:17 +02:00
2023-09-12 16:54:13 +02:00
const props = defineProps({
value: {
type: Object,
required: true,
},
2023-09-12 16:54:13 +02:00
});
2023-09-12 16:54:13 +02:00
const single = ref(null);
const data = ref({
meta: {},
data: [],
});
2021-08-22 22:23:17 +02:00
2023-09-12 16:54:13 +02:00
async function reload() {
data.value = (await axios.post(props.value.links.membership_index)).data;
}
2021-08-22 22:23:17 +02:00
2023-09-12 16:54:13 +02:00
onBeforeMount(async () => {
await reload();
});
2021-08-22 22:23:17 +02:00
2023-09-12 16:54:13 +02:00
function create() {
single.value = JSON.parse(JSON.stringify(data.value.meta.default));
}
2021-08-22 22:23:17 +02:00
2023-09-12 16:54:13 +02:00
function edit(membership) {
single.value = JSON.parse(JSON.stringify(membership));
}
2021-08-22 22:23:17 +02:00
2023-09-12 16:54:13 +02:00
async function submit() {
single.value.id ? await axios.patch(single.value.links.update, single.value) : await axios.post(data.value.meta.links.store, single.value);
await reload();
single.value = null;
}
2021-08-22 22:23:17 +02:00
2023-09-12 16:54:13 +02:00
async function remove(membership) {
await axios.delete(membership.links.destroy);
await reload();
}
2021-08-22 22:23:17 +02:00
</script>