2019-07-30 10:35:29 +02:00
|
|
|
<template>
|
2020-09-25 16:23:53 +02:00
|
|
|
<div class="address-autocomplete">
|
|
|
|
<b-field expanded>
|
|
|
|
<b-autocomplete
|
|
|
|
:data="addressData"
|
|
|
|
v-model="queryText"
|
|
|
|
:placeholder="$t('e.g. 10 Rue Jangot')"
|
|
|
|
field="fullName"
|
|
|
|
:loading="isFetching"
|
|
|
|
@typing="fetchAsyncData"
|
|
|
|
icon="map-marker"
|
|
|
|
expanded
|
|
|
|
@select="updateSelected"
|
2021-09-07 17:40:31 +02:00
|
|
|
v-bind="$attrs"
|
2020-09-25 16:23:53 +02:00
|
|
|
>
|
2021-04-16 18:13:17 +02:00
|
|
|
<template #default="{ option }">
|
2020-09-25 16:23:53 +02:00
|
|
|
<b-icon :icon="option.poiInfos.poiIcon.icon" />
|
|
|
|
<b>{{ option.poiInfos.name }}</b
|
|
|
|
><br />
|
|
|
|
<small>{{ option.poiInfos.alternativeName }}</small>
|
|
|
|
</template>
|
|
|
|
</b-autocomplete>
|
|
|
|
</b-field>
|
2021-09-07 17:40:31 +02:00
|
|
|
<b-field
|
|
|
|
v-if="canDoGeoLocation"
|
|
|
|
:message="fieldErrors"
|
|
|
|
:type="{ 'is-danger': fieldErrors.length }"
|
|
|
|
>
|
2020-11-30 10:24:11 +01:00
|
|
|
<b-button
|
|
|
|
type="is-text"
|
|
|
|
v-if="!gettingLocation"
|
|
|
|
icon-right="target"
|
|
|
|
@click="locateMe"
|
|
|
|
>{{ $t("Use my location") }}</b-button
|
|
|
|
>
|
2020-09-25 16:23:53 +02:00
|
|
|
<span v-else>{{ $t("Getting location") }}</span>
|
|
|
|
</b-field>
|
|
|
|
<!--
|
|
|
|
<div v-if="selected && selected.geom" class="control">
|
|
|
|
<b-checkbox @input="togglemap" />
|
|
|
|
<label class="label">{{ $t("Show map") }}</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="map" v-if="showmap && selected && selected.geom">
|
|
|
|
<map-leaflet
|
|
|
|
:coords="selected.geom"
|
|
|
|
:marker="{
|
|
|
|
text: [selected.poiInfos.name, selected.poiInfos.alternativeName],
|
|
|
|
icon: selected.poiInfos.poiIcon.icon,
|
|
|
|
}"
|
|
|
|
:updateDraggableMarkerCallback="reverseGeoCode"
|
|
|
|
:options="{ zoom: mapDefaultZoom }"
|
|
|
|
:readOnly="false"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
-->
|
|
|
|
</div>
|
2019-07-30 10:35:29 +02:00
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
2021-09-07 17:40:31 +02:00
|
|
|
import { Component, Mixins, Prop, Watch } from "vue-property-decorator";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Address, IAddress } from "../../types/address.model";
|
2021-09-07 17:40:31 +02:00
|
|
|
import AddressAutoCompleteMixin from "@/mixins/AddressAutoCompleteMixin";
|
2019-11-08 19:37:14 +01:00
|
|
|
|
2019-08-22 15:57:44 +02:00
|
|
|
@Component({
|
2021-09-07 17:40:31 +02:00
|
|
|
inheritAttrs: false,
|
2019-08-22 15:57:44 +02:00
|
|
|
})
|
2021-09-07 17:40:31 +02:00
|
|
|
export default class AddressAutoComplete extends Mixins(
|
|
|
|
AddressAutoCompleteMixin
|
|
|
|
) {
|
2021-02-12 18:19:49 +01:00
|
|
|
@Prop({ required: false, default: false }) type!: string | false;
|
2021-03-02 10:02:06 +01:00
|
|
|
@Prop({ required: false, default: true, type: Boolean })
|
|
|
|
doGeoLocation!: boolean;
|
2020-08-31 12:40:30 +02:00
|
|
|
|
2019-11-20 13:49:57 +01:00
|
|
|
addressData: IAddress[] = [];
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-11-20 13:49:57 +01:00
|
|
|
selected: IAddress = new Address();
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2021-03-05 17:19:42 +01:00
|
|
|
initialQueryText = "";
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-09-25 16:23:53 +02:00
|
|
|
addressModalActive = false;
|
|
|
|
|
|
|
|
showmap = false;
|
|
|
|
|
2021-09-07 17:40:31 +02:00
|
|
|
get queryText2(): string {
|
2021-04-16 17:18:41 +02:00
|
|
|
if (this.value !== undefined) {
|
2021-03-05 17:19:42 +01:00
|
|
|
return new Address(this.value).fullName;
|
|
|
|
}
|
|
|
|
return this.initialQueryText;
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:40:31 +02:00
|
|
|
set queryText2(queryText: string) {
|
2021-03-05 17:19:42 +01:00
|
|
|
this.initialQueryText = queryText;
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@Watch("value")
|
2020-09-25 16:23:53 +02:00
|
|
|
updateEditing(): void {
|
2021-02-12 18:19:49 +01:00
|
|
|
if (!this.value?.id) return;
|
2019-11-20 13:49:57 +01:00
|
|
|
this.selected = this.value;
|
|
|
|
}
|
|
|
|
|
2020-09-25 16:23:53 +02:00
|
|
|
updateSelected(option: IAddress): void {
|
2019-11-08 19:37:14 +01:00
|
|
|
if (option == null) return;
|
|
|
|
this.selected = option;
|
2020-02-18 08:57:00 +01:00
|
|
|
this.$emit("input", this.selected);
|
2019-07-30 10:35:29 +02:00
|
|
|
}
|
2020-09-25 16:23:53 +02:00
|
|
|
|
|
|
|
resetPopup(): void {
|
|
|
|
this.selected = new Address();
|
|
|
|
}
|
|
|
|
|
|
|
|
openNewAddressModal(): void {
|
|
|
|
this.resetPopup();
|
|
|
|
this.addressModalActive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
togglemap(): void {
|
|
|
|
this.showmap = !this.showmap;
|
|
|
|
}
|
|
|
|
|
2021-03-02 10:02:06 +01:00
|
|
|
get canDoGeoLocation(): boolean {
|
|
|
|
return this.isSecureContext && this.doGeoLocation;
|
|
|
|
}
|
2019-07-30 10:35:29 +02:00
|
|
|
}
|
|
|
|
</script>
|
2019-08-22 15:57:44 +02:00
|
|
|
<style lang="scss">
|
2020-02-18 08:57:00 +01:00
|
|
|
.address-autocomplete {
|
|
|
|
margin-bottom: 0.75rem;
|
|
|
|
}
|
2019-12-20 13:04:34 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.autocomplete {
|
|
|
|
.dropdown-menu {
|
|
|
|
z-index: 2000;
|
|
|
|
}
|
2019-11-08 19:37:14 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.dropdown-item.is-disabled {
|
|
|
|
opacity: 1 !important;
|
|
|
|
cursor: auto;
|
|
|
|
}
|
|
|
|
}
|
2019-11-08 19:37:14 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.read-only {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2019-11-08 19:37:14 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.map {
|
|
|
|
height: 400px;
|
|
|
|
width: 100%;
|
|
|
|
}
|
2019-08-22 15:57:44 +02:00
|
|
|
</style>
|