corrections + details

This commit is contained in:
Mathieu Jaumotte 2021-08-07 18:50:10 +02:00
parent 63fbf4b249
commit e178183cef
5 changed files with 71 additions and 57 deletions

View File

@ -28,6 +28,13 @@
</template>
<script>
/*
* Address component is a uniq component for many contexts.
* Allow to create/attach/edit an address to
* - a person (new or edit address),
* - a household (move or edit address)
*
* */
import AddAddress from './components/AddAddress.vue';
export default {

View File

@ -362,8 +362,8 @@ export default {
* apply some transformations before asyncing with backend
* from entity.selected to entity.address
*/
applyChanges() {
applyChanges()
{
let newAddress = {
'isNoAddress': this.entity.selected.isNoAddress,
'street': this.entity.selected.isNoAddress ? '' : this.entity.selected.address.street,
@ -403,6 +403,52 @@ export default {
}
},
/*
* Async POST transactions,
* creating new address, and receive backend datas when promise is resolved
*/
addAddress(payload)
{
this.flag.loading = true;
if ('newPostcode' in payload) {
let postcodeBody = payload.newPostcode;
if (this.context.entity.type === 'person') {
postcodeBody = Object.assign(postcodeBody, {'origin': 3});
}
postPostalCode(postcodeBody)
.then(postalCode => {
let body = payload;
body.postcode = {'id': postalCode.id },
postAddress(body)
.then(address => new Promise((resolve, reject) => {
this.entity.address = address;
this.flag.loading = false;
this.flag.success = true;
resolve();
}))
.catch((error) => {
this.errorMsg.push(error);
this.flag.loading = false;
});
})
} else {
postAddress(payload)
.then(address => new Promise((resolve, reject) => {
this.entity.address = address;
this.flag.loading = false;
this.flag.success = true;
resolve();
}))
.catch((error) => {
this.errorMsg.push(error);
this.flag.loading = false;
});
}
},
/*
* Async PATCH transactions,
* then update existing address with backend datas when promise is resolved
@ -423,6 +469,7 @@ export default {
.then(address => new Promise((resolve, reject) => {
this.entity.address = address;
this.flag.loading = false;
this.flag.success = true;
resolve();
}))
.catch((error) => {
@ -436,6 +483,7 @@ export default {
.then(address => new Promise((resolve, reject) => {
this.entity.address = address;
this.flag.loading = false;
this.flag.success = true;
resolve();
}))
.catch((error) => {
@ -445,47 +493,6 @@ export default {
}
},
/*
* Async POST transactions,
* creating new address, and receive backend datas when promise is resolved
*/
addAddress(payload)
{
this.flag.loading = true;
if('newPostcode' in payload){
let postcodeBody = payload.newPostcode;
postcodeBody = Object.assign(postcodeBody, {'origin': 3});
postPostalCode(postcodeBody)
.then(postalCode => {
let body = payload;
body.postcode = {'id': postalCode.id},
postAddress(body)
.then(address => new Promise((resolve, reject) => {
this.entity.address = address;
resolve();
this.flag.loading = false;
}))
.catch((error) => {
this.errorMsg.push(error);
this.flag.loading = false;
});
})
} else {
postAddress(payload)
.then(address => new Promise((resolve, reject) => {
this.entity.address = address;
resolve();
this.flag.loading = false;
}))
.catch((error) => {
this.errorMsg.push(error);
this.flag.loading = false;
});
}
},
/*
* When submit address (step1 show pane)
*/
@ -528,12 +535,11 @@ export default {
postAddressToPerson(payload.entityId, payload.addressId)
.then(person => new Promise((resolve, reject) => {
console.log('commit addAddressToPerson !!!', person);
console.log('TODO commit addAddressToPerson !!!', person);
//this.$props.result = person;
this.flag.loading = false;
this.flag.success = true;
if (this.options.redirectToBackUrl) {
window.location.assign(payload.backUrl);
}
@ -563,11 +569,10 @@ export default {
postAddressToHousehold(payload.entityId, payload.addressId)
.then(household => new Promise((resolve, reject) => {
console.log('commit addAddressToHousehold', household);
console.log('TODO commit addAddressToHousehold', household);
this.flag.success = true;
this.flag.loading = false;
this.flag.success = true;
if (this.options.redirectToBackUrl) {
window.location.assign(payload.backUrl);
}

View File

@ -68,13 +68,13 @@
aria-describedby="validFrom"
/>
</div>
<!--div v-if="errorMsg.length > 0">
{{ errors }}
</div-->
<div v-if="flag.loading">
{{ $t('loading') }}
</div>
<div v-if="flag.success">
<div v-if="errorMsg.length > 0" class="alert alert-danger">
{{ errors }}
</div>
<div v-if="flag.success" class="alert alert-success">
{{ $t('person_address_creation_success') }}
</div>
</div>

View File

@ -30,7 +30,6 @@
{# include vue_address component #}
{% include '@ChillPerson/Address/_insert_vue_address.html.twig' with {
address_id: person.lastAddress.id,
mode: 'new',
buttonSize: 'btn-lg',
buttonText: 'Add an address',

View File

@ -15,10 +15,13 @@
<li style="margin: auto;">
{# include vue_address component #}
<a class="btn btn-lg btn-create"
href="{{ chill_path_add_return_path('chill_person_household_address_move', { 'household_id': household.id }) }}">
{{ 'Move household'|trans }}
</a>
{% include '@ChillPerson/Address/_insert_vue_address.html.twig' with {
mode: 'new',
backUrl: chill_path_add_return_path('chill_person_household_address_move', { 'household_id': household.id }),
buttonSize: 'btn-lg',
buttonText: 'Move household',
modalTitle: 'Move household',
} %}
</li>
</ul>