fix add/edit event

This commit is contained in:
les 2020-10-27 11:56:47 +01:00
parent 1001a4d25b
commit 0731b4dd8c
4 changed files with 44 additions and 30 deletions

View file

@ -1,5 +1,6 @@
<template lang="pug">
v-row
p {{value}}
v-menu(
v-model="datePickerMenu"
:close-on-content-click="false"
@ -10,7 +11,7 @@ v-row
)
template(v-slot:activator="{ on, attrs }")
v-text-field.col-md-8(
v-model='date'
:value='value.date'
:label="$t('common.when')"
:rules="[$validators.required('common.when')]"
prepend-icon='mdi-calendar'
@ -19,7 +20,7 @@ v-row
v-on="on")
v-date-picker(
:min='today'
v-model="date"
v-model="value.date"
:range="type === 'multidate'"
:locale='settings.locale'
@input="pick")

View file

@ -5,7 +5,7 @@
:close-on-content-click="false"
transition="slide-x-transition"
ref='startTimeMenu'
:return-value.sync="time.start"
:return-value.sync="value.start"
offset-y
absolute
top
@ -15,7 +15,7 @@
v-text-field(
:label="$t('event.from')"
:rules="[$validators.required('event.from')]"
:value='time.start'
:value='value.start'
v-on='on'
clearable)
v-time-picker(
@ -24,7 +24,7 @@
format="24hr"
ref='time_start'
:allowed-minutes="[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]"
v-model='time.start'
v-model='value.start'
@click:minute="selectTime('start')")
v-col.col-6
@ -41,7 +41,7 @@
template(v-slot:activator='{ on }')
v-text-field(
:label="$t('event.due')"
:value='time.end'
:value='value.end'
v-on='on'
clearable
readonly)
@ -50,7 +50,7 @@
:label="$t('event.due')"
format="24hr"
:allowed-minutes="[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]"
v-model='time.end'
v-model='value.end'
@click:minute="selectTime('end')")
</template>
@ -61,7 +61,9 @@ export default {
value: { type: Object, default: () => { } }
},
data () {
// console.error('sono dentro data ', this.value)
return {
// time: { start: this.value.start, end: this.value.end },
time: {},
startTimeMenu: false,
endTimeMenu: false
@ -69,8 +71,8 @@ export default {
},
methods: {
selectTime (type) {
this.$refs[`${type}TimeMenu`].save(this.time.end)
this.$emit('input', this.time)
this.$refs[`${type}TimeMenu`].save(this.value[type])
this.$emit('input', this.value)
}
}
}

View file

@ -7,6 +7,7 @@
:hide-no-data="!place._name"
:search-input.sync="place._name"
persistent-hint
:value="value.place"
:items="places"
item-text='name'
@change='selectPlace')
@ -19,7 +20,7 @@
:rules="[$validators.required('common.address')]"
:label="$t('common.address')"
@change="changeAddress"
:value="place.address")
:value="value.address")
</template>
<script>
@ -27,6 +28,9 @@ import { mapState } from 'vuex'
export default {
name: 'WhereInput',
props: {
value: { type: Object, default: () => {} }
},
data () {
return {
place: { _name: '' },

View file

@ -93,22 +93,27 @@ export default {
error({ statusCode: 404, message: 'Event not found!' })
return {}
}
data.event.recurrent = {}
data.event.place.name = event.place.name
data.event.place.address = event.place.address || ''
data.date = {}
if (event.multidate) {
data.date = { start: dayjs.unix(event.start_datetime).toDate(), end: dayjs.unix(event.end_datetime).toDate() }
data.event.type = 'multidate'
data.date = {
type: 'multidate',
start: dayjs.unix(event.start_datetime).toDate(),
end: dayjs.unix(event.end_datetime).toDate()
}
} else if (event.recurrent) {
data.event.type = 'recurrent'
data.event.recurrent = event.recurrent
data.date.type = 'recurrent'
data.date.recurrent = event.recurrent
} else {
data.event.type = 'normal'
data.date = dayjs.unix(event.start_datetime).toDate()
data.date.type = 'normal'
data.date.date = dayjs.unix(event.start_datetime).format('YYYY-MM-DD')
}
data.time.start = dayjs.unix(event.start_datetime).format('HH:mm')
data.time.end = dayjs.unix(event.end_datetime).format('HH:mm')
data.event.title = event.title
data.event.description = event.description
data.event.id = event.id
@ -165,6 +170,7 @@ export default {
this.loading = true
let start_datetime, end_datetime
const [start_hour, start_minute] = this.time.start.split(':')
console.error('TIME: hour', start_hour, this.time)
if (!this.time.end) {
this.time.end = (Number(start_hour) + 2) + ':' + start_minute
}
@ -172,29 +178,30 @@ export default {
const formData = new FormData()
if (this.event.type === 'multidate') {
start_datetime = dayjs(this.date.start)
if (this.date.type === 'multidate') {
start_datetime = dayjs(this.date.date[0])
.set('hour', start_hour).set('minute', start_minute)
end_datetime = dayjs(this.date.end)
end_datetime = dayjs(this.date.date[1])
.set('hour', end_hour).set('minute', end_minute)
} else if (this.event.type === 'normal') {
start_datetime = dayjs(this.date).set('hour', start_hour).set('minute', start_minute)
end_datetime = dayjs(this.date).set('hour', end_hour).set('minute', end_minute)
} else if (this.date.type === 'normal') {
console.error('dentro type normal', this.date.type)
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)
if (end_hour < start_hour) {
end_datetime = end_datetime.add(1, 'day')
}
} else if (this.event.type === 'recurrent') {
} else if (this.date.type === 'recurrent') {
start_datetime = dayjs().set('hour', start_hour).set('minute', start_minute)
end_datetime = dayjs().set('hour', end_hour).set('minute', end_minute)
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
}
// 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
// }
if (end_hour < start_hour) {
end_datetime = end_datetime.add(1, 'day')
}
formData.append('recurrent', JSON.stringify(recurrent))
formData.append('recurrent', JSON.stringify(this.date.recurrent))
}
if (this.event.image) {