2019-04-03 00:25:12 +02:00
|
|
|
<template lang="pug">
|
2020-08-16 14:07:44 +02:00
|
|
|
v-container.container
|
|
|
|
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')
|
2020-10-14 21:13:20 +02:00
|
|
|
<v-icon>mdi-file-import</v-icon> {{$t('common.import')}}
|
2020-10-10 00:40:47 +02:00
|
|
|
v-dialog(v-model='openImportDialog')
|
|
|
|
ImportDialog(@close='openImportDialog=false' @imported='eventImported')
|
|
|
|
|
2020-08-16 14:07:44 +02:00
|
|
|
v-card-text
|
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
|
|
|
|
v-col.col-12(v-if='!$auth.loggedIn')
|
|
|
|
v-divider <v-icon name='user-secret'/> {{$t('event.anon')}}
|
|
|
|
p(v-html="$t('event.anon_description')")
|
|
|
|
|
|
|
|
//- Title
|
|
|
|
v-text-field.col-12(
|
|
|
|
@change='v => event.title = v'
|
|
|
|
:value = 'event.title'
|
|
|
|
:rules="[$validators.required('common.title')]"
|
|
|
|
:hint="$t('event.what_description')"
|
2020-11-04 10:55:30 +01:00
|
|
|
prepend-icon='mdi-format-title'
|
2020-10-25 00:31:38 +02:00
|
|
|
:label="$t('common.title')"
|
|
|
|
autofocus
|
|
|
|
ref='title')
|
|
|
|
|
|
|
|
//- Where
|
|
|
|
WhereInput.col-12(v-model='event.place')
|
|
|
|
|
|
|
|
//- When
|
|
|
|
DateInput.col-12(v-model='date')
|
|
|
|
HourInput.col-12(v-model='time')
|
|
|
|
|
|
|
|
//- Description
|
|
|
|
Editor.col-12.mb-3(
|
|
|
|
v-model='event.description'
|
|
|
|
:placeholder="$t('event.description_description')"
|
|
|
|
max-height='400px')
|
|
|
|
|
|
|
|
//- MEDIA / FLYER / POSTER
|
|
|
|
|
|
|
|
v-file-input.col-6.mt-3(
|
|
|
|
:label="$t('common.media')"
|
|
|
|
:hint="$t('event.media_description')"
|
|
|
|
prepend-icon="mdi-camera"
|
|
|
|
v-model='event.image'
|
|
|
|
persistent-hint
|
|
|
|
accept='image/*')
|
|
|
|
|
|
|
|
//- tags
|
|
|
|
v-combobox.col-6.mt-3(v-model='event.tags'
|
2020-11-04 10:55:30 +01:00
|
|
|
prepend-icon="mdi-tag-multiple"
|
2020-10-25 00:31:38 +02:00
|
|
|
chips small-chips multiple deletable-chips hide-no-data hide-selected persistent-hint
|
|
|
|
:delimiters="[',', ' ']"
|
|
|
|
:items="tags.map(t => t.tag)"
|
|
|
|
:label="$t('common.tags')")
|
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'
|
2020-08-16 14:07:44 +02:00
|
|
|
color='primary') {{edit?$t('common.edit'):$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'
|
2020-01-15 23:56:11 +01:00
|
|
|
import Editor from '@/components/Editor'
|
2019-05-30 12:04:14 +02:00
|
|
|
import List from '@/components/List'
|
2020-10-10 00:40:47 +02:00
|
|
|
import ImportDialog from './ImportDialog'
|
2020-10-25 00:31:38 +02:00
|
|
|
import DateInput from './DateInput'
|
|
|
|
import HourInput from './HourInput'
|
|
|
|
import WhereInput from './WhereInput'
|
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',
|
2020-10-25 00:31:38 +02:00
|
|
|
components: { List, Editor, ImportDialog, WhereInput, HourInput, DateInput },
|
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) {
|
2019-09-11 19:12:24 +02:00
|
|
|
const data = { time: {}, event: { place: {} } }
|
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-10-27 11:56:47 +01:00
|
|
|
data.date = {}
|
2019-06-12 22:26:28 +02:00
|
|
|
if (event.multidate) {
|
2020-10-27 11:56:47 +01:00
|
|
|
data.date = {
|
|
|
|
type: 'multidate',
|
|
|
|
start: dayjs.unix(event.start_datetime).toDate(),
|
|
|
|
end: dayjs.unix(event.end_datetime).toDate()
|
|
|
|
}
|
2019-09-11 19:12:24 +02:00
|
|
|
} else if (event.recurrent) {
|
2020-10-27 11:56:47 +01:00
|
|
|
data.date.type = 'recurrent'
|
|
|
|
data.date.recurrent = event.recurrent
|
2019-06-12 22:26:28 +02:00
|
|
|
} else {
|
2020-10-27 11:56:47 +01:00
|
|
|
data.date.type = 'normal'
|
|
|
|
data.date.date = dayjs.unix(event.start_datetime).format('YYYY-MM-DD')
|
2019-07-13 01:02:11 +02:00
|
|
|
}
|
2019-07-30 18:32:26 +02:00
|
|
|
|
2020-10-16 16:10:01 +02:00
|
|
|
data.time.start = dayjs.unix(event.start_datetime).format('HH:mm')
|
|
|
|
data.time.end = dayjs.unix(event.end_datetime).format('HH:mm')
|
2020-10-27 11:56:47 +01: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
|
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 {
|
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: {
|
|
|
|
type: 'normal',
|
|
|
|
place: { name: '', address: '' },
|
|
|
|
title: '',
|
|
|
|
description: '',
|
|
|
|
tags: [],
|
2020-10-25 00:31:38 +02:00
|
|
|
image: null,
|
2020-10-07 10:08:18 +02:00
|
|
|
recurrent: { frequency: '1m', days: [], type: 'weekday_desc' }
|
2020-01-15 23:56:11 +01:00
|
|
|
},
|
|
|
|
page: { month, year },
|
|
|
|
fileList: [],
|
|
|
|
id: null,
|
2020-10-16 16:10:01 +02:00
|
|
|
date: { type: 'normal', recurrent: {} },
|
2020-10-07 10:08:18 +02:00
|
|
|
time: { start: null, end: null },
|
2020-01-15 23:56:11 +01:00
|
|
|
edit: false,
|
|
|
|
loading: false,
|
|
|
|
mediaUrl: '',
|
2020-10-25 00:31:38 +02:00
|
|
|
disableAddress: false
|
2019-09-11 19:12:24 +02:00
|
|
|
}
|
|
|
|
},
|
2019-04-03 00:25:12 +02:00
|
|
|
computed: {
|
2020-10-25 00:31:38 +02:00
|
|
|
...mapState(['tags', 'places', 'events', 'settings'])
|
2020-01-15 23:56:11 +01:00
|
|
|
},
|
2019-04-03 00:25:12 +02:00
|
|
|
methods: {
|
2019-06-12 22:26:28 +02:00
|
|
|
...mapActions(['addEvent', 'updateEvent', 'updateMeta', 'updateEvents']),
|
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)
|
2020-10-10 00:40:47 +02:00
|
|
|
},
|
2020-01-15 23:56:11 +01:00
|
|
|
// recurrentDays () {
|
|
|
|
// if (this.event.type !== 'recurrent' || !this.date || !this.date.length) { return }
|
|
|
|
// const type = this.event.recurrent.type
|
2020-10-16 16:10:01 +02:00
|
|
|
// if (type === 'ordinal') { return map(this.date, d => dayjs(d).date()) } else if (type === 'weekday') { return map(this.date, d => dayjs(d).day() + 1) }
|
2020-01-15 23:56:11 +01:00
|
|
|
// },
|
|
|
|
// },
|
2019-07-17 12:19:09 +02:00
|
|
|
cleanFile () {
|
2020-07-25 21:41:22 +02:00
|
|
|
this.event.image = {}
|
2019-07-17 12:19:09 +02:00
|
|
|
},
|
2019-04-03 00:25:12 +02:00
|
|
|
async done () {
|
2020-10-25 00:31:38 +02:00
|
|
|
if (!this.$refs.form.validate()) { return }
|
2019-07-05 01:38:31 +02:00
|
|
|
this.loading = true
|
2019-04-03 00:25:12 +02:00
|
|
|
let start_datetime, end_datetime
|
2020-01-15 23:56:11 +01:00
|
|
|
const [start_hour, start_minute] = this.time.start.split(':')
|
2019-04-03 00:25:12 +02:00
|
|
|
if (!this.time.end) {
|
2019-09-11 19:12:24 +02:00
|
|
|
this.time.end = (Number(start_hour) + 2) + ':' + start_minute
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
2020-01-15 23:56:11 +01:00
|
|
|
const [end_hour, end_minute] = this.time.end.split(':')
|
2019-07-15 23:35:59 +02:00
|
|
|
|
|
|
|
const formData = new FormData()
|
|
|
|
|
2020-10-27 11:56:47 +01:00
|
|
|
if (this.date.type === 'multidate') {
|
|
|
|
start_datetime = dayjs(this.date.date[0])
|
2019-04-03 00:25:12 +02:00
|
|
|
.set('hour', start_hour).set('minute', start_minute)
|
2020-10-27 11:56:47 +01:00
|
|
|
end_datetime = dayjs(this.date.date[1])
|
2019-04-03 00:25:12 +02:00
|
|
|
.set('hour', end_hour).set('minute', end_minute)
|
2020-10-27 11:56:47 +01:00
|
|
|
} else if (this.date.type === 'normal') {
|
|
|
|
start_datetime = dayjs(this.date.date).set('hour', start_hour).set('minute', start_minute)
|
|
|
|
end_datetime = dayjs(this.date.date).set('hour', end_hour).set('minute', end_minute)
|
2019-09-11 19:12:24 +02:00
|
|
|
if (end_hour < start_hour) {
|
2019-07-13 22:51:45 +02:00
|
|
|
end_datetime = end_datetime.add(1, 'day')
|
|
|
|
}
|
2020-10-27 11:56:47 +01:00
|
|
|
} else if (this.date.type === 'recurrent') {
|
2020-10-16 16:10:01 +02:00
|
|
|
start_datetime = dayjs().set('hour', start_hour).set('minute', start_minute)
|
|
|
|
end_datetime = dayjs().set('hour', end_hour).set('minute', end_minute)
|
2020-10-27 11:56:47 +01:00
|
|
|
// const recurrent = {
|
|
|
|
// frequency: this.event.recurrent.frequency,
|
|
|
|
// days: this.event.recurrent.type === 'ordinal' ? _.map(this.date, d => dayjs(d).date()) : _.map(this.date, d => dayjs(d).day() + 1),
|
|
|
|
// type: this.event.recurrent.type
|
|
|
|
// }
|
2019-09-11 19:12:24 +02:00
|
|
|
if (end_hour < start_hour) {
|
2019-07-15 23:35:59 +02:00
|
|
|
end_datetime = end_datetime.add(1, 'day')
|
2019-09-11 19:12:24 +02:00
|
|
|
}
|
2020-10-27 11:56:47 +01:00
|
|
|
formData.append('recurrent', JSON.stringify(this.date.recurrent))
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.event.image) {
|
2020-07-28 12:24:39 +02:00
|
|
|
formData.append('image', this.event.image)
|
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)
|
2019-07-14 01:44:28 +02:00
|
|
|
formData.append('multidate', this.event.type === 'multidate')
|
2019-10-20 14:22:55 +02:00
|
|
|
formData.append('start_datetime', start_datetime.unix())
|
|
|
|
formData.append('end_datetime', end_datetime.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) {
|
|
|
|
await this.updateEvent(formData)
|
|
|
|
} else {
|
|
|
|
await this.addEvent(formData)
|
|
|
|
}
|
|
|
|
this.updateMeta()
|
2019-05-30 12:04:14 +02:00
|
|
|
this.$router.replace('/')
|
2019-07-05 01:38:31 +02:00
|
|
|
this.loading = false
|
2020-10-07 11:12:13 +02:00
|
|
|
this.$root.$message(this.$auth.loggedIn ? 'event.added' : 'event.added_anon', { color: 'success' })
|
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:
|
2020-10-07 11:12:13 +02:00
|
|
|
this.$root.$message(e.response.data, { 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
|
|
|
}
|
|
|
|
}
|
2020-01-15 23:56:11 +01:00
|
|
|
},
|
|
|
|
head () {
|
|
|
|
return {
|
|
|
|
title: `${this.settings.title} - ${this.$t('common.add_event')}`
|
|
|
|
}
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-23 01:31:43 +02:00
|
|
|
</script>
|
2020-01-15 23:56:11 +01:00
|
|
|
<style style='less'>
|
2020-08-16 14:07:44 +02:00
|
|
|
.container {
|
|
|
|
max-width: 1400px;
|
|
|
|
}
|
2020-01-21 01:24:10 +01:00
|
|
|
|
2019-10-28 17:33:20 +01:00
|
|
|
</style>
|