Merge remote-tracking branch 'origin/master' into issue589_private_comments

This commit is contained in:
2022-05-27 15:47:25 +02:00
276 changed files with 4245 additions and 1708 deletions

View File

@@ -123,6 +123,7 @@ export default {
body.email = payload.data.email;
body.altNames = payload.data.altNames;
body.gender = payload.data.gender;
if (payload.data.civility !== null) { body.civility = {id: payload.data.civility.id, type: payload.data.civility.type }; }
makeFetch('PATCH', `/api/1.0/person/person/${payload.data.id}.json`, body)
.then(response => {

View File

@@ -150,6 +150,7 @@ export default {
body.email = payload.data.email;
body.altNames = payload.data.altNames;
body.gender = payload.data.gender;
if (payload.data.civility !== null) { body.civility = {id: payload.data.civility.id, type: payload.data.civility.type}; }
makeFetch('PATCH', `/api/1.0/person/person/${payload.data.id}.json`, body)
.then(response => {

View File

@@ -14,8 +14,13 @@ const getPersonAltNames = () =>
fetch('/api/1.0/person/config/alt_names.json').then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});;
});
const getCivilities = () =>
fetch('/api/1.0/main/civility.json').then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
/*
* POST a new person
@@ -56,6 +61,7 @@ const patchPerson = (id, body) => {
export {
getPerson,
getPersonAltNames,
getCivilities,
postPerson,
patchPerson
};

View File

@@ -277,12 +277,79 @@ export default {
}
},
saveFormOnTheFly({ type, data }) {
// console.log('saveFormOnTheFly from addPersons, type', type, ', data', data);
console.log('saveFormOnTheFly from addPersons, type', type, ', data', data);
if (type === 'person') {
makeFetch('POST', '/api/1.0/person/person.json', data)
.then(response => {
this.newPriorSuggestion(response);
.then(responsePerson => {
this.newPriorSuggestion(responsePerson);
this.$refs.onTheFly.closeModal();
if (null !== data.addressId) {
const household = {
'type': 'household'
};
const address = {
'id': data.addressId
};
makeFetch('POST', '/api/1.0/person/household.json', household)
.then(responseHousehold => {
const member = {
'concerned': [
{
'person': {
'type': 'person',
'id': responsePerson.id
},
'start_date': {
// TODO: use date.js methods (low priority)
'datetime': `${new Date().toISOString().split('T')[0]}T00:00:00+02:00`
},
'holder': false,
'comment': null
}
],
'destination': {
'type': 'household',
'id': responseHousehold.id
},
'composition': null
};
return makeFetch('POST', '/api/1.0/person/household/members/move.json', member)
.then(_response => {
makeFetch('POST', `/api/1.0/person/household/${responseHousehold.id}/address.json`, address)
.then(_response => {})
.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'});
}
});
})
.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'});
}
});
})
.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'});
}
});
}
})
.catch((error) => {
if (error.name === 'ValidationException') {
@@ -292,7 +359,8 @@ export default {
} else {
this.$toast.open({message: 'An error occurred'});
}
})
});
}
else if (type === 'thirdparty') {
makeFetch('POST', '/api/1.0/thirdparty/thirdparty.json', data)

View File

@@ -87,6 +87,20 @@
<label>{{ $t('person.gender.title') }}</label>
</div>
<div class="form-floating mb-3">
<select
class="form-select form-select-lg"
id="civility"
v-model="civility"
>
<option selected disabled >{{ $t('person.civility.placeholder') }}</option>
<option v-for="c in config.civilities" :value="c.id" :key="c.id">
{{ c.name.fr }}
</option>
</select>
<label>{{ $t('person.civility.title') }}</label>
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="birthdate"><i class="fa fa-fw fa-birthday-cake"></i></span>
<input type="date"
@@ -124,6 +138,24 @@
aria-describedby="email" />
</div>
<div v-if="action === 'create'" class="input-group mb-3 form-check">
<input class="form-check-input"
type='checkbox'
v-model="showAddressForm"
name='showAddressForm'/>
<label class="form-check-label">{{ $t('person.address.show_address_form') }}</label>
</div>
<div v-if="action === 'create' && showAddressFormValue" class="form-floating mb-3">
<p>{{ $t('person.address.warning') }}</p>
<add-address
:context="addAddress.context"
:options="addAddress.options"
:addressChangedCallback="submitNewAddress"
ref="addAddress">
</add-address>
</div>
<div class="alert alert-warning" v-if="errors.length">
<ul>
<li v-for="(e, i) in errors" :key="i">{{ e }}</li>
@@ -134,24 +166,43 @@
</template>
<script>
import { getPerson, getPersonAltNames } from '../../_api/OnTheFly';
import { getCivilities, getPerson, getPersonAltNames } from '../../_api/OnTheFly';
import PersonRenderBox from '../Entity/PersonRenderBox.vue';
import AddAddress from "ChillMainAssets/vuejs/Address/components/AddAddress.vue";
export default {
name: "OnTheFlyPerson",
props: ['id', 'type', 'action', 'query'],
//emits: ['createAction'],
components: {
PersonRenderBox
PersonRenderBox,
AddAddress
},
data() {
return {
person: {
type: 'person',
altNames: []
altNames: [],
addressId: null
},
config: {
altNames: []
altNames: [],
civilities: []
},
showAddressFormValue: false,
addAddress: {
options: {
button: {
text: { create: 'person.address.create_address' },
size: 'btn-sm'
},
title: { create: 'person.address.create_address' },
},
context: {
target: {}, // boilerplate for getting the address id
edit: false,
addressId: null
}
},
errors: []
}
@@ -171,6 +222,10 @@ export default {
set(value) { this.person.gender = value; },
get() { return this.person.gender; }
},
civility: {
set(value) { this.person.civility = {id: value, type: 'chill_main_civility'}; },
get() { return this.person.civility ? this.person.civility.id : null; }
},
birthDate: {
set(value) {
if (this.person.birthdate) {
@@ -195,6 +250,10 @@ export default {
set(value) { this.person.email = value; },
get() { return this.person.email; }
},
showAddressForm: {
set(value) { this.showAddressFormValue = value; },
get() { return this.showAddressFormValue; }
},
genderClass() {
switch (this.person.gender) {
case 'woman':
@@ -230,6 +289,13 @@ export default {
.then(altNames => {
this.config.altNames = altNames;
});
getCivilities()
.then(civilities => {
if ('results' in civilities) {
this.config.civilities = civilities.results;
}
});
if (this.action !== 'create') {
this.loadData();
}
@@ -273,6 +339,9 @@ export default {
this.person.firstName = queryItem;
break;
}
},
submitNewAddress(payload) {
this.person.addressId = payload.addressId;
}
}
}
@@ -293,4 +362,9 @@ dl {
margin-left: 1em;
}
}
div.form-check {
label {
margin-left: 0.5em!important;
}
}
</style>

View File

@@ -38,6 +38,15 @@ const personMessages = {
man: "Masculin",
neuter: "Neutre, non binaire",
undefined: "Non renseigné"
},
civility: {
title: "Civilité",
placeholder: "Choisissez la civilité",
},
address: {
create_address: "Ajouter une adresse",
show_address_form: "Créer un ménage et ajouter une adresse",
warning: "Un nouveau ménage va être créé. L'usager sera membre de ce ménage."
}
},
error_only_one_person: "Une seule personne peut être sélectionnée !"