DateInput
This commit is contained in:
@@ -20,11 +20,11 @@ v-row
|
||||
v-date-picker(
|
||||
:min='today'
|
||||
v-model="value.date"
|
||||
:range="type === 'multidate'"
|
||||
:range="value.type === 'multidate'"
|
||||
:locale='settings.locale'
|
||||
@input="pick")
|
||||
|
||||
v-btn-toggle.col-md-4(@change='changeType' color='primary' :value='type')
|
||||
v-btn-toggle.col-md-4(@change='changeType' color='primary' :value='value.type')
|
||||
v-btn(value='normal') {{$t('event.normal')}}
|
||||
v-btn(value='multidate') {{$t('event.multidate')}}
|
||||
v-menu(v-if='settings.allow_recurrent_event' offset-y open-on-hover)
|
||||
@@ -34,8 +34,8 @@ v-row
|
||||
v-list-item(v-for='f in frequencies' :key='f.value'
|
||||
@click='selectFrequency(f.value)') {{f.text}}
|
||||
|
||||
//- //- p.col-12 {{$t(`event.${type}_description`)}}
|
||||
//- v-btn-toggle(v-if="type === 'recurrent'" v-model='recurrent.frequency' color='primary')
|
||||
p.col-12 {{$t(`event.${value.type}_description`)}}
|
||||
//- v-btn-toggle(v-if="type === 'recurrent'" v-model='value.recurrent.frequency' color='primary')
|
||||
//- v-btn(v-for='f in frequencies' :value='f.value') {{f.text}}
|
||||
|
||||
//- .datePicker
|
||||
@@ -49,9 +49,9 @@ v-row
|
||||
//- is-expanded
|
||||
//- :min-date='type !== "recurrent" && new Date()')
|
||||
|
||||
div.text-center.mb-2(v-if='type === "recurrent"')
|
||||
span(v-if='recurrent.frequency !== "1m" && recurrent.frequency !== "2m"') {{whenPatterns}}
|
||||
v-btn-toggle.mt-1(v-else v-model='recurrent.type' color='primary')
|
||||
div.text-center.mb-2(v-if='value.type === "recurrent"')
|
||||
span(v-if='value.recurrent.frequency !== "1m" && value.recurrent.frequency !== "2m"') {{whenPatterns}}
|
||||
v-btn-toggle.mt-1(v-else v-model='value.recurrent.type' color='primary')
|
||||
v-btn(v-for='whenPattern in whenPatterns' :value='whenPattern.key' :key='whenPatterns.key' small)
|
||||
span {{whenPattern.label}}
|
||||
|
||||
@@ -72,7 +72,6 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
date: null,
|
||||
datePickerMenu: false,
|
||||
today: dayjs().format('YYYY-MM-DD'),
|
||||
type: 'normal',
|
||||
@@ -95,10 +94,10 @@ export default {
|
||||
return modeMap[this.type]
|
||||
},
|
||||
whenPatterns () {
|
||||
if (!this.date) { return }
|
||||
const date = dayjs(this.date)
|
||||
if (!this.value.date) { return }
|
||||
const date = dayjs(this.value.date)
|
||||
|
||||
const freq = this.recurrent.frequency
|
||||
const freq = this.value.recurrent.frequency
|
||||
const weekDay = date.format('dddd')
|
||||
if (freq === '1w' || freq === '2w') {
|
||||
return this.$t(`event.recurrent_${freq}_days`, { days: weekDay })
|
||||
@@ -219,15 +218,13 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
changeType (type) {
|
||||
this.date = null
|
||||
this.type = type || 'normal'
|
||||
this.$emit('input', { type: type || 'normal', date: undefined })
|
||||
},
|
||||
selectFrequency (f) {
|
||||
this.recurrent.frequency = f
|
||||
this.type = 'recurrent'
|
||||
this.$emit('input', { recurrent: { frequency: f }, date: null, type: 'recurrent' })
|
||||
},
|
||||
pick (value) {
|
||||
if (this.type === 'normal' || this.type === 'recurrent' || this.date.length === 2) {
|
||||
if (this.value.type === 'normal' || this.value.type === 'recurrent' || this.value.date.length === 2) {
|
||||
this.datePickerMenu = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,10 +99,11 @@ export default {
|
||||
data.event.place.address = event.place.address || ''
|
||||
data.date = {}
|
||||
if (event.multidate) {
|
||||
const start = dayjs.unix(event.start_datetime).format('YYYY-MM-DD')
|
||||
const end = dayjs.unix(event.end_datetime).format('YYYY-MM-DD')
|
||||
data.date = {
|
||||
type: 'multidate',
|
||||
start: dayjs.unix(event.start_datetime).toDate(),
|
||||
end: dayjs.unix(event.end_datetime).toDate()
|
||||
date: [start, end]
|
||||
}
|
||||
} else if (event.recurrent) {
|
||||
data.date.type = 'recurrent'
|
||||
@@ -150,10 +151,10 @@ export default {
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState(['tags', 'places', 'events', 'settings'])
|
||||
...mapState(['tags', 'places', 'settings'])
|
||||
},
|
||||
methods: {
|
||||
...mapActions(['addEvent', 'updateEvent', 'updateMeta', 'updateEvents']),
|
||||
...mapActions(['updateMeta']),
|
||||
eventImported (event) {
|
||||
this.event = Object.assign(this.event, event)
|
||||
},
|
||||
@@ -179,6 +180,7 @@ export default {
|
||||
const formData = new FormData()
|
||||
|
||||
if (this.date.type === 'multidate') {
|
||||
console.error('sono in multidate!')
|
||||
start_datetime = dayjs(this.date.date[0])
|
||||
.set('hour', start_hour).set('minute', start_minute)
|
||||
end_datetime = dayjs(this.date.date[1])
|
||||
@@ -210,7 +212,7 @@ export default {
|
||||
formData.append('place_name', this.event.place.name)
|
||||
formData.append('place_address', this.event.place.address)
|
||||
formData.append('description', this.event.description)
|
||||
formData.append('multidate', this.event.type === 'multidate')
|
||||
formData.append('multidate', this.date.type === 'multidate')
|
||||
formData.append('start_datetime', start_datetime.unix())
|
||||
formData.append('end_datetime', end_datetime.unix())
|
||||
|
||||
@@ -220,9 +222,9 @@ export default {
|
||||
if (this.event.tags) { this.event.tags.forEach(tag => formData.append('tags[]', tag.tag || tag)) }
|
||||
try {
|
||||
if (this.edit) {
|
||||
await this.updateEvent(formData)
|
||||
await this.$axios.$put('/event', formData)
|
||||
} else {
|
||||
await this.addEvent(formData)
|
||||
await this.$axios.$post('/event', formData)
|
||||
}
|
||||
this.updateMeta()
|
||||
this.$router.replace('/')
|
||||
|
||||
Reference in New Issue
Block a user