mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
CourseLocation: action and mutation for updateLocation, hide button if personLocation
This commit is contained in:
parent
f535e794a7
commit
5e0c930087
@ -27,10 +27,12 @@
|
||||
<ul class="record_actions">
|
||||
<li>
|
||||
<add-address
|
||||
v-if="hasTemporaryAddressButton"
|
||||
v-bind:context="context"
|
||||
v-bind:key="addAddress.type"
|
||||
v-bind:options="addAddress.options"
|
||||
v-bind:result="addAddress.result"
|
||||
@submitAddress="submitAddress"
|
||||
ref="addAddress">
|
||||
</add-address>
|
||||
</li>
|
||||
@ -52,8 +54,8 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
addAddress: {
|
||||
type: 'accompanying_course_location',
|
||||
options: {
|
||||
|
||||
/// Options override default.
|
||||
/// null value take default component value
|
||||
button: {
|
||||
@ -69,13 +71,8 @@ export default {
|
||||
/// Display each step in page or Modal
|
||||
bindModal: {
|
||||
//step1: false, step2: false
|
||||
},
|
||||
// Options only for root parent component
|
||||
displayResult: true,
|
||||
redirectToBackUrl: false
|
||||
},
|
||||
type: 'accompanying_course_location',
|
||||
result: null // <== returned from addAddress component
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -83,27 +80,43 @@ export default {
|
||||
...mapState({
|
||||
accompanyingCourse: state => state.accompanyingCourse,
|
||||
context: state => state.addressContext
|
||||
})
|
||||
}),
|
||||
hasTemporaryAddressButton() { // return true if locationStatus equal 'none' or 'address'
|
||||
return this.accompanyingCourse.locationStatus !== 'person';
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
initAddressContext() {
|
||||
let ac = {
|
||||
let context = {
|
||||
entity: {
|
||||
type: this.accompanyingCourse.type,
|
||||
id: this.accompanyingCourse.id
|
||||
},
|
||||
edit: false,
|
||||
addressId: null,
|
||||
backUrl: null
|
||||
addressId: null
|
||||
}
|
||||
this.$store.commit('setAddressContext', ac);
|
||||
if (this.accompanyingCourse.location) {
|
||||
context['edit'] = true;
|
||||
context['addressId'] = this.accompanyingCourse.location.address_id
|
||||
}
|
||||
this.$store.commit('setAddressContext', context);
|
||||
},
|
||||
displayErrors() {
|
||||
return this.$refs.addAddress.errorMsg;
|
||||
},
|
||||
submitAddress() {
|
||||
console.log('@@@ click on Submit Address Button');
|
||||
|
||||
let payload = this.$refs.addAddress.submitNewAddress();
|
||||
console.log('payload from parent', payload);
|
||||
|
||||
this.$store.dispatch('updateLocation', payload);
|
||||
|
||||
}
|
||||
},
|
||||
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);
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n'
|
||||
import { addressMessages } from 'ChillMainAssets/vuejs/Address/i18n';
|
||||
|
||||
const appMessages = {
|
||||
fr: {
|
||||
@ -100,7 +101,7 @@ const appMessages = {
|
||||
}
|
||||
};
|
||||
|
||||
Object.assign(appMessages.fr, personMessages.fr);
|
||||
Object.assign(appMessages.fr, personMessages.fr, addressMessages.fr);
|
||||
|
||||
export {
|
||||
appMessages
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'es6-promise/auto';
|
||||
import { createStore } from 'vuex';
|
||||
import { patchAddressToAccompanyingPeriod } from "../../_api/AddAddress.js";
|
||||
import { getAccompanyingCourse,
|
||||
patchAccompanyingCourse,
|
||||
confirmAccompanyingCourse,
|
||||
@ -8,6 +9,7 @@ import { getAccompanyingCourse,
|
||||
postResource,
|
||||
postSocialIssue } from '../api';
|
||||
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
const id = window.accompanyingCourseId;
|
||||
|
||||
@ -97,6 +99,12 @@ let initPromise = getAccompanyingCourse(id)
|
||||
setAddressContext(state, context) {
|
||||
//console.log('define location context');
|
||||
state.addressContext = context;
|
||||
},
|
||||
updateLocation(state, r) {
|
||||
console.log('### mutation: set location attributes', r);
|
||||
state.accompanyingCourse.location = r.location;
|
||||
state.accompanyingCourse.locationStatus = r.locationStatus;
|
||||
state.accompanyingCourse.personLocation = r.personLocation;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
@ -214,6 +222,20 @@ let initPromise = getAccompanyingCourse(id)
|
||||
resolve();
|
||||
})).catch((error) => { commit('catchError', error) });
|
||||
},
|
||||
/////
|
||||
updateLocation({ commit }, payload) {
|
||||
console.log('## action: updateLocation', payload);
|
||||
patchAddressToAccompanyingPeriod(payload.entityId, payload.addressId)
|
||||
.then(accompanyingCourse => new Promise((resolve, reject) => {
|
||||
commit('updateLocation', {
|
||||
location: accompanyingCourse.location,
|
||||
locationStatus: accompanyingCourse.locationStatus,
|
||||
personLocation: accompanyingCourse.personLocation
|
||||
});
|
||||
resolve();
|
||||
})).catch((error) => { commit('catchError', error) });
|
||||
},
|
||||
/////
|
||||
confirmAccompanyingCourse({ commit }) {
|
||||
//console.log('## action: confirmAccompanyingCourse');
|
||||
confirmAccompanyingCourse(id)
|
||||
|
@ -205,8 +205,7 @@ This view should receive those arguments:
|
||||
mode: 'edit',
|
||||
address_id: person.lastAddress.id,
|
||||
backUrl: path('chill_person_view', { 'person_id': person.id }),
|
||||
modalTitle: 'Edit address',
|
||||
buttonText: 'Edit address',
|
||||
modalTitle: 'Edit address', buttonText: 'Edit address',
|
||||
buttonType: 'btn-update',
|
||||
buttonSize: 'btn-sm',
|
||||
buttonDisplay: false
|
||||
|
Loading…
x
Reference in New Issue
Block a user