From 17a3f45247a07f74a26e5425b34058314a7e1d38 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 16 Sep 2021 15:48:45 +0200 Subject: [PATCH] AddAddress final submit, managed by callback and not an event --- .../Resources/public/vuejs/Address/App.vue | 20 +++--- .../vuejs/Address/components/AddAddress.vue | 70 ++++++++++++------- .../Address/components/ShowAddressPane.vue | 13 ++-- .../Resources/views/ThirdParty/show.html.twig | 4 +- 4 files changed, 63 insertions(+), 44 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue index 249b53588..b79840998 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue @@ -4,7 +4,7 @@ v-bind:context="context" v-bind:options="addAddress.options" v-bind:result="addAddress.result" - @submitAddress="submitAddress" + v-bind:addressChanged="submitAddress" ref="addAddress"> @@ -73,13 +73,11 @@ export default { displayErrors() { return this.$refs.addAddress.errorMsg; }, - submitAddress() { - console.log('@@@ click on Submit Address Button'); - let payload = this.$refs.addAddress.submitNewAddress(); // Cast child method - this.addDateToAddressAndPostAddressTo(payload); + submitAddress(payload) { + console.log('@@@ click on Submit Address Button', payload); + this.addDateToAddressAndPostAddressTo(payload); // !! }, - addDateToAddressAndPostAddressTo(payload) - { + addDateToAddressAndPostAddressTo(payload) { payload.body = { validFrom: { datetime: `${this.context.valid.from.toISOString().split('T')[0]}T00:00:00+0100` @@ -100,11 +98,9 @@ export default { this.$refs.addAddress.flag.loading = false; }); }, - - postAddressTo(payload) - { + postAddressTo(payload) { console.log('postAddressTo', payload.entity); - if (!this.context.edit) { + if (!this.context.edit) { // !! switch (payload.entity) { case 'household': postAddressToHousehold(payload.entityId, payload.addressId) @@ -141,7 +137,7 @@ export default { } } else { // address is already linked, just finish ! - window.location.assign(this.context.backUrl); + //window.location.assign(this.context.backUrl); } }, } 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 19d35381c..8faaa4e5a 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue @@ -57,9 +57,9 @@ v-bind:entity="this.entity" v-bind:valid="this.context.valid" v-bind:flag="this.flag" - ref="showAddress" - v-bind:insideModal="false" @openEditPane="openEditPane" - @submitAddress="$emit('submitAddress')"> + v-bind:insideModal="false" + @openEditPane="openEditPane" + ref="showAddress"> @@ -110,7 +110,8 @@ v-bind:default="this.default" v-bind:entity="this.entity" v-bind:flag="this.flag" - v-bind:insideModal="false" @closeEditPane="closeEditPane" + v-bind:insideModal="false" + @closeEditPane="closeEditPane" @getCities="getCities" @getReferenceAddresses="getReferenceAddresses"> @@ -127,8 +128,7 @@ import EditAddressPane from './EditAddressPane.vue'; export default { name: "AddAddress", - props: ['context', 'options', 'result'], - emits: ['submitAddress'], + props: ['context', 'options', 'addressChanged'], components: { Modal, ShowAddressPane, @@ -249,7 +249,7 @@ export default { this.getInitialAddress(this.context.addressId); } - // when create new address, start first with editPane + // when create new address, start first with editPane !! if ( this.context.edit === false && this.flag.editPane === false ) { @@ -407,10 +407,19 @@ export default { this.updateAddress({ addressId: this.context.addressId, newAddress: newAddress - }); + }) + .then(payload => { + console.log('payload', payload); + this.addressChanged(payload); + } + ); + } else { - this.addNewAddress(newAddress); + this.addNewAddress(newAddress) + .then(payload => this.addressChanged(payload)); } + + }, /* @@ -428,25 +437,30 @@ export default { if (this.context.entity.type === 'person') { postcodeBody = Object.assign(postcodeBody, {'origin': 3}); } - postPostalCode(postcodeBody) + return postPostalCode(postcodeBody) .then(postalCode => { payload.postcode = {'id': postalCode.id }; - this.postNewAddress(payload); + return this.postNewAddress(payload); }); } else { - this.postNewAddress(payload); + return this.postNewAddress(payload); } }, postNewAddress(payload) { //console.log('postNewAddress', payload); - postAddress(payload) + return postAddress(payload) .then(address => new Promise((resolve, reject) => { this.entity.address = address; this.flag.loading = false; this.flag.success = true; - resolve(); + resolve({ + entity: this.context.entity.type, + entityId: this.context.entity.id, + addressId: this.entity.address.address_id + } + ); })) .catch((error) => { this.errorMsg.push(error); @@ -463,31 +477,37 @@ export default { this.flag.loading = true; // TODO change the condition because it writes new postal code in edit mode now: !writeNewPostalCode - if ('newPostcode' in payload.newAddress) { + if ('newPostcode' in payload.newAddress) { let postcodeBody = payload.newAddress.newPostcode; postcodeBody = Object.assign(postcodeBody, {'origin': 3}); - postPostalCode(postcodeBody) + return postPostalCode(postcodeBody) .then(postalCode => { + console.log('create new postcode', postalCode.id); payload.newAddress.postcode = {'id': postalCode.id }; - this.patchExistingAddress(payload); + return this.patchExistingAddress(payload); }); } else { - this.patchExistingAddress(payload); + return this.patchExistingAddress(payload); } }, patchExistingAddress(payload) { console.log('patchExistingAddress', payload); - patchAddress(payload.addressId, payload.newAddress) + return patchAddress(payload.addressId, payload.newAddress) .then(address => new Promise((resolve, reject) => { - this.entity.address = address; - this.flag.loading = false; - this.flag.success = true; - resolve(); - })) + this.entity.address = address; + this.flag.loading = false; + this.flag.success = true; + return resolve({ + entity: this.context.entity.type, + entityId: this.context.entity.id, + addressId: this.entity.address.address_id + }); + }) + ) .catch((error) => { this.errorMsg.push(error); this.flag.loading = false; @@ -497,7 +517,6 @@ export default { /* * Method called by parent when submitting address * (get out step1 show pane, submit button) - */ submitNewAddress() { let payload = { @@ -513,6 +532,7 @@ export default { return payload; } + */ } } diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddressPane.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddressPane.vue index d3894f972..25811f7be 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddressPane.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddressPane.vue @@ -4,9 +4,11 @@ {{ $t('loading') }} +
{{ errorMsg }}
+
{{ $t(getSuccessText) }}
@@ -26,23 +28,24 @@ @@ -65,7 +68,7 @@ export default { 'errorMsg', 'insideModal' ], - emits: ['openEditPane', 'submitAddress'], //? + emits: ['openEditPane'], // 'submitAddress' computed: { address() { return this.entity.address; diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig index 6f647f6b6..d711bdefa 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/show.html.twig @@ -82,7 +82,7 @@ {% if thirdParty.address == null %} {{ 'No address given'|trans }} {% else %} - {{ thirdParty.address|chill_entity_render_box({'with_valid_from': false }) }} + {{ thirdParty.address|chill_entity_render_box({'with_valid_from': false, 'extended_infos': true }) }} {% endif %} @@ -103,7 +103,7 @@