improve addAddress

This commit is contained in:
2021-09-18 17:47:49 +02:00
parent 2788170f03
commit a842229d5e
18 changed files with 136 additions and 70 deletions

View File

@@ -243,7 +243,7 @@ export default {
validTo: false
},
forceRedirect: false,
onlyButton: false
hideAddress: false
},
entity: {
address: {}, // <== loaded and returned
@@ -300,7 +300,6 @@ export default {
return true;
},
displaySuggestions() {
console.log('displaySuggestions');
return !this.context.edit && this.hasSuggestions;
},
getTextTitle() {
@@ -314,7 +313,6 @@ export default {
},
bypassFirstStep() {
// exception: passing step0 if new address and pane are not in modal
console.log('bypassFirstStep');
return !this.context.edit && !this.inModal;
}
},
@@ -325,9 +323,13 @@ export default {
//console.log('options bindModal.step2', this.options.bindModal.step2);
//console.log('options useDate.validFrom', this.options.useDate.validFrom);
//console.log('options useDate.validTo', this.options.useDate.validTo);
console.log('useDatePane', this.useDatePane);
//console.log('useDatePane', this.useDatePane);
console.log('Mounted now !');
if (this.context.edit) {
console.log('getInitialAddress');
this.getInitialAddress(this.context.addressId);
}
this.openShowPane();
},
@@ -337,11 +339,8 @@ export default {
* Opening and closing Panes when interacting with buttons
*/
openShowPane() {
if (this.context.edit) {
console.log('getInitialAddress');
this.getInitialAddress(this.context.addressId);
}
if (this.flag.editPane === false && this.bypassFirstStep) {
console.log('bypassFirstStep');
this.closeShowPane();
this.openEditPane();
} else {
@@ -366,6 +365,7 @@ export default {
},
openEditPane() {
if (this.flag.suggestPane === false && this.displaySuggestions) {
console.log('displaySuggestions');
this.openSuggestPane();
} else {
if (this.flag.suggestPane === true) {
@@ -396,11 +396,21 @@ export default {
console.log('step3: close the Date Panel');
},
resetPane() {
console.log('resetPane');
this.flag.suggestPane = false;
this.flag.editPane = false;
this.flag.datePane = false;
this.openShowPane();
},
lastPaneAction() {
if (this.options.forceRedirect === true) {
console.log("redirect to backUrl");
window.location.assign(this.context.backUrl);
} else {
console.log("don't redirect");
this.resetPane();
}
},
/*
* Async Fetch datas
@@ -492,6 +502,7 @@ export default {
this.entity.selected.writeNew.address = this.context.edit;
this.entity.selected.writeNew.postcode = this.context.edit;
console.log('!! just set writeNew.postcode to', this.entity.selected.writeNew.postcode);
},
/*
@@ -501,6 +512,8 @@ export default {
*/
applyChanges()
{
console.log('apply changes');
let newAddress = {
'isNoAddress': this.entity.selected.isNoAddress,
'street': this.entity.selected.isNoAddress ? '' : this.entity.selected.address.street,
@@ -525,22 +538,22 @@ export default {
newPostcode = Object.assign(newPostcode, {
'country': {'id': this.entity.selected.country.id },
});
console.log('writeNew postcode is true! newPostcode: ', newPostcode);
newAddress = Object.assign(newAddress, {
'newPostcode': newPostcode
});
}
console.log('apply changes');
if (this.context.edit) {
if (!this.context.edit) {
this.addNewAddress(newAddress)
.then(payload => this.closePaneAndCallbackSubmit(payload));
} else {
this.updateAddress({
addressId: this.context.addressId,
newAddress: newAddress
})
.then(payload => this.closePaneAndCallbackSubmit(payload));
} else {
this.addNewAddress(newAddress)
.then(payload => this.closePaneAndCallbackSubmit(payload));
}
},
@@ -556,7 +569,7 @@ export default {
if ('newPostcode' in payload) {
let postcodeBody = payload.newPostcode;
if (this.context.entity.name === 'person') {
if (this.context.target.name === 'person') { // !!! maintain here ?
postcodeBody = Object.assign(postcodeBody, {'origin': 3});
}
return postPostalCode(postcodeBody)
@@ -578,8 +591,8 @@ export default {
this.flag.loading = false;
this.flag.success = true;
resolve({
entity: this.context.entity.name,
entityId: this.context.entity.id,
target: this.context.target.name,
targetId: this.context.target.id,
addressId: this.entity.address.address_id
}
);
@@ -599,14 +612,16 @@ export default {
this.flag.loading = true;
// TODO change the condition because it writes new postal code in edit mode now: !writeNewPostalCode
// BUG réécrit un postcode à chaque édition !
if ('newPostcode' in payload.newAddress) {
let postcodeBody = payload.newAddress.newPostcode;
postcodeBody = Object.assign(postcodeBody, {'origin': 3});
console.log('juste before post new postcode', postcodeBody);
return postPostalCode(postcodeBody)
.then(postalCode => {
console.log('create new postcode', postalCode.id);
console.log('new postcode created', postalCode.id);
payload.newAddress.postcode = {'id': postalCode.id };
return this.patchExistingAddress(payload);
});
@@ -624,8 +639,8 @@ export default {
this.flag.loading = false;
this.flag.success = true;
return resolve({
entity: this.context.entity.name,
entityId: this.context.entity.id,
target: this.context.target.name,
targetId: this.context.target.id,
addressId: this.entity.address.address_id
});
})
@@ -642,10 +657,11 @@ export default {
*/
closePaneAndCallbackSubmit(payload)
{
console.log('close pane and call parent callback method', payload);
//this.initForm();
this.flag.showPane = false;
this.initForm();
this.resetPane();
console.log('will call parent callback method', payload);
// callback props method from parent
this.addressChangedCallback(payload);
@@ -662,4 +678,7 @@ div.entity-address {
right: 0; top: -55px;
}
}
h4.h3 {
font-weight: bold;
}
</style>