mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
addresses: enable POSTing Postal Code entities (back + front)
This commit is contained in:
@@ -49,7 +49,19 @@ export default {
|
||||
};
|
||||
|
||||
if (address.selected.address.point !== undefined){
|
||||
newAddress = Object.assign(newAddress, {'point': address.selected.address.point.coordinates});
|
||||
createdAddress = Object.assign(createdAddress, {
|
||||
'point': address.selected.address.point.coordinates
|
||||
});
|
||||
}
|
||||
|
||||
if(address.writeNewPostalCode){
|
||||
let newPostalCode = address.newPostalCode;
|
||||
newPostalCode = Object.assign(newPostalCode, {
|
||||
'country': {'id': address.selected.country.id },
|
||||
});
|
||||
createdAddress = Object.assign(createdAddress, {
|
||||
'newPostalCode': newPostalCode
|
||||
});
|
||||
}
|
||||
|
||||
this.$store.dispatch('addAddress', newAddress);
|
||||
|
@@ -16,7 +16,10 @@ const addressMessages = {
|
||||
flat: 'Appartement',
|
||||
buildingName: 'Nom du batiment',
|
||||
extra: 'Complément d\'adresse',
|
||||
distribution: 'Service particulier de distribution'
|
||||
distribution: 'Service particulier de distribution',
|
||||
create_postal_code: 'Localité inconnue. Cliquez ici pour créer une nouvelle localité',
|
||||
postalCode_name: 'Nom de la localité',
|
||||
postalCode_code: 'Code postal de la localité'
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import 'es6-promise/auto';
|
||||
import { createStore } from 'vuex';
|
||||
|
||||
import { postAddress } from '../../_api/AddAddress'
|
||||
import { postAddress, postPostalCode } from '../../_api/AddAddress'
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
@@ -25,19 +25,32 @@ const store = createStore({
|
||||
actions: {
|
||||
addAddress({ commit }, payload) {
|
||||
console.log('@A addAddress payload', payload);
|
||||
//commit('addAddress', payload); // à remplacer par la suite
|
||||
|
||||
//fetch POST qui envoie l'adresse, et récupère la confirmation que c'est ok.
|
||||
//La confirmation est l'adresse elle-même.
|
||||
if('newPostalCode' in payload){
|
||||
postPostalCode(payload.newPostalCode)
|
||||
.then(postalCode => {
|
||||
let body = payload;
|
||||
body.postcode = {'id': postalCode.id },
|
||||
postAddress(body)
|
||||
.then(address => new Promise((resolve, reject) => {
|
||||
commit('addAddress', address);
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
commit('catchError', error);
|
||||
});
|
||||
})
|
||||
|
||||
postAddress(payload)
|
||||
.then(address => new Promise((resolve, reject) => {
|
||||
commit('addAddress', address);
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
commit('catchError', error);
|
||||
});
|
||||
} else {
|
||||
postAddress(payload)
|
||||
.then(address => new Promise((resolve, reject) => {
|
||||
commit('addAddress', address);
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
commit('catchError', error);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@@ -66,7 +66,6 @@ const fetchAddresses = () => {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
const postAddress = (address) => {
|
||||
console.log(address);
|
||||
const url = `/api/1.0/main/address.json?`;
|
||||
const body = address;
|
||||
|
||||
@@ -91,7 +90,6 @@ const postAddress = (address) => {
|
||||
* @body Object - dictionary with changes to post
|
||||
*/
|
||||
const patchAddress = (id, body) => {
|
||||
|
||||
const url = `/api/1.0/main/address/${id}.json`;
|
||||
return fetch(url, {
|
||||
method: 'PATCH',
|
||||
@@ -106,7 +104,26 @@ const patchAddress = (id, body) => {
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Endpoint chill_api_single_postal_code__entity_create
|
||||
* method POST, post Postal Code Object
|
||||
* @returns {Promise}
|
||||
*/
|
||||
const postPostalCode = (postalCode) => {
|
||||
const url = `/api/1.0/main/postal-code.json?`;
|
||||
const body = postalCode;
|
||||
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
}).then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
||||
|
||||
export {
|
||||
fetchCountries,
|
||||
@@ -114,5 +131,6 @@ export {
|
||||
fetchReferenceAddresses,
|
||||
fetchAddresses,
|
||||
postAddress,
|
||||
patchAddress
|
||||
patchAddress,
|
||||
postPostalCode
|
||||
};
|
||||
|
@@ -106,6 +106,7 @@ export default {
|
||||
},
|
||||
address: {
|
||||
writeNewAddress: false,
|
||||
writeNewPostalCode: false,
|
||||
loaded: {
|
||||
countries: [],
|
||||
cities: [],
|
||||
@@ -116,6 +117,10 @@ export default {
|
||||
city: {},
|
||||
address: {},
|
||||
},
|
||||
newPostalCode: {
|
||||
code: null,
|
||||
name: null
|
||||
},
|
||||
addressMap: {
|
||||
center : [48.8589, 2.3469], // Note: LeafletJs demands [lat, lon] cfr https://macwright.com/lonlat/
|
||||
zoom: 12
|
||||
@@ -211,6 +216,8 @@ export default {
|
||||
this.address.distribution = null;
|
||||
this.address.extra = null;
|
||||
this.address.writeNewAddress = false;
|
||||
this.address.writeNewPostalCode = false;
|
||||
this.address.newPostalCode = {};
|
||||
console.log('cities and addresses', this.address.loaded.cities, this.address.loaded.addresses);
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@
|
||||
:options="addresses">
|
||||
</VueMultiselect>
|
||||
</div>
|
||||
<div v-if="writeNewAddress">
|
||||
<div v-if="writeNewAddress || writeNewPostalCode">
|
||||
<input
|
||||
type="text"
|
||||
name="street"
|
||||
@@ -45,6 +45,9 @@ export default {
|
||||
writeNewAddress() {
|
||||
return this.address.writeNewAddress;
|
||||
},
|
||||
writeNewPostalCode() {
|
||||
return this.address.writeNewPostalCode;
|
||||
},
|
||||
addresses() {
|
||||
return this.address.loaded.addresses;
|
||||
},
|
||||
|
@@ -8,9 +8,25 @@
|
||||
label="value"
|
||||
:custom-label="transName"
|
||||
:placeholder="$t('select_city')"
|
||||
:taggable="true"
|
||||
:multiple="false"
|
||||
@tag="addPostalCode"
|
||||
:tagPlaceholder="$t('create_postal_code')"
|
||||
:options="cities">
|
||||
</VueMultiselect>
|
||||
</div>
|
||||
<div v-if="writeNewPostalCode">
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
:placeholder="$t('postalCode_name')"
|
||||
v-model="name"/>
|
||||
<input
|
||||
type="text"
|
||||
name="code"
|
||||
:placeholder="$t('postalCode_code')"
|
||||
v-model="code"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@@ -25,6 +41,30 @@ export default {
|
||||
value: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
writeNewPostalCode() {
|
||||
return this.address.writeNewPostalCode;
|
||||
},
|
||||
cities() {
|
||||
return this.address.loaded.cities;
|
||||
},
|
||||
name: {
|
||||
set(value) {
|
||||
this.address.newPostalCode.name = value;
|
||||
},
|
||||
get() {
|
||||
return this.address.newPostalCode.name;
|
||||
}
|
||||
},
|
||||
code: {
|
||||
set(value) {
|
||||
this.address.newPostalCode.code= value;
|
||||
},
|
||||
get() {
|
||||
return this.address.newPostalCode.code;
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
transName(value) {
|
||||
return `${value.code}-${value.name}`
|
||||
@@ -33,10 +73,8 @@ export default {
|
||||
this.address.selected.city = value;
|
||||
this.getReferenceAddresses(value);
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
cities() {
|
||||
return this.address.loaded.cities;
|
||||
addPostalCode() {
|
||||
this.address.writeNewPostalCode = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -28,7 +28,7 @@ export default {
|
||||
methods: {
|
||||
init() {
|
||||
if (this.value !== undefined) {
|
||||
this.getCities(this.value);
|
||||
this.selectCountry(this.value);
|
||||
}
|
||||
},
|
||||
transName ({ name }) {
|
||||
|
Reference in New Issue
Block a user