2020-10-25 00:31:38 +02:00
|
|
|
<template lang="pug">
|
2022-04-27 12:34:58 +02:00
|
|
|
v-row
|
|
|
|
v-col(cols=12 md=6)
|
|
|
|
v-combobox(ref='place'
|
|
|
|
:rules="[$validators.required('common.where')]"
|
|
|
|
:label="$t('common.where')"
|
|
|
|
:hint="$t('event.where_description')"
|
|
|
|
:search-input.sync="placeName"
|
|
|
|
:prepend-icon='mdiMapMarker'
|
|
|
|
persistent-hint
|
|
|
|
:value="value.name"
|
|
|
|
:items="filteredPlaces"
|
|
|
|
no-filter
|
|
|
|
item-text='name'
|
|
|
|
@change='selectPlace')
|
|
|
|
template(v-slot:item="{ item, attrs, on }")
|
|
|
|
v-list-item(v-bind='attrs' v-on='on')
|
|
|
|
v-list-item-content(two-line v-if='item.create')
|
|
|
|
v-list-item-title <v-icon color='primary' v-text='mdiPlus' :aria-label='$t("common.add")'></v-icon> {{item.name}}
|
|
|
|
v-list-item-content(two-line v-else)
|
|
|
|
v-list-item-title(v-text='item.name')
|
|
|
|
v-list-item-subtitle(v-text='item.address')
|
2020-10-25 00:31:38 +02:00
|
|
|
|
2022-04-27 12:34:58 +02:00
|
|
|
v-col(cols=12 md=6)
|
|
|
|
v-text-field(ref='address'
|
|
|
|
:prepend-icon='mdiMap'
|
|
|
|
:disabled='disableAddress'
|
|
|
|
:rules="[ v => disableAddress ? true : $validators.required('common.address')(v)]"
|
|
|
|
:label="$t('common.address')"
|
|
|
|
@change="changeAddress"
|
|
|
|
:value="value.address")
|
2020-10-25 00:31:38 +02:00
|
|
|
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import { mapState } from 'vuex'
|
2022-02-08 14:45:19 +01:00
|
|
|
import { mdiMap, mdiMapMarker, mdiPlus } from '@mdi/js'
|
2020-10-25 00:31:38 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'WhereInput',
|
2020-10-27 11:56:47 +01:00
|
|
|
props: {
|
|
|
|
value: { type: Object, default: () => {} }
|
|
|
|
},
|
2020-10-25 00:31:38 +02:00
|
|
|
data () {
|
|
|
|
return {
|
2022-02-08 14:45:19 +01:00
|
|
|
mdiMap, mdiMapMarker, mdiPlus,
|
2021-01-21 01:11:08 +01:00
|
|
|
place: { },
|
|
|
|
placeName: '',
|
2020-10-25 00:31:38 +02:00
|
|
|
disableAddress: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2021-01-21 01:11:08 +01:00
|
|
|
...mapState(['places']),
|
|
|
|
filteredPlaces () {
|
|
|
|
if (!this.placeName) { return this.places }
|
|
|
|
const placeName = this.placeName.toLowerCase()
|
|
|
|
let nameMatch = false
|
|
|
|
const matches = this.places.filter(p => {
|
|
|
|
const tmpName = p.name.toLowerCase()
|
|
|
|
const tmpAddress = p.address.toLowerCase()
|
|
|
|
if (tmpName.includes(placeName)) {
|
|
|
|
if (tmpName === placeName) { nameMatch = true }
|
|
|
|
return true
|
|
|
|
}
|
2022-04-27 12:34:58 +02:00
|
|
|
return tmpAddress.includes(placeName)
|
2021-01-21 01:11:08 +01:00
|
|
|
})
|
|
|
|
if (!nameMatch) {
|
|
|
|
matches.unshift({ create: true, name: this.placeName })
|
|
|
|
}
|
|
|
|
return matches
|
|
|
|
}
|
2020-10-25 00:31:38 +02:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
selectPlace (p) {
|
2021-01-21 01:11:08 +01:00
|
|
|
if (!p) { return }
|
|
|
|
if (typeof p === 'object' && !p.create) {
|
2020-10-25 00:31:38 +02:00
|
|
|
this.place.name = p.name
|
2020-11-04 10:55:30 +01:00
|
|
|
this.place.address = p.address
|
2020-10-25 00:31:38 +02:00
|
|
|
this.disableAddress = true
|
2020-11-04 10:55:30 +01:00
|
|
|
} else { // this is a new place
|
2021-01-21 01:11:08 +01:00
|
|
|
this.place.name = p.name || p
|
2021-06-07 00:00:31 +02:00
|
|
|
// search for a place with the same name
|
|
|
|
const place = this.places.find(p => p.name === this.place.name)
|
|
|
|
if (place) {
|
|
|
|
this.place.address = place.address
|
|
|
|
this.disableAddress = true
|
|
|
|
} else {
|
|
|
|
this.place.address = ''
|
|
|
|
this.disableAddress = false
|
|
|
|
this.$refs.place.blur()
|
|
|
|
this.$refs.address.focus()
|
|
|
|
}
|
2020-10-25 00:31:38 +02:00
|
|
|
}
|
2020-11-04 10:55:30 +01:00
|
|
|
this.$emit('input', { ...this.place })
|
2020-10-25 00:31:38 +02:00
|
|
|
},
|
|
|
|
changeAddress (v) {
|
|
|
|
this.place.address = v
|
2020-11-04 10:55:30 +01:00
|
|
|
this.$emit('input', { ...this.place })
|
2020-10-25 00:31:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|