diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php index 1580c5932..79391e904 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php @@ -150,14 +150,19 @@ class HouseholdController extends AbstractController */ public function addressEdit(Request $request, Household $household) { - // TODO ACL - //$address = $this->findAddressById($household, $address_id); //TODO + // TODO ACL + + $address_id = $request->query->get('address_id'); + $address = $this->getDoctrine()->getManager() + ->getRepository(Address::class) + ->find($address_id) + ; return $this->render('@ChillPerson/Household/address_edit.html.twig', [ 'household' => $household, - //'address' => $address, + 'address' => $address, ] ); } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/App.vue index 018ccc42c..f95e8c0fb 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/App.vue @@ -2,7 +2,8 @@
-

{{ $t('create_a_new_address') }}

+

{{ $t('create_a_new_address') }}

+

{{ $t('edit_a_new_address') }}

@@ -14,7 +15,7 @@
-
+

{{ $t('move_date') }}

{{ $t('loading') }}
-
+
{{ $t('household_address_move_success') }}
+
+ {{ $t('household_address_edit_success') }} +
  • {{ $t('back_to_the_list') }}
  • -
  • +
  • @@ -61,6 +65,7 @@ export default { return { edit: window.mode === 'edit', householdId: window.householdId, + addressId: window.addressId, backUrl: `/fr/person/household/${householdId}/addresses`, //TODO better way to pass this validFrom: new Date().toISOString().split('T')[0] } @@ -113,7 +118,14 @@ export default { }); } - this.$store.dispatch('addAddress', createdAddress); + if (this.edit){ + this.$store.dispatch('updateAddress', { + addressId: this.addressId, + newAddress: createdAddress + }); + } else { + this.$store.dispatch('addAddress', createdAddress); + } modal.showModal = false; }, @@ -124,8 +136,16 @@ export default { body: { validFrom: {datetime: `${this.validFrom}T00:00:00+0100`}}, backUrl: this.backUrl }) + }, + getEditAddress() { + this.$store.dispatch('getEditAddress', this.addressId); } - } + }, + mounted() { + if (this.edit) { + this.getEditAddress(); + } + }, }; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/js/i18n.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/js/i18n.js index 59a67438c..f7ee56e02 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/js/i18n.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/js/i18n.js @@ -9,6 +9,7 @@ const appMessages = { move_date: 'Date du déménagement', back_to_the_list: 'Retour à la liste', household_address_move_success: 'La nouvelle adresse du ménage est enregistrée', + household_address_edit_success: 'L\'adresse du ménage a été mise à jour', loading: 'chargement en cours...' } }; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/store/index.js index 074dbf76b..7127ce60c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/store/index.js @@ -1,7 +1,7 @@ import 'es6-promise/auto'; import { createStore } from 'vuex'; -import { postAddress, postPostalCode, patchAddress } from 'ChillMainAssets/vuejs/_api/AddAddress'; +import { postAddress, postPostalCode, patchAddress, getAddress } from 'ChillMainAssets/vuejs/_api/AddAddress'; import { postAddressToHousehold } from '../api'; const debug = process.env.NODE_ENV !== 'production'; @@ -10,6 +10,7 @@ const store = createStore({ strict: debug, state: { newAddress: {}, + editAddress: {}, //TODO or should be newAddress? household: {}, validFrom: {}, errorMsg: [], @@ -26,6 +27,10 @@ const store = createStore({ console.log('@M addAddress address', address); state.newAddress = address; }, + updateAddress(state, address) { + console.log('@M updateAddress address', address); + state.newAddress = address; + }, addAddressToHousehold(state, household) { console.log('@M addAddressToHousehold household', household); state.household = household; @@ -34,6 +39,10 @@ const store = createStore({ console.log('@M addDateToAddress address.validFrom', validFrom); state.validFrom = validFrom; }, + getEditAddress(state, address) { + console.log('@M getEditAddress address', address); + state.editAddress = address; + }, setLoading(state, b) { state.loading = b; }, @@ -101,6 +110,50 @@ const store = createStore({ commit('setLoading', false); }); }, + updateAddress({ commit }, payload) { + console.log('@A updateAddress payload', payload); + + if('newPostalCode' in payload.newAddress){ // TODO change the condition because it writes new postal code in edit mode now: !writeNewPostalCode + let postalCodeBody = payload.newAddress.newPostalCode; + postalCodeBody = Object.assign(postalCodeBody, {'origin': 3}); + postPostalCode(postalCodeBody) + .then(postalCode => { + let body = payload.newAddress; + body.postcode = {'id': postalCode.id }, + patchAddress(payload.addressId, body) + .then(address => new Promise((resolve, reject) => { + commit('updateAddress', address); + commit('setSuccess', true); + resolve(); + })) + .catch((error) => { + commit('catchError', error); + }); + }) + + } else { + patchAddress(payload.addressId, payload.newAddress) + .then(address => new Promise((resolve, reject) => { + commit('updateAddress', address); + commit('setSuccess', true); + resolve(); + })) + .catch((error) => { + commit('catchError', error); + }); + } + }, + getEditAddress({ commit }, payload) { + console.log('@A getEditAddress payload', payload); + + getAddress(payload).then(address => new Promise((resolve, reject) => { + commit('getEditAddress', address); + resolve(); + })) + .catch((error) => { + commit('catchError', error); + }); + }, } }); diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig index 8cfbd6c9b..a148e0d91 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig @@ -40,11 +40,11 @@ {% endif %}
- {#
diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 851932290..25d09858f 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -349,6 +349,7 @@ Move household: Nouveau déménagement Addresses history for household: Historique des adresses Household accompanying period: Parcours d'accompagnement du ménage Household summary: Résumé du ménage +Edit household address: Modifier l'adresse du ménage # accompanying course work Accompanying Course Actions: Actions d'accompagnements