From a842229d5e8ab846015d4beeec057a84d337e87c Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Sat, 18 Sep 2021 17:47:49 +0200 Subject: [PATCH] improve addAddress --- .../Resources/public/vuejs/Address/App.vue | 24 ++++--- .../Resources/public/vuejs/Address/api.js | 2 +- .../vuejs/Address/components/AddAddress.vue | 67 ++++++++++++------- .../components/AddAddress/CitySelection.vue | 12 +++- .../vuejs/Address/components/DatePane.vue | 2 +- .../vuejs/Address/components/EditPane.vue | 4 -- .../vuejs/Address/components/ShowPane.vue | 19 ++++-- .../vuejs/Address/components/SuggestPane.vue | 28 +++++++- .../Resources/public/vuejs/Address/i18n.js | 2 + .../Resources/public/vuejs/Address/index.js | 8 +-- .../Address/_insert_vue_address.html.twig | 4 +- .../components/ButtonLocation.vue | 4 +- .../components/CourseLocation.vue | 8 +-- .../vuejs/AccompanyingCourse/store/index.js | 4 +- .../components/Household.vue | 4 +- .../views/Household/address_edit.html.twig | 4 +- .../views/Household/address_move.html.twig | 6 +- .../views/Household/addresses.html.twig | 4 +- 18 files changed, 136 insertions(+), 70 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue index 884849ba6..17f5ee288 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue @@ -27,7 +27,7 @@ export default { }, key() { return (this.context.edit) ? 'address_' + this.context.addressId - : this.context.entity.name + '_' + this.context.entity.id ; + : this.context.target.name + '_' + this.context.target.id ; } }, mounted() { @@ -45,9 +45,7 @@ export default { if (this.context.edit) { // address is already linked, just finish ! - if (this.options.forceRedirect === true) { - window.location.assign(this.context.backUrl); - } + this.$refs.addAddress.lastPaneAction(); // New created address } else { @@ -85,15 +83,18 @@ export default { * Post new created address to targetEntity */ postAddressTo(payload) { - console.log('postAddressTo', payload.entity); - switch (payload.entity) { + console.log('postAddressTo', payload.target); + switch (payload.target) { case 'household': - postAddressToHousehold(payload.entityId, payload.addressId) + postAddressToHousehold(payload.targetId, 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); + + // finish + this.$refs.addAddress.lastPaneAction(); + resolve(); })) .catch((error) => { @@ -103,12 +104,15 @@ export default { ; break; case 'person': - postAddressToPerson(payload.entityId, payload.addressId) + postAddressToPerson(payload.targetId, 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); + + // finish + this.$refs.addAddress.lastPaneAction(); + resolve(); })) .catch((error) => { diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/api.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/api.js index e4ed78f35..14fa0490f 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/api.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/api.js @@ -109,7 +109,7 @@ const patchAddress = (id, body) => { * method POST, post Postal Code Object * @returns {Promise} */ -const postPostalCode = (postalCode) => { +const postPostalCode = (postalCode) => { //<-- const url = `/api/1.0/main/postal-code.json?`; const body = postalCode; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue index d5bf8f9e2..75f7b9c63 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue @@ -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; +} diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue index 828c3ed96..9b6a7b87f 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CitySelection.vue @@ -1,6 +1,6 @@