mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
person: accompanying course: treat validation error when editing on-the-fly entities
This commit is contained in:
parent
a68a43adc0
commit
befd5dac42
@ -63,6 +63,7 @@ import OnTheFly from 'ChillMainAssets/vuejs/OnTheFly/components/OnTheFly.vue';
|
|||||||
import ButtonLocation from '../ButtonLocation.vue';
|
import ButtonLocation from '../ButtonLocation.vue';
|
||||||
import PersonRenderBox from 'ChillPersonAssets/vuejs/_components/Entity/PersonRenderBox.vue';
|
import PersonRenderBox from 'ChillPersonAssets/vuejs/_components/Entity/PersonRenderBox.vue';
|
||||||
import Modal from 'ChillMainAssets/vuejs/_components/Modal';
|
import Modal from 'ChillMainAssets/vuejs/_components/Modal';
|
||||||
|
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ParticipationItem',
|
name: 'ParticipationItem',
|
||||||
@ -111,17 +112,53 @@ export default {
|
|||||||
saveFormOnTheFly(payload) {
|
saveFormOnTheFly(payload) {
|
||||||
console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data);
|
console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data);
|
||||||
payload.target = 'participation';
|
payload.target = 'participation';
|
||||||
this.$store.dispatch('patchOnTheFly', payload)
|
|
||||||
|
let body = { type: payload.type };
|
||||||
|
if (payload.type === 'person') {
|
||||||
|
body.firstName = payload.data.firstName;
|
||||||
|
body.lastName = payload.data.lastName;
|
||||||
|
if (payload.data.birthdate !== null) { body.birthdate = payload.data.birthdate; }
|
||||||
|
body.phonenumber = payload.data.phonenumber;
|
||||||
|
body.mobilenumber = payload.data.mobilenumber;
|
||||||
|
body.gender = payload.data.gender;
|
||||||
|
|
||||||
|
makeFetch('PATCH', `/api/1.0/person/person/${payload.data.id}.json`, body)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
this.$store.dispatch('addPerson', { target: payload.target, body: response })
|
||||||
this.canCloseOnTheFlyModal = true;
|
this.canCloseOnTheFlyModal = true;
|
||||||
})
|
})
|
||||||
.catch(({name, violations}) => {
|
.catch((error) => {
|
||||||
if (name === 'ValidationException' || name === 'AccessException') {
|
if (error.name === 'ValidationException') {
|
||||||
violations.forEach((violation) => this.$toast.open({message: violation}));
|
for (let v of error.violations) {
|
||||||
} else {
|
this.$toast.open({message: v });
|
||||||
this.$toast.open({message: 'An error occurred'})
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
this.$toast.open({message: 'An error occurred'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else if (payload.type === 'thirdparty') {
|
||||||
|
body.name = payload.data.text;
|
||||||
|
body.email = payload.data.email;
|
||||||
|
body.telephone = payload.data.phonenumber;
|
||||||
|
body.address = { id: payload.data.address.address_id };
|
||||||
|
|
||||||
|
makeFetch('PATCH', `/api/1.0/third-party/third-party/${payload.data.id}.json`, body)
|
||||||
|
.then(response => {
|
||||||
|
this.$store.dispatch('addThirdparty', { target: payload.target, body: response })
|
||||||
|
this.canCloseOnTheFlyModal = true;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (error.name === 'ValidationException') {
|
||||||
|
for (let v of error.violations) {
|
||||||
|
this.$toast.open({message: v });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.$toast.open({message: 'An error occurred'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@
|
|||||||
<template v-slot:record-actions>
|
<template v-slot:record-actions>
|
||||||
<ul class="record_actions">
|
<ul class="record_actions">
|
||||||
<li><on-the-fly :type="accompanyingCourse.requestor.type" :id="accompanyingCourse.requestor.id" action="show"></on-the-fly></li>
|
<li><on-the-fly :type="accompanyingCourse.requestor.type" :id="accompanyingCourse.requestor.id" action="show"></on-the-fly></li>
|
||||||
<li><on-the-fly :type="accompanyingCourse.requestor.type" :id="accompanyingCourse.requestor.id" action="edit" @saveFormOnTheFly="saveFormOnTheFly"></on-the-fly></li>
|
<li><on-the-fly :type="accompanyingCourse.requestor.type" :id="accompanyingCourse.requestor.id" action="edit" @saveFormOnTheFly="saveFormOnTheFly" :canCloseModal="canCloseOnTheFlyModal"></on-the-fly></li>
|
||||||
</ul>
|
</ul>
|
||||||
</template>
|
</template>
|
||||||
</person-render-box>
|
</person-render-box>
|
||||||
@ -162,6 +162,7 @@ import PersonRenderBox from '../../_components/Entity/PersonRenderBox.vue';
|
|||||||
import ThirdPartyRenderBox from 'ChillThirdPartyAssets/vuejs/_components/Entity/ThirdPartyRenderBox.vue';
|
import ThirdPartyRenderBox from 'ChillThirdPartyAssets/vuejs/_components/Entity/ThirdPartyRenderBox.vue';
|
||||||
import Confidential from 'ChillMainAssets/vuejs/_components/Confidential.vue';
|
import Confidential from 'ChillMainAssets/vuejs/_components/Confidential.vue';
|
||||||
import { mapState } from 'vuex';
|
import { mapState } from 'vuex';
|
||||||
|
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Requestor',
|
name: 'Requestor',
|
||||||
@ -182,7 +183,8 @@ export default {
|
|||||||
priority: null,
|
priority: null,
|
||||||
uniq: true,
|
uniq: true,
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
canCloseOnTheFlyModal: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -246,14 +248,52 @@ export default {
|
|||||||
saveFormOnTheFly(payload) {
|
saveFormOnTheFly(payload) {
|
||||||
console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data);
|
console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data);
|
||||||
payload.target = 'requestor';
|
payload.target = 'requestor';
|
||||||
this.$store.dispatch('patchOnTheFly', payload)
|
|
||||||
.catch(({name, violations}) => {
|
let body = { type: payload.type };
|
||||||
if (name === 'ValidationException' || name === 'AccessException') {
|
if (payload.type === 'person') {
|
||||||
violations.forEach((violation) => this.$toast.open({message: violation}));
|
body.firstName = payload.data.firstName;
|
||||||
} else {
|
body.lastName = payload.data.lastName;
|
||||||
this.$toast.open({message: 'An error occurred'})
|
if (payload.data.birthdate !== null) { body.birthdate = payload.data.birthdate; }
|
||||||
|
body.phonenumber = payload.data.phonenumber;
|
||||||
|
body.mobilenumber = payload.data.mobilenumber;
|
||||||
|
body.gender = payload.data.gender;
|
||||||
|
|
||||||
|
makeFetch('PATCH', `/api/1.0/person/person/${payload.data.id}.json`, body)
|
||||||
|
.then(response => {
|
||||||
|
this.$store.dispatch('addPerson', { target: payload.target, body: response })
|
||||||
|
this.canCloseOnTheFlyModal = true;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (error.name === 'ValidationException') {
|
||||||
|
for (let v of error.violations) {
|
||||||
|
this.$toast.open({message: v });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.$toast.open({message: 'An error occurred'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else if (payload.type === 'thirdparty') {
|
||||||
|
body.name = payload.data.text;
|
||||||
|
body.email = payload.data.email;
|
||||||
|
body.telephone = payload.data.phonenumber;
|
||||||
|
body.address = { id: payload.data.address.address_id };
|
||||||
|
|
||||||
|
makeFetch('PATCH', `/api/1.0/third-party/third-party/${payload.data.id}.json`, body)
|
||||||
|
.then(response => {
|
||||||
|
this.$store.dispatch('addThirdparty', { target: payload.target, body: response })
|
||||||
|
this.canCloseOnTheFlyModal = true;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (error.name === 'ValidationException') {
|
||||||
|
for (let v of error.violations) {
|
||||||
|
this.$toast.open({message: v });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.$toast.open({message: 'An error occurred'});
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
},
|
||||||
addSuggestedEntity(e) {
|
addSuggestedEntity(e) {
|
||||||
this.$store.dispatch('addRequestor', { result: e, type: e.type })
|
this.$store.dispatch('addRequestor', { result: e, type: e.type })
|
||||||
|
@ -34,7 +34,8 @@
|
|||||||
:type="resource.resource.type"
|
:type="resource.resource.type"
|
||||||
:id="resource.resource.id"
|
:id="resource.resource.id"
|
||||||
action="edit"
|
action="edit"
|
||||||
@saveFormOnTheFly="saveFormOnTheFly">
|
@saveFormOnTheFly="saveFormOnTheFly"
|
||||||
|
:canCloseModal="canCloseOnTheFlyModal">
|
||||||
</on-the-fly>
|
</on-the-fly>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
@ -80,7 +81,8 @@
|
|||||||
:type="resource.resource.type"
|
:type="resource.resource.type"
|
||||||
:id="resource.resource.id"
|
:id="resource.resource.id"
|
||||||
action="edit"
|
action="edit"
|
||||||
@saveFormOnTheFly="saveFormOnTheFly">
|
@saveFormOnTheFly="saveFormOnTheFly"
|
||||||
|
:canCloseModal="canCloseOnTheFlyModal">
|
||||||
</on-the-fly>
|
</on-the-fly>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
@ -101,6 +103,7 @@ import ButtonLocation from '../ButtonLocation.vue';
|
|||||||
import PersonRenderBox from 'ChillPersonAssets/vuejs/_components/Entity/PersonRenderBox.vue';
|
import PersonRenderBox from 'ChillPersonAssets/vuejs/_components/Entity/PersonRenderBox.vue';
|
||||||
import ThirdPartyRenderBox from 'ChillThirdPartyAssets/vuejs/_components/Entity/ThirdPartyRenderBox.vue';
|
import ThirdPartyRenderBox from 'ChillThirdPartyAssets/vuejs/_components/Entity/ThirdPartyRenderBox.vue';
|
||||||
import WriteComment from './WriteComment';
|
import WriteComment from './WriteComment';
|
||||||
|
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ResourceItem',
|
name: 'ResourceItem',
|
||||||
@ -113,6 +116,11 @@ export default {
|
|||||||
},
|
},
|
||||||
props: ['resource'],
|
props: ['resource'],
|
||||||
emits: ['remove'],
|
emits: ['remove'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
canCloseOnTheFlyModal: false
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
parent() {
|
parent() {
|
||||||
return {
|
return {
|
||||||
@ -136,14 +144,52 @@ export default {
|
|||||||
saveFormOnTheFly(payload) {
|
saveFormOnTheFly(payload) {
|
||||||
console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data);
|
console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data);
|
||||||
payload.target = 'resource';
|
payload.target = 'resource';
|
||||||
this.$store.dispatch('patchOnTheFly', payload)
|
|
||||||
.catch(({name, violations}) => {
|
let body = { type: payload.type };
|
||||||
if (name === 'ValidationException' || name === 'AccessException') {
|
if (payload.type === 'person') {
|
||||||
violations.forEach((violation) => this.$toast.open({message: violation}));
|
body.firstName = payload.data.firstName;
|
||||||
} else {
|
body.lastName = payload.data.lastName;
|
||||||
this.$toast.open({message: 'An error occurred'})
|
if (payload.data.birthdate !== null) { body.birthdate = payload.data.birthdate; }
|
||||||
|
body.phonenumber = payload.data.phonenumber;
|
||||||
|
body.mobilenumber = payload.data.mobilenumber;
|
||||||
|
body.gender = payload.data.gender;
|
||||||
|
|
||||||
|
makeFetch('PATCH', `/api/1.0/person/person/${payload.data.id}.json`, body)
|
||||||
|
.then(response => {
|
||||||
|
this.$store.dispatch('addPerson', { target: payload.target, body: response })
|
||||||
|
this.canCloseOnTheFlyModal = true;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (error.name === 'ValidationException') {
|
||||||
|
for (let v of error.violations) {
|
||||||
|
this.$toast.open({message: v });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.$toast.open({message: 'An error occurred'});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else if (payload.type === 'thirdparty') {
|
||||||
|
body.name = payload.data.text;
|
||||||
|
body.email = payload.data.email;
|
||||||
|
body.telephone = payload.data.phonenumber;
|
||||||
|
body.address = { id: payload.data.address.address_id };
|
||||||
|
|
||||||
|
makeFetch('PATCH', `/api/1.0/third-party/third-party/${payload.data.id}.json`, body)
|
||||||
|
.then(response => {
|
||||||
|
this.$store.dispatch('addThirdparty', { target: payload.target, body: response })
|
||||||
|
this.canCloseOnTheFlyModal = true;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (error.name === 'ValidationException') {
|
||||||
|
for (let v of error.violations) {
|
||||||
|
this.$toast.open({message: v });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.$toast.open({message: 'An error occurred'});
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
},
|
||||||
updateComment(resource) {
|
updateComment(resource) {
|
||||||
console.log('updateComment', resource);
|
console.log('updateComment', resource);
|
||||||
|
@ -286,6 +286,12 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
|
|||||||
commit('removeParticipation', payload);
|
commit('removeParticipation', payload);
|
||||||
// fetch DELETE request...
|
// fetch DELETE request...
|
||||||
},
|
},
|
||||||
|
addPerson({ commit }, payload) {
|
||||||
|
commit('updatePerson', { target: payload.target, person: payload.body });
|
||||||
|
},
|
||||||
|
addThirdparty({ commit }, payload) {
|
||||||
|
commit('updateThirdparty', { target: payload.target, thirdparty: payload.body });
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Add/close participation
|
* Add/close participation
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user