2019-04-03 00:25:12 +02:00
|
|
|
<template lang="pug">
|
2022-02-04 22:35:15 +01:00
|
|
|
v-container.container.pa-0.pa-md-3
|
2020-08-16 14:07:44 +02:00
|
|
|
v-card
|
2020-10-10 00:40:47 +02:00
|
|
|
v-card-title
|
|
|
|
h4 {{edit?$t('common.edit_event'):$t('common.add_event')}}
|
|
|
|
v-spacer
|
2020-10-25 00:31:38 +02:00
|
|
|
v-btn(link text color='primary' @click='openImportDialog=true')
|
2022-02-08 14:45:19 +01:00
|
|
|
<v-icon v-text='mdiFileImport'></v-icon> {{$t('common.import')}}
|
2021-12-02 11:14:53 +01:00
|
|
|
v-dialog(v-model='openImportDialog' :fullscreen='$vuetify.breakpoint.xsOnly')
|
2020-10-10 00:40:47 +02:00
|
|
|
ImportDialog(@close='openImportDialog=false' @imported='eventImported')
|
|
|
|
|
2021-02-09 12:12:38 +01:00
|
|
|
v-card-text.px-0.px-xs-2
|
2020-10-10 00:40:47 +02:00
|
|
|
v-form(v-model='valid' ref='form' lazy-validation)
|
2020-10-25 00:31:38 +02:00
|
|
|
v-container
|
|
|
|
v-row
|
|
|
|
//- Not logged event
|
2021-04-27 11:10:18 +02:00
|
|
|
v-col(v-if='!$auth.loggedIn' cols=12)
|
2020-10-25 00:31:38 +02:00
|
|
|
p(v-html="$t('event.anon_description')")
|
|
|
|
|
|
|
|
//- Title
|
2021-04-27 11:10:18 +02:00
|
|
|
v-col(cols=12)
|
|
|
|
v-text-field(
|
|
|
|
@change='v => event.title = v'
|
|
|
|
:value = 'event.title'
|
|
|
|
:rules="[$validators.required('common.title')]"
|
2022-02-08 14:45:19 +01:00
|
|
|
:prepend-icon='mdiFormatTitle'
|
2021-04-27 11:10:18 +02:00
|
|
|
:label="$t('common.title')"
|
|
|
|
autofocus
|
|
|
|
ref='title')
|
2020-10-25 00:31:38 +02:00
|
|
|
|
|
|
|
//- Where
|
2021-04-27 11:10:18 +02:00
|
|
|
v-col(cols=12)
|
2021-06-05 00:51:27 +02:00
|
|
|
WhereInput(ref='where' v-model='event.place')
|
2020-10-25 00:31:38 +02:00
|
|
|
|
|
|
|
//- When
|
2021-07-19 12:04:06 +02:00
|
|
|
DateInput(v-model='date' :event='event')
|
2020-10-25 00:31:38 +02:00
|
|
|
//- Description
|
2021-04-27 11:10:18 +02:00
|
|
|
v-col.px-0(cols='12')
|
|
|
|
Editor.px-3.ma-0(
|
|
|
|
:label="$t('event.description_description')"
|
|
|
|
v-model='event.description'
|
|
|
|
:placeholder="$t('event.description_description')"
|
|
|
|
max-height='400px')
|
2020-10-25 00:31:38 +02:00
|
|
|
|
|
|
|
//- MEDIA / FLYER / POSTER
|
2021-04-27 11:10:18 +02:00
|
|
|
v-col(cols=12 md=6)
|
2021-07-15 16:18:56 +02:00
|
|
|
MediaInput(v-model='event.media[0]' :event='event' @remove='event.media=[]')
|
2020-10-25 00:31:38 +02:00
|
|
|
|
|
|
|
//- tags
|
2021-04-27 11:10:18 +02:00
|
|
|
v-col(cols=12 md=6)
|
|
|
|
v-combobox(v-model='event.tags'
|
2022-02-08 14:45:19 +01:00
|
|
|
:prepend-icon="mdiTagMultiple"
|
2021-04-27 11:10:18 +02:00
|
|
|
chips small-chips multiple deletable-chips hide-no-data hide-selected persistent-hint
|
2022-02-08 22:54:47 +01:00
|
|
|
:delimiters="[',', ';']"
|
2021-04-27 11:10:18 +02:00
|
|
|
:items="tags.map(t => t.tag)"
|
|
|
|
:label="$t('common.tags')")
|
2022-02-21 11:34:27 +01:00
|
|
|
template(v-slot:selection="{ item, on, attrs, selected, parent}")
|
|
|
|
v-chip(v-bind="attrs" close :close-icon='mdiCloseCircle' @click:close='parent.selectItem(item)'
|
|
|
|
:input-value="selected" label small) {{item}}
|
|
|
|
</v-chip>
|
2020-10-09 00:42:03 +02:00
|
|
|
|
2020-08-16 14:07:44 +02:00
|
|
|
v-card-actions
|
|
|
|
v-spacer
|
2020-10-10 00:40:47 +02:00
|
|
|
v-btn(@click='done' :loading='loading' :disabled='!valid || loading'
|
2021-07-15 16:18:56 +02:00
|
|
|
color='primary') {{edit?$t('common.save'):$t('common.send')}}
|
2019-04-03 00:25:12 +02:00
|
|
|
|
|
|
|
</template>
|
|
|
|
<script>
|
2020-01-15 23:56:11 +01:00
|
|
|
import { mapActions, mapState } from 'vuex'
|
2020-10-16 16:10:01 +02:00
|
|
|
import dayjs from 'dayjs'
|
2022-02-08 14:45:19 +01:00
|
|
|
|
2022-02-21 11:34:27 +01:00
|
|
|
import { mdiFileImport, mdiFormatTitle, mdiTagMultiple, mdiCloseCircle } from '@mdi/js'
|
2019-05-30 12:04:14 +02:00
|
|
|
|
2019-04-03 00:25:12 +02:00
|
|
|
export default {
|
2020-01-15 23:56:11 +01:00
|
|
|
name: 'NewEvent',
|
2022-02-08 22:54:47 +01:00
|
|
|
components: {
|
|
|
|
List: () => import(/* webpackChunkName: "add" */'@/components/List'),
|
|
|
|
Editor: () => import(/* webpackChunkName: "add" */'@/components/Editor'),
|
|
|
|
ImportDialog: () => import(/* webpackChunkName: "add" */'./ImportDialog.vue'),
|
|
|
|
MediaInput: () => import(/* webpackChunkName: "add" */'./MediaInput.vue'),
|
|
|
|
WhereInput: () => import(/* webpackChunkName: "add" */'./WhereInput.vue'),
|
|
|
|
DateInput: () => import(/* webpackChunkName: "add" */'./DateInput.vue')
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
validate ({ store }) {
|
2019-06-25 01:05:38 +02:00
|
|
|
return (store.state.auth.loggedIn || store.state.settings.allow_anon_event)
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
async asyncData ({ params, $axios, error, store }) {
|
2019-06-12 22:26:28 +02:00
|
|
|
if (params.edit) {
|
2021-07-15 16:18:56 +02:00
|
|
|
const data = { event: { place: {}, media: [] } }
|
2019-06-12 22:26:28 +02:00
|
|
|
data.id = params.edit
|
|
|
|
data.edit = true
|
|
|
|
let event
|
|
|
|
try {
|
2019-09-11 19:12:24 +02:00
|
|
|
event = await $axios.$get('/event/' + data.id)
|
2019-06-12 22:26:28 +02:00
|
|
|
} catch (e) {
|
2019-09-11 19:12:24 +02:00
|
|
|
error({ statusCode: 404, message: 'Event not found!' })
|
2019-06-12 22:26:28 +02:00
|
|
|
return {}
|
|
|
|
}
|
2020-10-27 11:56:47 +01:00
|
|
|
|
2019-06-12 22:26:28 +02:00
|
|
|
data.event.place.name = event.place.name
|
|
|
|
data.event.place.address = event.place.address || ''
|
2020-12-04 17:27:45 +01:00
|
|
|
data.date = {
|
|
|
|
recurrent: event.recurrent,
|
|
|
|
from: new Date(dayjs.unix(event.start_datetime)),
|
2021-02-09 12:12:38 +01:00
|
|
|
due: new Date(dayjs.unix(event.end_datetime)),
|
2021-02-27 00:53:26 +01:00
|
|
|
multidate: event.multidate,
|
|
|
|
fromHour: true,
|
|
|
|
dueHour: true
|
2019-07-13 01:02:11 +02:00
|
|
|
}
|
2019-07-30 18:32:26 +02:00
|
|
|
|
2019-06-12 22:26:28 +02:00
|
|
|
data.event.title = event.title
|
2020-01-15 23:56:11 +01:00
|
|
|
data.event.description = event.description
|
2019-06-12 22:26:28 +02:00
|
|
|
data.event.id = event.id
|
2019-10-30 15:01:15 +01:00
|
|
|
data.event.tags = event.tags
|
2021-07-15 16:18:56 +02:00
|
|
|
data.event.media = event.media || []
|
2019-06-12 22:26:28 +02:00
|
|
|
return data
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
2019-06-25 01:05:38 +02:00
|
|
|
return {}
|
2019-04-03 00:25:12 +02:00
|
|
|
},
|
2020-01-15 23:56:11 +01:00
|
|
|
data () {
|
2020-10-16 16:10:01 +02:00
|
|
|
const month = dayjs().month() + 1
|
|
|
|
const year = dayjs().year()
|
2020-01-15 23:56:11 +01:00
|
|
|
return {
|
2022-02-21 11:34:27 +01:00
|
|
|
mdiFileImport, mdiFormatTitle, mdiTagMultiple, mdiCloseCircle,
|
2020-07-28 12:24:39 +02:00
|
|
|
valid: false,
|
2020-10-10 00:40:47 +02:00
|
|
|
openImportDialog: false,
|
2020-01-15 23:56:11 +01:00
|
|
|
event: {
|
|
|
|
place: { name: '', address: '' },
|
|
|
|
title: '',
|
|
|
|
description: '',
|
|
|
|
tags: [],
|
2021-07-15 16:18:56 +02:00
|
|
|
media: []
|
2020-01-15 23:56:11 +01:00
|
|
|
},
|
|
|
|
page: { month, year },
|
|
|
|
fileList: [],
|
|
|
|
id: null,
|
2021-10-22 12:43:03 +02:00
|
|
|
date: { from: null, due: null, recurrent: null },
|
2020-01-15 23:56:11 +01:00
|
|
|
edit: false,
|
|
|
|
loading: false,
|
2020-10-25 00:31:38 +02:00
|
|
|
disableAddress: false
|
2019-09-11 19:12:24 +02:00
|
|
|
}
|
|
|
|
},
|
2020-12-04 17:27:45 +01:00
|
|
|
head () {
|
|
|
|
return {
|
|
|
|
title: `${this.settings.title} - ${this.$t('common.add_event')}`
|
|
|
|
}
|
|
|
|
},
|
2021-07-15 16:18:56 +02:00
|
|
|
computed: mapState(['tags', 'places', 'settings']),
|
2019-04-03 00:25:12 +02:00
|
|
|
methods: {
|
2020-11-13 00:13:59 +01:00
|
|
|
...mapActions(['updateMeta']),
|
2020-10-10 00:40:47 +02:00
|
|
|
eventImported (event) {
|
2020-10-16 16:10:01 +02:00
|
|
|
this.event = Object.assign(this.event, event)
|
2021-06-05 00:51:27 +02:00
|
|
|
this.$refs.where.selectPlace({ name: event.place.name, create: true })
|
2021-04-26 23:29:01 +02:00
|
|
|
this.date = {
|
2021-06-05 00:51:27 +02:00
|
|
|
recurrent: this.event.recurrent || null,
|
2021-04-26 23:29:01 +02:00
|
|
|
from: new Date(dayjs.unix(this.event.start_datetime)),
|
|
|
|
due: new Date(dayjs.unix(this.event.end_datetime)),
|
|
|
|
multidate: event.multidate,
|
|
|
|
fromHour: true,
|
|
|
|
dueHour: true
|
|
|
|
}
|
2021-04-27 11:10:18 +02:00
|
|
|
this.openImportDialog = false
|
2020-10-10 00:40:47 +02:00
|
|
|
},
|
2019-04-03 00:25:12 +02:00
|
|
|
async done () {
|
2021-06-05 00:51:27 +02:00
|
|
|
if (!this.$refs.form.validate()) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
const el = document.querySelector('.v-input.error--text:first-of-type')
|
|
|
|
el.scrollIntoView()
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2019-07-05 01:38:31 +02:00
|
|
|
this.loading = true
|
2019-07-15 23:35:59 +02:00
|
|
|
|
|
|
|
const formData = new FormData()
|
|
|
|
|
2020-12-04 17:27:45 +01:00
|
|
|
formData.append('recurrent', JSON.stringify(this.date.recurrent))
|
2019-04-03 00:25:12 +02:00
|
|
|
|
2021-07-15 16:18:56 +02:00
|
|
|
if (this.event.media.length) {
|
|
|
|
formData.append('image', this.event.media[0].image)
|
|
|
|
formData.append('image_url', this.event.media[0].url)
|
|
|
|
formData.append('image_name', this.event.media[0].name)
|
|
|
|
formData.append('image_focalpoint', this.event.media[0].focalpoint)
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
2021-07-15 16:18:56 +02:00
|
|
|
|
2019-04-03 00:25:12 +02:00
|
|
|
formData.append('title', this.event.title)
|
|
|
|
formData.append('place_name', this.event.place.name)
|
|
|
|
formData.append('place_address', this.event.place.address)
|
|
|
|
formData.append('description', this.event.description)
|
2021-02-09 12:12:38 +01:00
|
|
|
formData.append('multidate', !!this.date.multidate)
|
2020-12-04 17:27:45 +01:00
|
|
|
formData.append('start_datetime', dayjs(this.date.from).unix())
|
2021-10-22 12:43:03 +02:00
|
|
|
formData.append('end_datetime', this.date.due ? dayjs(this.date.due).unix() : this.date.from.add(2, 'hour').unix())
|
2019-07-11 23:31:37 +02:00
|
|
|
|
2019-04-03 00:25:12 +02:00
|
|
|
if (this.edit) {
|
|
|
|
formData.append('id', this.event.id)
|
|
|
|
}
|
2020-08-16 14:07:44 +02:00
|
|
|
if (this.event.tags) { this.event.tags.forEach(tag => formData.append('tags[]', tag.tag || tag)) }
|
2019-04-03 00:25:12 +02:00
|
|
|
try {
|
|
|
|
if (this.edit) {
|
2020-11-13 00:13:59 +01:00
|
|
|
await this.$axios.$put('/event', formData)
|
2019-04-03 00:25:12 +02:00
|
|
|
} else {
|
2020-11-13 00:13:59 +01:00
|
|
|
await this.$axios.$post('/event', formData)
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
|
|
|
this.updateMeta()
|
2021-01-22 21:16:22 +01:00
|
|
|
this.$router.push('/')
|
|
|
|
this.$nextTick(() => {
|
2021-02-27 00:53:26 +01:00
|
|
|
this.$root.$message(this.$auth.loggedIn ? (this.edit ? 'event.saved' : 'event.added') : 'event.added_anon', { color: 'success' })
|
2021-01-22 21:16:22 +01:00
|
|
|
})
|
2019-04-03 00:25:12 +02:00
|
|
|
} catch (e) {
|
2019-09-11 19:12:24 +02:00
|
|
|
switch (e.request.status) {
|
2019-07-17 12:19:09 +02:00
|
|
|
case 413:
|
2020-10-07 11:12:13 +02:00
|
|
|
this.$root.$message('event.image_too_big', { color: 'error' })
|
2019-09-11 19:12:24 +02:00
|
|
|
break
|
2019-07-17 12:19:09 +02:00
|
|
|
default:
|
2021-10-21 12:17:32 +02:00
|
|
|
this.$root.$message(e.response ? e.response.data : e, { color: 'error' })
|
2019-07-17 12:19:09 +02:00
|
|
|
}
|
2019-07-05 01:38:31 +02:00
|
|
|
this.loading = false
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-23 01:31:43 +02:00
|
|
|
</script>
|