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