mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
handle suggestion in addAddress component
This commit is contained in:
parent
315253589e
commit
f4999548ac
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* Endpoint chill_api_single_country__index
|
||||
* method GET, get Country Object
|
||||
* @returns {Promise} a promise containing all Country object
|
||||
@ -14,7 +14,7 @@ const fetchCountries = () => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Endpoint chill_api_single_postal_code__index
|
||||
* method GET, get Country Object
|
||||
* @returns {Promise} a promise containing all Postal Code objects filtered with country
|
||||
@ -29,7 +29,7 @@ const fetchCities = (country) => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Endpoint chill_api_single_address_reference__index
|
||||
* method GET, get AddressReference Object
|
||||
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
|
||||
@ -44,7 +44,7 @@ const fetchReferenceAddresses = (postalCode) => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Endpoint chill_api_single_address_reference__index
|
||||
* method GET, get AddressReference Object
|
||||
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
|
||||
@ -60,7 +60,7 @@ const fetchAddresses = () => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
/**
|
||||
* Endpoint chill_api_single_address__entity__create
|
||||
* method POST, post Address Object
|
||||
* @returns {Promise}
|
||||
@ -81,8 +81,28 @@ const postAddress = (address) => {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param address
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
const duplicateAddress = (address) => {
|
||||
const url = `/api/1.0/main/address/${address.address_id}/duplicate.json`;
|
||||
return fetch(url, {
|
||||
'method': 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
/**
|
||||
* Endpoint chill_api_single_address__entity__create
|
||||
* method PATCH, patch Address Instance
|
||||
*
|
||||
@ -142,6 +162,7 @@ const getAddress = (id) => {
|
||||
};
|
||||
|
||||
export {
|
||||
duplicateAddress,
|
||||
fetchCountries,
|
||||
fetchCities,
|
||||
fetchReferenceAddresses,
|
||||
|
@ -34,6 +34,7 @@
|
||||
v-bind:defaultz="this.defaultz"
|
||||
v-bind:entity="this.entity"
|
||||
v-bind:flag="this.flag"
|
||||
@pick-address="this.pickAddress"
|
||||
ref="suggestAddress">
|
||||
</suggest-pane>
|
||||
</template>
|
||||
@ -55,6 +56,7 @@
|
||||
v-bind:entity="this.entity"
|
||||
v-bind:flag="this.flag"
|
||||
v-bind:insideModal="false"
|
||||
@pick-address="this.pickAddress"
|
||||
ref="suggestAddress">
|
||||
|
||||
<template v-slot:before v-if="!bypassFirstStep">
|
||||
@ -217,7 +219,16 @@
|
||||
|
||||
<script>
|
||||
import Modal from 'ChillMainAssets/vuejs/_components/Modal';
|
||||
import { getAddress, fetchCountries, fetchCities, fetchReferenceAddresses, patchAddress, postAddress, postPostalCode } from '../api';
|
||||
import {
|
||||
duplicateAddress,
|
||||
fetchCountries,
|
||||
fetchCities,
|
||||
fetchReferenceAddresses,
|
||||
getAddress,
|
||||
patchAddress,
|
||||
postAddress,
|
||||
postPostalCode,
|
||||
} from '../api';
|
||||
import { postAddressToPerson, postAddressToHousehold } from "ChillPersonAssets/vuejs/_api/AddAddress.js";
|
||||
import ShowPane from './ShowPane.vue';
|
||||
import SuggestPane from './SuggestPane.vue';
|
||||
@ -234,6 +245,9 @@ export default {
|
||||
EditPane,
|
||||
DatePane
|
||||
},
|
||||
emits: {
|
||||
pickAddress: null
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
flag: {
|
||||
@ -311,7 +325,10 @@ export default {
|
||||
return (this.validFrom || this.validTo) ? true : false;
|
||||
},
|
||||
hasSuggestions() {
|
||||
// TODO
|
||||
console.log(this.context.suggestions);
|
||||
if (typeof(this.context.suggestions) !== 'undefined') {
|
||||
return this.context.suggestions.length > 0;
|
||||
}
|
||||
//return addressSuggestions.length > 0
|
||||
return false;
|
||||
},
|
||||
@ -647,9 +664,12 @@ export default {
|
||||
this.flag.loading = false;
|
||||
this.flag.success = true;
|
||||
resolve({
|
||||
address,
|
||||
targetOrigin: this.context.target,
|
||||
// for "legacy" use:
|
||||
target: this.context.target.name,
|
||||
targetId: this.context.target.id,
|
||||
addressId: this.entity.address.address_id
|
||||
addressId: this.entity.address.address_id,
|
||||
}
|
||||
);
|
||||
}))
|
||||
@ -695,6 +715,9 @@ export default {
|
||||
this.flag.loading = false;
|
||||
this.flag.success = true;
|
||||
return resolve({
|
||||
address,
|
||||
targetOrigin: this.context.target,
|
||||
// for "legacy" use:
|
||||
target: this.context.target.name,
|
||||
targetId: this.context.target.id,
|
||||
addressId: this.entity.address.address_id
|
||||
@ -707,6 +730,29 @@ export default {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param address the address selected
|
||||
*/
|
||||
pickAddress(address) {
|
||||
console.log('pickAddress', address);
|
||||
duplicateAddress(address).then(newAddress => {
|
||||
this.entity.address = newAddress;
|
||||
this.flag.loading = false;
|
||||
this.flag.success = true;
|
||||
let payload = {
|
||||
address: newAddress,
|
||||
targetOrigin: this.context.target,
|
||||
// for "legacy" use:
|
||||
target: this.context.target.name,
|
||||
targetId: this.context.target.id,
|
||||
addressId: this.entity.address.address_id
|
||||
};
|
||||
this.addressChangedCallback(payload);
|
||||
this.closeSuggestPane();
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Method just add closing pane to the callback method
|
||||
* (get out step1 show pane, submit button)
|
||||
|
@ -10,13 +10,14 @@
|
||||
<h4 class="h3">{{ $t('address_suggestions') }}</h4>
|
||||
|
||||
<div class="flex-table AddressSuggestionList">
|
||||
<div class="item-bloc">
|
||||
<div v-for="a in context.suggestions" class="item-bloc">
|
||||
<div class="float-button bottom">
|
||||
<div class="box">
|
||||
<div class="action">
|
||||
<!-- QUESTION normal que ça vienne avant l'adresse ? pourquoi pas après avoir affiché le address-render-box ? -->
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<button class="btn btn-sm btn-choose">
|
||||
<button class="btn btn-sm btn-choose" @click="this.pickAddress(a)">
|
||||
{{ $t('use_this_address') }}
|
||||
</button>
|
||||
</li>
|
||||
@ -25,9 +26,7 @@
|
||||
<ul class="list-content fa-ul">
|
||||
<li>
|
||||
<i class="fa fa-li fa-map-marker"></i>
|
||||
<!--
|
||||
<address-render-box></address-render-box>
|
||||
-->
|
||||
<address-render-box :address="a"></address-render-box>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -68,9 +67,14 @@ export default {
|
||||
'flag',
|
||||
'entity',
|
||||
'errorMsg',
|
||||
'insideModal'
|
||||
'insideModal',
|
||||
],
|
||||
computed: {},
|
||||
methods: {}
|
||||
methods: {
|
||||
pickAddress(address) {
|
||||
console.log('pickAddress in suggest pane', address);
|
||||
this.$emit('pickAddress', address);
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -94,7 +94,7 @@
|
||||
</template>
|
||||
<template v-else>
|
||||
<household-render-box :household="household" :isAddressMultiline="true"></household-render-box>
|
||||
<ul v-if="!hasHouseholhdAddress" class="record_actions">
|
||||
<ul v-if="!hasHouseholdAddress" class="record_actions">
|
||||
<li>
|
||||
<add-address
|
||||
:context="getAddressContext"
|
||||
@ -151,6 +151,7 @@ export default {
|
||||
validFrom: false,
|
||||
validTo: false,
|
||||
},
|
||||
hideAddress: true,
|
||||
button: {
|
||||
text: {
|
||||
create: 'household_members_editor.household.set_address',
|
||||
|
@ -96,6 +96,12 @@ const store = createStore({
|
||||
getAddressContext(state) {
|
||||
return {
|
||||
edit: false,
|
||||
addressId: null,
|
||||
target: {
|
||||
name: state.household.type,
|
||||
id: state.household.id
|
||||
},
|
||||
suggestions: state.addressesSuggestion
|
||||
};
|
||||
},
|
||||
hasHouseholdAddress(state) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user