mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fetch post resource
This commit is contained in:
parent
87e2ac9386
commit
aef97cca32
@ -1,5 +1,5 @@
|
||||
|
||||
const getBodyTypeId = (payload) => {
|
||||
const getEntityTypeId = (payload) => {
|
||||
const body = {};
|
||||
if (payload !== null) {
|
||||
body['type'] = payload.type;
|
||||
@ -56,7 +56,7 @@ const patchAccompanyingCourse = (id, body) => {
|
||||
* @method string - POST or DELETE
|
||||
*/
|
||||
const postParticipation = (id, payload, method) => {
|
||||
const body = getBodyTypeId(payload);
|
||||
const body = getEntityTypeId(payload);
|
||||
const url = `/api/1.0/person/accompanying-course/${id}/participation.json`;
|
||||
return fetch(url, {
|
||||
method: method,
|
||||
@ -80,7 +80,7 @@ const postParticipation = (id, payload, method) => {
|
||||
* @method string - POST or DELETE
|
||||
*/
|
||||
const postRequestor = (id, payload, method) => {
|
||||
const body = getBodyTypeId(payload);
|
||||
const body = getEntityTypeId(payload);
|
||||
const url = `/api/1.0/person/accompanying-course/${id}/requestor.json`;
|
||||
return fetch(url, {
|
||||
method: method,
|
||||
@ -104,7 +104,14 @@ const postRequestor = (id, payload, method) => {
|
||||
* @method string - POST or DELETE
|
||||
*/
|
||||
const postResource = (id, payload, method) => {
|
||||
const body = getBodyTypeId(payload);
|
||||
console.log('payload', payload);
|
||||
const body = { type: "accompanying_period_resource" };
|
||||
if (method === 'DELETE') {
|
||||
body['id'] = payload.id;
|
||||
} else {
|
||||
body['resource'] = getEntityTypeId(payload);
|
||||
}
|
||||
console.log('body', body);
|
||||
const url = `/api/1.0/person/accompanying-course/${id}/resource.json`;
|
||||
return fetch(url, {
|
||||
method: method,
|
||||
|
@ -1,14 +1,10 @@
|
||||
<template>
|
||||
<tr>
|
||||
|
||||
<td>{{ interlocutor.key }}</td>
|
||||
<td>{{ interlocutor.result.text }}</td>
|
||||
<td><span >
|
||||
</span>
|
||||
</td>
|
||||
<td><span >
|
||||
</span>
|
||||
</td>
|
||||
<td>{{ resource.resource.text }}</td>
|
||||
<td>{{ resource.resource.type }} {{ resource.resource.id }}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
|
||||
<td>
|
||||
<ul class="record_actions">
|
||||
@ -28,7 +24,7 @@
|
||||
<button
|
||||
class="sc-button bt-remove"
|
||||
:title="$t('action.remove')"
|
||||
@click.prevent="$emit('remove', interlocutor)">
|
||||
@click.prevent="$emit('remove', resource)">
|
||||
</button>
|
||||
|
||||
</li>
|
||||
@ -40,7 +36,7 @@
|
||||
<script>
|
||||
export default {
|
||||
name: 'InterlocutorItem',
|
||||
props: ['interlocutor'],
|
||||
props: ['resource'],
|
||||
data() {
|
||||
return {
|
||||
url: {
|
||||
|
@ -16,9 +16,9 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<interlocutor-item
|
||||
v-for="interlocutor in interlocutors"
|
||||
v-bind:interlocutor="interlocutor"
|
||||
v-bind:key="interlocutor.id"
|
||||
v-for="resource in resources"
|
||||
v-bind:resource="resource"
|
||||
v-bind:key="resource.id"
|
||||
@remove="removeInterlocutor">
|
||||
</interlocutor-item>
|
||||
</tbody>
|
||||
@ -37,6 +37,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState } from 'vuex';
|
||||
import AddPersons from 'ChillPersonAssets/vuejs/_components/AddPersons.vue';
|
||||
import InterlocutorItem from './InterlocutorItem.vue';
|
||||
|
||||
@ -58,15 +59,14 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
accompanyingCourse() {
|
||||
return this.$store.state.accompanyingCourse;
|
||||
}
|
||||
},
|
||||
computed: mapState({
|
||||
resources: state => state.accompanyingCourse.resources,
|
||||
counter: state => state.accompanyingCourse.resources.length
|
||||
}),
|
||||
methods: {
|
||||
removeInterlocutor() {
|
||||
console.log('@@ CLICK remove interlocutor: item');
|
||||
this.$store.dispatch('removeInterlocutor');
|
||||
removeInterlocutor(item) {
|
||||
console.log('@@ CLICK remove interlocutor: item', item);
|
||||
this.$store.dispatch('removeInterlocutor', item);
|
||||
},
|
||||
addNewPersons({ selected, modal }) {
|
||||
console.log('@@@ CLICK button addNewPersons', selected);
|
||||
|
@ -23,9 +23,9 @@ let initPromise = getAccompanyingCourse(id)
|
||||
getters: {
|
||||
},
|
||||
mutations: {
|
||||
removeParticipation(state, item) {
|
||||
//console.log('### mutation: remove item', item.id);
|
||||
state.accompanyingCourse.participations = state.accompanyingCourse.participations.filter(participation => participation !== item);
|
||||
removeParticipation(state, participation) {
|
||||
//console.log('### mutation: remove participation', participation.id);
|
||||
state.accompanyingCourse.participations = state.accompanyingCourse.participations.filter(element => element !== participation);
|
||||
},
|
||||
closeParticipation(state, { participation, payload }) {
|
||||
//console.log('### mutation: close item', { participation, payload });
|
||||
@ -50,13 +50,13 @@ let initPromise = getAccompanyingCourse(id)
|
||||
//console.log('### mutation: requestorIsAnonymous', value);
|
||||
state.accompanyingCourse.requestorAnonymous = value;
|
||||
},
|
||||
removeInterlocutor(state, interlocutor) {
|
||||
console.log('### mutation: removeInterlocutor', interlocutor);
|
||||
state.accompanyingCourse.resources = state.accompanyingCourse.resources.filter(resource => resource !== interlocutor);
|
||||
removeInterlocutor(state, resource) {
|
||||
console.log('### mutation: removeInterlocutor', resource);
|
||||
state.accompanyingCourse.resources = state.accompanyingCourse.resources.filter(element => element !== resource);
|
||||
},
|
||||
addInterlocutor(state, interlocutor) {
|
||||
console.log('### mutation: addInterlocutor', interlocutor);
|
||||
state.accompanyingCourse.resources.push(interlocutor);
|
||||
addInterlocutor(state, resource) {
|
||||
console.log('### mutation: addInterlocutor', resource);
|
||||
state.accompanyingCourse.resources.push(resource);
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
@ -122,9 +122,9 @@ let initPromise = getAccompanyingCourse(id)
|
||||
},
|
||||
removeInterlocutor({ commit }, payload) {
|
||||
console.log('## action: fetch postInterlocutor: payload', payload);
|
||||
postResource(id, payload, 'POST')
|
||||
postResource(id, payload, 'DELETE')
|
||||
.then(resource => new Promise((resolve, reject) => {
|
||||
commit('removeInterlocutor', resource)
|
||||
commit('removeInterlocutor', payload) // mieux un retour de l'objet !
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user