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