adrema/resources/js/views/contribution/VIndex.vue

84 lines
3.2 KiB
Vue
Raw Normal View History

2022-05-17 01:37:07 +02:00
<template>
2023-04-29 23:41:26 +02:00
<page-layout>
<form target="_BLANK" class="max-w-4xl w-full mx-auto gap-6 grid-cols-2 grid p-6">
2024-06-28 12:43:05 +02:00
<f-text id="eventName" v-model="values.eventName" class="col-span-2" label="Veranstaltungs-Name" required></f-text>
<f-text id="dateFrom" v-model="values.dateFrom" type="date" label="Datum von" required></f-text>
<f-text id="dateUntil" v-model="values.dateUntil" type="date" label="Datum bis" required></f-text>
2022-05-20 01:18:11 +02:00
2024-06-28 12:43:05 +02:00
<f-text id="zipLocation" v-model="values.zipLocation" label="PLZ / Ort" required></f-text>
<f-select id="country" v-model="values.country" :options="countries" name="country" label="Land" required></f-select>
2022-08-23 23:49:19 +02:00
2023-04-29 23:41:26 +02:00
<div class="border-gray-200 shadow shadow-primary-700 p-3 shadow-[0_0_4px_gray] col-span-2">
2024-07-03 17:12:57 +02:00
<f-text id="search_text" ref="searchInput" v-model="searchString" class="col-span-2" label="Suchen …" size="sm" @keypress.enter.prevent="onSubmitFirstMemberResult"></f-text>
2023-04-29 23:41:26 +02:00
<div class="mt-2 grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-2 col-span-2">
2024-06-28 12:43:05 +02:00
<f-switch
2024-07-03 17:31:06 +02:00
v-for="member in results.hits"
2024-06-28 12:43:05 +02:00
:id="`members-${member.id}`"
:key="member.id"
v-model="values.members"
:label="member.fullname"
name="members[]"
:value="member.id"
size="sm"
inline
@keypress.enter.prevent="onSubmitMemberResult(member)"
></f-switch>
2023-04-29 23:41:26 +02:00
</div>
</div>
2022-05-20 01:18:11 +02:00
2024-07-03 17:10:04 +02:00
<button v-for="(compiler, index) in compilers" :key="index" class="btn btn-primary mt-3 inline-block" @click.prevent="submit(compiler.class)" v-text="compiler.title"></button>
2023-04-29 23:41:26 +02:00
</form>
</page-layout>
2022-05-17 01:37:07 +02:00
</template>
2024-07-03 16:37:58 +02:00
<script lang="js" setup>
2024-07-03 17:31:06 +02:00
import { ref, inject } from 'vue';
2024-01-28 11:42:32 +01:00
import useSearch from '../../composables/useSearch.js';
const axios = inject('axios');
2023-02-26 20:51:59 +01:00
2024-07-03 17:31:06 +02:00
const { searchString, results, clearSearch } = useSearch(['birthday IS NOT NULL', 'address IS NOT EMPTY']);
2023-02-26 20:51:59 +01:00
2024-01-28 11:42:32 +01:00
const props = defineProps({
data: {},
countries: {},
compilers: {},
});
2024-07-03 17:12:32 +02:00
const searchInput = ref([]);
2024-01-28 11:42:32 +01:00
const values = ref({
type: null,
members: [],
2024-07-03 17:09:34 +02:00
eventName: '',
2024-01-28 11:42:32 +01:00
dateFrom: '',
dateUntil: '',
zipLocation: '',
country: null,
...props.data,
});
2024-01-28 11:42:32 +01:00
async function submit(compiler) {
values.value.type = compiler;
await axios.post('/contribution-validate', values.value);
var payload = btoa(encodeURIComponent(JSON.stringify(values.value)));
window.open(`/contribution-generate?payload=${payload}`);
}
function onSubmitMemberResult(selected) {
if (values.value.members.find((m) => m === selected.id) !== undefined) {
values.value.members = values.value.members.filter((m) => m !== selected.id);
} else {
values.value.members.push(selected.id);
}
2024-07-03 17:31:06 +02:00
clearSearch();
2024-07-03 17:12:32 +02:00
searchInput.value.$el.querySelector('input').focus();
2024-01-28 11:42:32 +01:00
}
function onSubmitFirstMemberResult() {
2024-07-03 17:31:06 +02:00
if (results.value.hits.length === 0) {
clearSearch();
2024-01-28 11:42:32 +01:00
return;
}
2024-07-03 17:31:06 +02:00
onSubmitMemberResult(results.value.hits[0]);
2024-01-28 11:42:32 +01:00
}
2022-05-17 01:37:07 +02:00
</script>