adrema/resources/js/views/activity/VForm.vue

63 lines
1.9 KiB
Vue
Raw Normal View History

2023-02-25 17:19:17 +01:00
<template>
2023-03-04 12:02:17 +01:00
<form id="actionform" class="grow p-3" @submit.prevent="submit">
2023-02-25 17:19:17 +01:00
<f-text id="name" v-model="inner.name" label="Name" required></f-text>
2023-03-04 12:02:17 +01:00
<checkboxes-label class="mt-6">Untertätigkeiten</checkboxes-label>
2023-02-25 17:19:17 +01:00
<div class="grid gap-2 sm:grid-cols-2 md:grid-cols-4">
2023-03-04 12:02:17 +01:00
<f-switch
inline
size="sm"
:key="option.id"
v-model="inner.subactivities"
name="subactivities[]"
:id="`subactivities-${option.id}`"
:value="option.id"
:label="option.name"
v-for="option in subactivities"
></f-switch>
2023-02-25 17:19:17 +01:00
</div>
<save-button form="actionform"></save-button>
2023-03-04 12:02:17 +01:00
<new-subactivity @stored="reloadSubactivities" :activity-id="inner.id"></new-subactivity>
2023-02-25 17:19:17 +01:00
</form>
</template>
<script>
export default {
data: function () {
return {
2023-03-04 12:02:17 +01:00
subactivities: [...this.meta.subactivities],
2023-02-25 17:19:17 +01:00
inner: {...this.data},
2023-02-25 18:00:23 +01:00
mode: this.data.name === '' ? 'create' : 'edit',
2023-02-25 17:19:17 +01:00
};
},
props: {
data: {},
meta: {},
},
components: {
'checkboxes-label': () => import('../../components/Form/CheckboxesLabel'),
2023-03-04 12:02:17 +01:00
'new-subactivity': () => import('./NewSubactivity.vue'),
2023-02-25 17:19:17 +01:00
},
methods: {
submit() {
2023-03-04 12:02:17 +01:00
this.mode === 'create' ? this.$inertia.post('/activity', this.inner) : this.$inertia.patch(`/activity/${this.inner.id}`, this.inner);
2023-02-25 17:19:17 +01:00
},
2023-03-04 12:02:17 +01:00
reloadSubactivities(model) {
var _self = this;
this.$inertia.reload({
onSuccess(page) {
_self.subactivities = page.props.meta.subactivities;
_self.inner.subactivities.push(model.id);
_self.$success('Untertätigkeit gespeichert.');
},
});
},
},
2023-02-25 17:19:17 +01:00
};
</script>