mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +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
|
* Endpoint chill_api_single_country__index
|
||||||
* method GET, get Country Object
|
* method GET, get Country Object
|
||||||
* @returns {Promise} a promise containing all Country object
|
* @returns {Promise} a promise containing all Country object
|
||||||
@ -14,7 +14,7 @@ const fetchCountries = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Endpoint chill_api_single_postal_code__index
|
* Endpoint chill_api_single_postal_code__index
|
||||||
* method GET, get Country Object
|
* method GET, get Country Object
|
||||||
* @returns {Promise} a promise containing all Postal Code objects filtered with country
|
* @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
|
* Endpoint chill_api_single_address_reference__index
|
||||||
* method GET, get AddressReference Object
|
* method GET, get AddressReference Object
|
||||||
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
|
* @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
|
* Endpoint chill_api_single_address_reference__index
|
||||||
* method GET, get AddressReference Object
|
* method GET, get AddressReference Object
|
||||||
* @returns {Promise} a promise containing all AddressReference objects filtered with postal code
|
* @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
|
* Endpoint chill_api_single_address__entity__create
|
||||||
* method POST, post Address Object
|
* method POST, post Address Object
|
||||||
* @returns {Promise}
|
* @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
|
* Endpoint chill_api_single_address__entity__create
|
||||||
* method PATCH, patch Address Instance
|
* method PATCH, patch Address Instance
|
||||||
*
|
*
|
||||||
@ -142,6 +162,7 @@ const getAddress = (id) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
duplicateAddress,
|
||||||
fetchCountries,
|
fetchCountries,
|
||||||
fetchCities,
|
fetchCities,
|
||||||
fetchReferenceAddresses,
|
fetchReferenceAddresses,
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
v-bind:defaultz="this.defaultz"
|
v-bind:defaultz="this.defaultz"
|
||||||
v-bind:entity="this.entity"
|
v-bind:entity="this.entity"
|
||||||
v-bind:flag="this.flag"
|
v-bind:flag="this.flag"
|
||||||
|
@pick-address="this.pickAddress"
|
||||||
ref="suggestAddress">
|
ref="suggestAddress">
|
||||||
</suggest-pane>
|
</suggest-pane>
|
||||||
</template>
|
</template>
|
||||||
@ -55,6 +56,7 @@
|
|||||||
v-bind:entity="this.entity"
|
v-bind:entity="this.entity"
|
||||||
v-bind:flag="this.flag"
|
v-bind:flag="this.flag"
|
||||||
v-bind:insideModal="false"
|
v-bind:insideModal="false"
|
||||||
|
@pick-address="this.pickAddress"
|
||||||
ref="suggestAddress">
|
ref="suggestAddress">
|
||||||
|
|
||||||
<template v-slot:before v-if="!bypassFirstStep">
|
<template v-slot:before v-if="!bypassFirstStep">
|
||||||
@ -217,7 +219,16 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Modal from 'ChillMainAssets/vuejs/_components/Modal';
|
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 { postAddressToPerson, postAddressToHousehold } from "ChillPersonAssets/vuejs/_api/AddAddress.js";
|
||||||
import ShowPane from './ShowPane.vue';
|
import ShowPane from './ShowPane.vue';
|
||||||
import SuggestPane from './SuggestPane.vue';
|
import SuggestPane from './SuggestPane.vue';
|
||||||
@ -234,6 +245,9 @@ export default {
|
|||||||
EditPane,
|
EditPane,
|
||||||
DatePane
|
DatePane
|
||||||
},
|
},
|
||||||
|
emits: {
|
||||||
|
pickAddress: null
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
flag: {
|
flag: {
|
||||||
@ -311,7 +325,10 @@ export default {
|
|||||||
return (this.validFrom || this.validTo) ? true : false;
|
return (this.validFrom || this.validTo) ? true : false;
|
||||||
},
|
},
|
||||||
hasSuggestions() {
|
hasSuggestions() {
|
||||||
// TODO
|
console.log(this.context.suggestions);
|
||||||
|
if (typeof(this.context.suggestions) !== 'undefined') {
|
||||||
|
return this.context.suggestions.length > 0;
|
||||||
|
}
|
||||||
//return addressSuggestions.length > 0
|
//return addressSuggestions.length > 0
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
@ -647,9 +664,12 @@ export default {
|
|||||||
this.flag.loading = false;
|
this.flag.loading = false;
|
||||||
this.flag.success = true;
|
this.flag.success = true;
|
||||||
resolve({
|
resolve({
|
||||||
|
address,
|
||||||
|
targetOrigin: this.context.target,
|
||||||
|
// for "legacy" use:
|
||||||
target: this.context.target.name,
|
target: this.context.target.name,
|
||||||
targetId: this.context.target.id,
|
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.loading = false;
|
||||||
this.flag.success = true;
|
this.flag.success = true;
|
||||||
return resolve({
|
return resolve({
|
||||||
|
address,
|
||||||
|
targetOrigin: this.context.target,
|
||||||
|
// for "legacy" use:
|
||||||
target: this.context.target.name,
|
target: this.context.target.name,
|
||||||
targetId: this.context.target.id,
|
targetId: this.context.target.id,
|
||||||
addressId: this.entity.address.address_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
|
* Method just add closing pane to the callback method
|
||||||
* (get out step1 show pane, submit button)
|
* (get out step1 show pane, submit button)
|
||||||
|
@ -10,13 +10,14 @@
|
|||||||
<h4 class="h3">{{ $t('address_suggestions') }}</h4>
|
<h4 class="h3">{{ $t('address_suggestions') }}</h4>
|
||||||
|
|
||||||
<div class="flex-table AddressSuggestionList">
|
<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="float-button bottom">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="action">
|
<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">
|
<ul class="record_actions">
|
||||||
<li>
|
<li>
|
||||||
<button class="btn btn-sm btn-choose">
|
<button class="btn btn-sm btn-choose" @click="this.pickAddress(a)">
|
||||||
{{ $t('use_this_address') }}
|
{{ $t('use_this_address') }}
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
@ -25,9 +26,7 @@
|
|||||||
<ul class="list-content fa-ul">
|
<ul class="list-content fa-ul">
|
||||||
<li>
|
<li>
|
||||||
<i class="fa fa-li fa-map-marker"></i>
|
<i class="fa fa-li fa-map-marker"></i>
|
||||||
<!--
|
<address-render-box :address="a"></address-render-box>
|
||||||
<address-render-box></address-render-box>
|
|
||||||
-->
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -68,9 +67,14 @@ export default {
|
|||||||
'flag',
|
'flag',
|
||||||
'entity',
|
'entity',
|
||||||
'errorMsg',
|
'errorMsg',
|
||||||
'insideModal'
|
'insideModal',
|
||||||
],
|
],
|
||||||
computed: {},
|
computed: {},
|
||||||
methods: {}
|
methods: {
|
||||||
|
pickAddress(address) {
|
||||||
|
console.log('pickAddress in suggest pane', address);
|
||||||
|
this.$emit('pickAddress', address);
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -94,7 +94,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<household-render-box :household="household" :isAddressMultiline="true"></household-render-box>
|
<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>
|
<li>
|
||||||
<add-address
|
<add-address
|
||||||
:context="getAddressContext"
|
:context="getAddressContext"
|
||||||
@ -151,6 +151,7 @@ export default {
|
|||||||
validFrom: false,
|
validFrom: false,
|
||||||
validTo: false,
|
validTo: false,
|
||||||
},
|
},
|
||||||
|
hideAddress: true,
|
||||||
button: {
|
button: {
|
||||||
text: {
|
text: {
|
||||||
create: 'household_members_editor.household.set_address',
|
create: 'household_members_editor.household.set_address',
|
||||||
|
@ -96,6 +96,12 @@ const store = createStore({
|
|||||||
getAddressContext(state) {
|
getAddressContext(state) {
|
||||||
return {
|
return {
|
||||||
edit: false,
|
edit: false,
|
||||||
|
addressId: null,
|
||||||
|
target: {
|
||||||
|
name: state.household.type,
|
||||||
|
id: state.household.id
|
||||||
|
},
|
||||||
|
suggestions: state.addressesSuggestion
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
hasHouseholdAddress(state) {
|
hasHouseholdAddress(state) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user