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

View File

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

View File

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

View File

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