courseLocation: init Address context in the store

This commit is contained in:
Mathieu Jaumotte 2021-08-12 15:42:48 +02:00
parent 368bbcf9b2
commit 205c48f58a
4 changed files with 53 additions and 26 deletions

View File

@ -47,7 +47,8 @@ export default {
Confirm, Confirm,
}, },
computed: mapState([ computed: mapState([
'accompanyingCourse' 'accompanyingCourse',
'addressContext'
]) ])
}; };
</script> </script>

View File

@ -27,8 +27,8 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<add-address <add-address
v-bind:key="addAddress.type"
v-bind:context="context" v-bind:context="context"
v-bind:key="addAddress.type"
v-bind:options="addAddress.options" v-bind:options="addAddress.options"
v-bind:result="addAddress.result" v-bind:result="addAddress.result"
ref="addAddress"> ref="addAddress">
@ -41,6 +41,7 @@
</template> </template>
<script> <script>
import { mapState } from "vuex";
import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress.vue'; import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress.vue';
export default { export default {
@ -50,25 +51,21 @@ export default {
}, },
data() { data() {
return { return {
context: {
edit: true, //dynamic //window.mode === 'edit',
personId: null, //window.personId,
addressId: null, //window.addressId,
backUrl: null //window.backUrl,
},
addAddress: { addAddress: {
options: { options: {
/// Options override default. /// Options override default.
/// null value take default component value /// null value take default component value
button: { button: {
text: { create: null, edit: null }, text: {
type: null, create: 'courselocation.add_temporary_address',
size: null, edit: 'courselocation.edit_temporary_address'
//display: false },
},
title: {
create: 'courselocation.add_temporary_address',
edit: 'courselocation.edit_temporary_address'
}, },
/// Modal title text if create or edit address (trans chain, see i18n)
title: { create: null, edit: null },
/// Display each step in page or Modal /// Display each step in page or Modal
bindModal: { bindModal: {
//step1: false, step2: false //step1: false, step2: false
@ -77,15 +74,39 @@ export default {
displayResult: true, displayResult: true,
redirectToBackUrl: false redirectToBackUrl: false
}, },
type: 'courseLocation', type: 'accompanying_course_location',
result: null // <== returned from addAddress component result: null // <== returned from addAddress component
} }
} }
}, },
computed: {
...mapState({
accompanyingCourse: state => state.accompanyingCourse,
context: state => state.addressContext
})
},
methods: { methods: {
initAddressContext() {
let ac = {
entity: {
type: this.accompanyingCourse.type,
id: this.accompanyingCourse.id
},
edit: false,
addressId: null,
backUrl: null
}
this.$store.commit('setAddressContext', ac);
},
displayErrors() { displayErrors() {
return this.$refs.addAddress.errorMsg; return this.$refs.addAddress.errorMsg;
} }
},
mounted() {
this.initAddressContext();
console.log('ac.locationStatus', this.accompanyingCourse.locationStatus);
console.log('ac.location (temporary location)', this.accompanyingCourse.location);
console.log('ac.personLocation', this.accompanyingCourse.personLocation);
} }
} }
</script> </script>

View File

@ -65,8 +65,8 @@ const appMessages = {
}, },
courselocation: { courselocation: {
title: "Localisation du parcours", title: "Localisation du parcours",
add_temp_address: "Ajouter une adresse temporaire", add_temporary_address: "Ajouter une adresse temporaire",
edit_temp_address: "Modifier l'adresse temporaire", edit_temporary_address: "Modifier l'adresse temporaire",
assign_course_address: "Désigner comme l'adresse du parcours", assign_course_address: "Désigner comme l'adresse du parcours",
}, },
referrer: { referrer: {

View File

@ -20,6 +20,7 @@ let initPromise = getAccompanyingCourse(id)
}, },
state: { state: {
accompanyingCourse: accompanying_course, accompanyingCourse: accompanying_course,
addressContext: {},
errorMsg: [] errorMsg: []
}, },
getters: { getters: {
@ -92,6 +93,10 @@ let initPromise = getAccompanyingCourse(id)
confirmAccompanyingCourse(state, response) { confirmAccompanyingCourse(state, response) {
//console.log('### mutation: confirmAccompanyingCourse: response', response); //console.log('### mutation: confirmAccompanyingCourse: response', response);
state.accompanyingCourse.step = response.step; state.accompanyingCourse.step = response.step;
},
setAddressContext(state, context) {
//console.log('define location context');
state.addressContext = context;
} }
}, },
actions: { actions: {