AddPerson: add civility when creating a person

This commit is contained in:
nobohan 2022-04-14 18:04:36 +02:00
parent c1ec2933e5
commit 7a2151f23a
5 changed files with 41 additions and 6 deletions

View File

@ -210,7 +210,6 @@ export default {
let let
type = this.type, type = this.type,
data = {} ; data = {} ;
switch (type) { switch (type) {
case 'person': case 'person':
data = this.$refs.castPerson.$data.person; data = this.$refs.castPerson.$data.person;
@ -238,7 +237,7 @@ export default {
if (typeof data.civility !== 'undefined' && null !== data.civility) { if (typeof data.civility !== 'undefined' && null !== data.civility) {
data.civility = data.civility !== null ? {type: 'chill_main_civility', id: data.civility.id} : null; data.civility = data.civility !== null ? {type: 'chill_main_civility', id: data.civility.id} : null;
} }
if (typeof data.civility !== 'undefined' && null !== data.profession) { if (typeof data.profession !== 'undefined' && null !== data.profession) {
data.profession = data.profession !== null ? {type: 'third_party_profession', id: data.profession.id} : null; data.profession = data.profession !== null ? {type: 'third_party_profession', id: data.profession.id} : null;
} }
// console.log('onthefly data', data); // console.log('onthefly data', data);

View File

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

View File

@ -277,7 +277,7 @@ export default {
} }
}, },
saveFormOnTheFly({ type, data }) { saveFormOnTheFly({ type, data }) {
// console.log('saveFormOnTheFly from addPersons, type', type, ', data', data); console.log('saveFormOnTheFly from addPersons, type', type, ', data', data);
if (type === 'person') { if (type === 'person') {
makeFetch('POST', '/api/1.0/person/person.json', data) makeFetch('POST', '/api/1.0/person/person.json', data)
.then(response => { .then(response => {

View File

@ -87,6 +87,20 @@
<label>{{ $t('person.gender.title') }}</label> <label>{{ $t('person.gender.title') }}</label>
</div> </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"> <div class="input-group mb-3">
<span class="input-group-text" id="birthdate"><i class="fa fa-fw fa-birthday-cake"></i></span> <span class="input-group-text" id="birthdate"><i class="fa fa-fw fa-birthday-cake"></i></span>
<input type="date" <input type="date"
@ -134,7 +148,7 @@
</template> </template>
<script> <script>
import { getPerson, getPersonAltNames } from '../../_api/OnTheFly'; import { getCivilities, getPerson, getPersonAltNames } from '../../_api/OnTheFly';
import PersonRenderBox from '../Entity/PersonRenderBox.vue'; import PersonRenderBox from '../Entity/PersonRenderBox.vue';
export default { export default {
@ -151,7 +165,8 @@ export default {
altNames: [] altNames: []
}, },
config: { config: {
altNames: [] altNames: [],
civilities: []
}, },
errors: [] errors: []
} }
@ -171,6 +186,10 @@ export default {
set(value) { this.person.gender = value; }, set(value) { this.person.gender = value; },
get() { return this.person.gender; } get() { return this.person.gender; }
}, },
civility: {
set(value) { this.person.civility = value; },
get() { return this.person.civility; }
},
birthDate: { birthDate: {
set(value) { set(value) {
if (this.person.birthdate) { if (this.person.birthdate) {
@ -230,6 +249,13 @@ export default {
.then(altNames => { .then(altNames => {
this.config.altNames = altNames; this.config.altNames = altNames;
}); });
getCivilities()
.then(civilities => {
if ('results' in civilities) {
this.config.civilities = civilities.results;
}
});
if (this.action !== 'create') { if (this.action !== 'create') {
this.loadData(); this.loadData();
} }

View File

@ -38,6 +38,10 @@ const personMessages = {
man: "Masculin", man: "Masculin",
neuter: "Neutre, non binaire", neuter: "Neutre, non binaire",
undefined: "Non renseigné" undefined: "Non renseigné"
},
civility: {
title: "Civilité",
placeholder: "Choisissez la civilité",
} }
}, },
error_only_one_person: "Une seule personne peut être sélectionnée !" error_only_one_person: "Une seule personne peut être sélectionnée !"