parent callback will cast afterLastPaneAction, that manage redirection or context changes

This commit is contained in:
Mathieu Jaumotte 2021-09-20 12:24:28 +02:00
parent 717cd03d95
commit 75a240a2d6
4 changed files with 21 additions and 16 deletions

View File

@ -32,7 +32,7 @@ export default {
}, },
mounted() { mounted() {
console.log('AddAddress: data context', this.context); console.log('AddAddress: data context', this.context);
//console.log('AddAddress: data options', this.options); console.log('AddAddress: data options', this.options);
}, },
methods: { methods: {
displayErrors() { displayErrors() {
@ -45,7 +45,7 @@ export default {
if (this.context.edit) { if (this.context.edit) {
// address is already linked, just finish ! // address is already linked, just finish !
this.$refs.addAddress.lastPaneAction(); this.$refs.addAddress.afterLastPaneAction({});
// New created address // New created address
} else { } else {
@ -93,7 +93,7 @@ export default {
this.$refs.addAddress.flag.success = true; this.$refs.addAddress.flag.success = true;
// finish // finish
this.$refs.addAddress.lastPaneAction(); this.$refs.addAddress.afterLastPaneAction({ addressId: address.address_id });
resolve(); resolve();
})) }))
@ -111,7 +111,7 @@ export default {
this.$refs.addAddress.flag.success = true; this.$refs.addAddress.flag.success = true;
// finish // finish
this.$refs.addAddress.lastPaneAction(); this.$refs.addAddress.afterLastPaneAction({ addressId: address.address_id });
resolve(); resolve();
})) }))

View File

@ -384,7 +384,9 @@ export default {
if (!this.context.edit && this.useDatePane) { if (!this.context.edit && this.useDatePane) {
this.openDatePane(); this.openDatePane();
} else { } else {
this.openShowPane() if (!this.options.forceRedirect) {
this.openShowPane();
}
} }
}, },
openDatePane() { openDatePane() {
@ -402,13 +404,18 @@ export default {
this.flag.datePane = false; this.flag.datePane = false;
this.openShowPane(); this.openShowPane();
}, },
lastPaneAction() { afterLastPaneAction(params) {
this.initForm();
// redirect or reset pane
if (this.options.forceRedirect === true) { if (this.options.forceRedirect === true) {
console.log("redirect to backUrl"); console.log("redirect to backUrl");
window.location.assign(this.context.backUrl); window.location.assign(this.context.backUrl);
} else { } else {
console.log("don't redirect"); console.log("don't redirect, adapt context");
this.resetPane(); this.resetPane();
// change to edit context
this.context.edit = true;
this.context.addressId = params.addressId;
} }
}, },
@ -546,14 +553,14 @@ export default {
if (!this.context.edit) { if (!this.context.edit) {
this.addNewAddress(newAddress) this.addNewAddress(newAddress)
.then(payload => this.closePaneAndCallbackSubmit(payload)); .then(payload => this.addressChangedCallback(payload));
} else { } else {
this.updateAddress({ this.updateAddress({
addressId: this.context.addressId, addressId: this.context.addressId,
newAddress: newAddress newAddress: newAddress
}) })
.then(payload => this.closePaneAndCallbackSubmit(payload)); .then(payload => this.addressChangedCallback(payload));
} }
}, },
@ -655,18 +662,15 @@ export default {
/* /*
* 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)
*/
closePaneAndCallbackSubmit(payload) closePaneAndCallbackSubmit(payload)
{ {
//this.initForm();
this.initForm(); //this.resetPane(); // because parent callback will cast afterLastPaneAction()
this.resetPane();
console.log('will call parent callback method', payload); console.log('will call parent callback method', payload);
// callback props method from parent // callback props method from parent
this.addressChangedCallback(payload); this.addressChangedCallback(payload);
} }
*/
} }
} }
</script> </script>

View File

@ -10,6 +10,7 @@
{% include '@ChillMain/Address/_insert_vue_address.html.twig' with { {% include '@ChillMain/Address/_insert_vue_address.html.twig' with {
targetEntity: { name: 'household', id: household.id }, targetEntity: { name: 'household', id: household.id },
backUrl: path('chill_person_household_addresses', { 'household_id': household.id }), backUrl: path('chill_person_household_addresses', { 'household_id': household.id }),
forceRedirect: true,
stickyActions: true, stickyActions: true,
} %} } %}
{# {#

View File

@ -18,12 +18,12 @@
{% include '@ChillMain/Address/_insert_vue_address.html.twig' with { {% include '@ChillMain/Address/_insert_vue_address.html.twig' with {
targetEntity: { name: 'household', id: household.id }, targetEntity: { name: 'household', id: household.id },
backUrl: path('chill_person_household_addresses', { 'household_id': household.id }), backUrl: path('chill_person_household_addresses', { 'household_id': household.id }),
forceRedirect: true,
mode: 'new', mode: 'new',
useValidFrom: true, useValidFrom: true,
buttonSize: 'btn-lg', buttonSize: 'btn-lg',
buttonText: 'Move household', buttonText: 'Move household',
modalTitle: 'Move household', modalTitle: 'Move household',
forceRedirect: true,
} %} } %}
{# {#
#} #}