mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
submit methods: first promise is shared for person or household context
This commit is contained in:
parent
62dc94bb14
commit
0075fed9a5
@ -358,7 +358,7 @@ export default {
|
||||
},
|
||||
|
||||
/*
|
||||
* When changes are validated (step2 edit pane),
|
||||
* When changes are validated (get out step2 edit pane),
|
||||
* apply some transformations before asyncing with backend
|
||||
* from entity.selected to entity.address
|
||||
*/
|
||||
@ -494,7 +494,7 @@ export default {
|
||||
},
|
||||
|
||||
/*
|
||||
* When submit address (step1 show pane)
|
||||
* When submit address (get out step1 show pane)
|
||||
*/
|
||||
submitAddress()
|
||||
{
|
||||
@ -508,30 +508,59 @@ export default {
|
||||
},
|
||||
backUrl: this.context.backUrl
|
||||
}
|
||||
|
||||
console.log('@@@ CLICK button submitAddress for', this.context.entity.type, 'with payload', payload);
|
||||
this.addDateToAddressAndAddressTo(payload, this.context.entity.type);
|
||||
|
||||
if (this.context.entity.type === 'person') {
|
||||
this.addDateToAddressAndAddressToPerson();
|
||||
|
||||
} else if (this.context.entity.type === 'household') {
|
||||
this.addDateToAddressAndAddressToHousehold();
|
||||
|
||||
} else {
|
||||
this.errorMsg.push('this entity type is not yet allowed');
|
||||
}
|
||||
this.initForm();
|
||||
this.flag.showPane = false;
|
||||
},
|
||||
|
||||
addDateToAddressAndAddressToPerson(payload)
|
||||
addDateToAddressAndAddressTo(payload, postTo)
|
||||
{
|
||||
console.log('addDateToAddressAndAddressTo', postTo)
|
||||
this.flag.loading = true;
|
||||
patchAddress(payload.addressId, payload.body)
|
||||
.then(address => new Promise((resolve, reject) => {
|
||||
this.valid.from = address.validFrom;
|
||||
resolve();
|
||||
this.valid.from = address.validFrom;
|
||||
resolve();
|
||||
})
|
||||
.then(
|
||||
this.postAddressTo(payload, postTo)
|
||||
)
|
||||
)
|
||||
.catch((error) => {
|
||||
this.errorMsg.push(error);
|
||||
this.flag.loading = false;
|
||||
});
|
||||
},
|
||||
|
||||
}).then(
|
||||
postAddressTo(payload, postTo)
|
||||
{
|
||||
console.log('postAddressTo', postTo);
|
||||
switch (postTo) {
|
||||
case 'household':
|
||||
postAddressToHousehold(payload.entityId, payload.addressId)
|
||||
.then(household => new Promise((resolve, reject) => {
|
||||
|
||||
console.log('TODO commit addAddressToHousehold', household);
|
||||
|
||||
this.flag.loading = false;
|
||||
this.flag.success = true;
|
||||
if (this.options.redirectToBackUrl) {
|
||||
window.location.assign(payload.backUrl);
|
||||
}
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
this.errorMsg.push(error);
|
||||
this.flag.loading = false;
|
||||
})
|
||||
;
|
||||
break;
|
||||
|
||||
case 'person':
|
||||
default:
|
||||
postAddressToPerson(payload.entityId, payload.addressId)
|
||||
.then(person => new Promise((resolve, reject) => {
|
||||
|
||||
@ -549,45 +578,8 @@ export default {
|
||||
this.errorMsg.push(error);
|
||||
this.flag.loading = false;
|
||||
})
|
||||
|
||||
))
|
||||
.catch((error) => {
|
||||
this.errorMsg.push(error);
|
||||
this.flag.loading = false;
|
||||
});
|
||||
},
|
||||
|
||||
addDateToAddressAndAddressToHousehold(payload)
|
||||
{
|
||||
this.flag.loading = true;
|
||||
patchAddress(payload.addressId, payload.body)
|
||||
.then(address => new Promise((resolve, reject) => {
|
||||
this.valid.from = address.validFrom;
|
||||
resolve();
|
||||
|
||||
}).then(
|
||||
postAddressToHousehold(payload.entityId, payload.addressId)
|
||||
.then(household => new Promise((resolve, reject) => {
|
||||
|
||||
console.log('TODO commit addAddressToHousehold', household);
|
||||
|
||||
this.flag.loading = false;
|
||||
this.flag.success = true;
|
||||
if (this.options.redirectToBackUrl) {
|
||||
window.location.assign(payload.backUrl);
|
||||
}
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
this.errorMsg.push(error);
|
||||
this.flag.loading = false;
|
||||
})
|
||||
|
||||
))
|
||||
.catch((error) => {
|
||||
this.errorMsg.push(error);
|
||||
this.flag.loading = false;
|
||||
});
|
||||
;
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user