mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
add and remove requestor functions
This commit is contained in:
parent
4e31b3e424
commit
f7c08f02c2
@ -28,7 +28,36 @@ const postParticipation = (id, person_id, method) => {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json;charset=utf-8'
|
'Content-Type': 'application/json;charset=utf-8'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({id: person_id})
|
body: JSON.stringify({person_id: person_id})
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Endpoint v.2 chill_api_single_accompanying_course_requestor,
|
||||||
|
* method POST/DELETE, add/close a requestor to the accompanyingCourse
|
||||||
|
*
|
||||||
|
* @id integer - id of accompanyingCourse
|
||||||
|
* @payload object of type person|thirdparty
|
||||||
|
* @method string - POST or DELETE
|
||||||
|
*/
|
||||||
|
const postRequestor = (id, payload, method) => {
|
||||||
|
const body = {};
|
||||||
|
if (payload !== null) {
|
||||||
|
const typeId = `${payload.result.type}_id`;
|
||||||
|
body[typeId] = payload.result[typeId];
|
||||||
|
};
|
||||||
|
console.log(body);
|
||||||
|
const url = `/api/1.0/person/accompanying-course/${id}/requestor.json`;
|
||||||
|
return fetch(url, {
|
||||||
|
method: method,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json;charset=utf-8'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body)
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) { return response.json(); }
|
if (response.ok) { return response.json(); }
|
||||||
@ -38,5 +67,6 @@ const postParticipation = (id, person_id, method) => {
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
getAccompanyingCourse,
|
getAccompanyingCourse,
|
||||||
postParticipation
|
postParticipation,
|
||||||
|
postRequestor
|
||||||
};
|
};
|
||||||
|
@ -4,33 +4,36 @@
|
|||||||
<h3>{{ $t('requestor.title') }}</h3>
|
<h3>{{ $t('requestor.title') }}</h3>
|
||||||
|
|
||||||
<div v-if="accompanyingCourse.requestor">
|
<div v-if="accompanyingCourse.requestor">
|
||||||
<dt>{{ $t('requestor.person_id') }}</dt>
|
|
||||||
<dd>{{ accompanyingCourse.requestor.person_id }}</dd>
|
|
||||||
<dt>{{ $t('requestor.type') }}</dt>
|
<dt>{{ $t('requestor.type') }}</dt>
|
||||||
<dd>{{ accompanyingCourse.requestor.type }}</dd>
|
<dd>{{ accompanyingCourse.requestor.type }}</dd>
|
||||||
<dt>{{ $t('requestor.text') }}</dt>
|
<dt>{{ $t('requestor.text') }}</dt>
|
||||||
<dd>{{ accompanyingCourse.requestor.text }}</dd>
|
<dd>{{ accompanyingCourse.requestor.text }}</dd>
|
||||||
<dt>{{ $t('requestor.firstName') }}</dt>
|
|
||||||
<dd>{{ accompanyingCourse.requestor.firstName }}</dd>
|
|
||||||
<dt>{{ $t('requestor.lastName') }}</dt>
|
|
||||||
<dd>{{ accompanyingCourse.requestor.lastName }}</dd>
|
|
||||||
<dt>{{ $t('requestor.phonenumber') }}</dt>
|
|
||||||
<dd>{{ accompanyingCourse.requestor.phonenumber }}</dd>
|
|
||||||
<dt>{{ $t('requestor.mobilenumber') }}</dt>
|
|
||||||
<dd>{{ accompanyingCourse.requestor.mobilenumber }}</dd>
|
|
||||||
<dt>{{ $t('requestor.altNames') }}</dt>
|
|
||||||
<dd>{{ accompanyingCourse.requestor.altNames }}</dd>
|
|
||||||
<dt>{{ $t('requestor.anonymous') }}</dt>
|
<dt>{{ $t('requestor.anonymous') }}</dt>
|
||||||
<dd>{{ accompanyingCourse.requestorAnonymous }}</dd>
|
<dd>{{ accompanyingCourse.requestorAnonymous }}</dd>
|
||||||
|
|
||||||
<div v-if="accompanyingCourse.requestor.type === 'person'">
|
<div v-if="accompanyingCourse.requestor.type === 'person'">
|
||||||
|
<dt>{{ $t('requestor.person_id') }}</dt>
|
||||||
|
<dd>{{ accompanyingCourse.requestor.person_id }}</dd>
|
||||||
<dt>{{ $t('requestor.birthdate') }}</dt>
|
<dt>{{ $t('requestor.birthdate') }}</dt>
|
||||||
<dd>{{ $d(accompanyingCourse.requestor.birthdate.datetime, 'short') }}</dd>
|
<dd>{{ $d(accompanyingCourse.requestor.birthdate.datetime, 'short') }}</dd>
|
||||||
<dt>{{ $t('requestor.center') }}</dt>
|
<dt>{{ $t('requestor.center') }}</dt>
|
||||||
<dd>{{ accompanyingCourse.requestor.center.name }}</dd>
|
<dd>{{ accompanyingCourse.requestor.center.name }}</dd>
|
||||||
|
<dt>{{ $t('requestor.firstName') }}</dt>
|
||||||
|
<dd>{{ accompanyingCourse.requestor.firstName }}</dd>
|
||||||
|
<dt>{{ $t('requestor.lastName') }}</dt>
|
||||||
|
<dd>{{ accompanyingCourse.requestor.lastName }}</dd>
|
||||||
|
<dt>{{ $t('requestor.phonenumber') }}</dt>
|
||||||
|
<dd>{{ accompanyingCourse.requestor.phonenumber }}</dd>
|
||||||
|
<dt>{{ $t('requestor.mobilenumber') }}</dt>
|
||||||
|
<dd>{{ accompanyingCourse.requestor.mobilenumber }}</dd>
|
||||||
|
<dt>{{ $t('requestor.altNames') }}</dt>
|
||||||
|
<dd>{{ accompanyingCourse.requestor.altNames }}</dd>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="accompanyingCourse.requestor.type === 'thirdparty'">
|
<div v-if="accompanyingCourse.requestor.type === 'thirdparty'">
|
||||||
|
<dt>{{ $t('requestor.person_id') }}</dt>
|
||||||
|
<dd>{{ accompanyingCourse.requestor.thirdparty_id }}</dd>
|
||||||
<dt>{{ $t('requestor.address') }}</dt>
|
<dt>{{ $t('requestor.address') }}</dt>
|
||||||
<dd>{{ accompanyingCourse.requestor.address.text }}</dd>
|
<dd>{{ accompanyingCourse.requestor.address.text }}</dd>
|
||||||
<dt>{{ $t('requestor.location') }}</dt>
|
<dt>{{ $t('requestor.location') }}</dt>
|
||||||
@ -38,7 +41,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<add-persons
|
<button class="sc-button bt-delete"
|
||||||
|
v-if="accompanyingCourse.requestor !== null"
|
||||||
|
:title="$t('action.remove')"
|
||||||
|
@click="removeRequestor">
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<add-persons
|
||||||
|
v-if="accompanyingCourse.requestor === null"
|
||||||
buttonTitle="requestor.add_requestor"
|
buttonTitle="requestor.add_requestor"
|
||||||
v-bind:key="addPersons.key"
|
v-bind:key="addPersons.key"
|
||||||
v-bind:options="addPersons.options"
|
v-bind:options="addPersons.options"
|
||||||
@ -75,6 +85,10 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
removeRequestor() {
|
||||||
|
console.log('@@ CLICK remove requestor: item');
|
||||||
|
this.$store.dispatch('removeRequestor');
|
||||||
|
},
|
||||||
addNewPersons({ selected, modal }) {
|
addNewPersons({ selected, modal }) {
|
||||||
console.log('@@@ CLICK button addNewPersons', selected);
|
console.log('@@@ CLICK button addNewPersons', selected);
|
||||||
selected.forEach(function(item) {
|
selected.forEach(function(item) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'es6-promise/auto';
|
import 'es6-promise/auto';
|
||||||
import { createStore } from 'vuex';
|
import { createStore } from 'vuex';
|
||||||
import { getAccompanyingCourse, postParticipation } from '../api';
|
import { getAccompanyingCourse, postParticipation, postRequestor } from '../api';
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production';
|
const debug = process.env.NODE_ENV !== 'production';
|
||||||
const id = window.accompanyingCourseId;
|
const id = window.accompanyingCourseId;
|
||||||
@ -34,9 +34,13 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
//console.log('### mutation: add participation', participation);
|
//console.log('### mutation: add participation', participation);
|
||||||
state.accompanyingCourse.participations.push(participation);
|
state.accompanyingCourse.participations.push(participation);
|
||||||
},
|
},
|
||||||
|
removeRequestor(state) {
|
||||||
|
state.accompanyingCourse.requestor = null;
|
||||||
|
},
|
||||||
addRequestor(state, requestor) {
|
addRequestor(state, requestor) {
|
||||||
console.log(requestor);
|
console.log(requestor);
|
||||||
},
|
state.accompanyingCourse.requestor = requestor;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
removeParticipation({ commit }, payload) {
|
removeParticipation({ commit }, payload) {
|
||||||
@ -58,7 +62,16 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
postParticipation(id, payload.result.person_id, 'POST')
|
postParticipation(id, payload.result.person_id, 'POST')
|
||||||
.then(participation => new Promise((resolve, reject) => {
|
.then(participation => new Promise((resolve, reject) => {
|
||||||
commit('addParticipation', participation);
|
commit('addParticipation', participation);
|
||||||
//addPersons.commit('resetState', payload);
|
resolve();
|
||||||
|
}))
|
||||||
|
.catch((error) => {
|
||||||
|
state.errorMsg.push(error.message);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
removeRequestor({ commit }) {
|
||||||
|
postRequestor(id, null, 'DELETE')
|
||||||
|
.then(requestor => new Promise((resolve, reject) => {
|
||||||
|
commit('removeRequestor');
|
||||||
resolve();
|
resolve();
|
||||||
}))
|
}))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -67,7 +80,14 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
},
|
},
|
||||||
addRequestor({ commit }, payload) {
|
addRequestor({ commit }, payload) {
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
commit('addRequestor', payload);
|
postRequestor(id, payload, 'POST')
|
||||||
|
.then(requestor => new Promise((resolve, reject) => {
|
||||||
|
commit('addRequestor', requestor);
|
||||||
|
resolve();
|
||||||
|
}))
|
||||||
|
.catch((error) => {
|
||||||
|
state.errorMsg.push(error.message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user