AddAddress: adding a forceRedirect option

This commit is contained in:
Mathieu Jaumotte 2021-09-17 15:55:10 +02:00
parent 3f3b7af42b
commit 4855ec2065
4 changed files with 64 additions and 43 deletions

View File

@ -42,8 +42,24 @@ export default {
},
submitAddress(payload) {
console.log('@@@ click on Submit Address Button', payload);
this.addDateToAddressAndPostAddressTo(payload); // !!
// Existing address
if (this.context.edit) {
// address is already linked, just finish !
if (this.options.forceRedirect === true) {
window.location.assign(this.context.backUrl);
}
// New created address
} else {
this.postAddressTo(payload);
}
},
/*
* Patch date
* TO MOVE in DatePane
addDateToAddressAndPostAddressTo(payload) {
payload.body = {
validFrom: {
@ -65,48 +81,48 @@ export default {
this.$refs.addAddress.flag.loading = false;
});
},
*/
/*
* Post new created address to targetEntity
*/
postAddressTo(payload) {
console.log('postAddressTo', payload.entity);
if (!this.context.edit) { // !!
switch (payload.entity) {
case 'household':
postAddressToHousehold(payload.entityId, payload.addressId)
.then(household => new Promise((resolve, reject) => {
console.log('..toHousehold', household);
this.$refs.addAddress.flag.loading = false;
this.$refs.addAddress.flag.success = true;
window.location.assign(this.context.backUrl);
resolve();
}))
.catch((error) => {
this.$refs.addAddress.errorMsg.push(error);
this.$refs.addAddress.flag.loading = false;
})
;
break;
case 'person':
postAddressToPerson(payload.entityId, payload.addressId)
.then(person => new Promise((resolve, reject) => {
console.log('..toPerson', person);
this.$refs.addAddress.flag.loading = false;
this.$refs.addAddress.flag.success = true;
window.location.assign(this.context.backUrl);
resolve();
}))
.catch((error) => {
this.$refs.addAddress.errorMsg.push(error);
this.$refs.addAddress.flag.loading = false;
})
;
break;
default:
this.$refs.addAddress.errorMsg.push('That entity is not managed by address !');
}
} else {
// address is already linked, just finish !
//window.location.assign(this.context.backUrl);
switch (payload.entity) {
case 'household':
postAddressToHousehold(payload.entityId, payload.addressId)
.then(household => new Promise((resolve, reject) => {
console.log('..toHousehold', household);
this.$refs.addAddress.flag.loading = false;
this.$refs.addAddress.flag.success = true;
window.location.assign(this.context.backUrl);
resolve();
}))
.catch((error) => {
this.$refs.addAddress.errorMsg.push(error);
this.$refs.addAddress.flag.loading = false;
})
;
break;
case 'person':
postAddressToPerson(payload.entityId, payload.addressId)
.then(person => new Promise((resolve, reject) => {
console.log('..toPerson', person);
this.$refs.addAddress.flag.loading = false;
this.$refs.addAddress.flag.success = true;
window.location.assign(this.context.backUrl);
resolve();
}))
.catch((error) => {
this.$refs.addAddress.errorMsg.push(error);
this.$refs.addAddress.flag.loading = false;
})
;
break;
default:
this.$refs.addAddress.errorMsg.push('That entity is not managed by address !');
}
},
}
}
}
</script>

View File

@ -304,11 +304,9 @@ export default {
console.log('getInitialAddress');
this.getInitialAddress(this.context.addressId);
}
if (this.bypassFirstStep) {
this.closeShowPane();
this.openEditPane();
} else {
this.flag.showPane = true;
console.log('step0: open the Show Panel');

View File

@ -46,7 +46,9 @@ containers.forEach((container) => {
useDate: {
validFrom: container.dataset.useValidFrom === 'true', //boolean, default: false
validTo: container.dataset.useValidTo === 'true' //boolean, default: false
}
},
/// Force redirection after last step (cfr. backUrl)
forceRedirect: container.dataset.forceRedirect === 'true' //boolean, default: false
}
}
}

View File

@ -18,6 +18,7 @@
* stickyActions bool (default: false)
* useValidFrom bool (default: false)
* useValidTo bool (default: false)
* forceRedirect bool (default: false)
#}
<div class="address-container"
@ -67,6 +68,10 @@
{% if useValidTo is defined and useValidTo == 1 %}
data-use-valid-to="true"
{% endif %}
{% if forceRedirect is defined and forceRedirect == 1 %}
data-force-redirect="true"
{% endif %}
></div>
{{ encore_entry_script_tags('vue_address') }}