Integrate gender entity into vue components upon creation of persons

This commit is contained in:
Julie Lenaerts 2024-10-01 12:15:56 +02:00
parent 37cfc035a3
commit d9dc2d1f4e
3 changed files with 19 additions and 13 deletions

View File

@ -128,7 +128,7 @@ export default {
body.mobilenumber = payload.data.mobilenumber; body.mobilenumber = payload.data.mobilenumber;
body.email = payload.data.email; body.email = payload.data.email;
body.altNames = payload.data.altNames; body.altNames = payload.data.altNames;
body.gender = payload.data.gender; body.gender = {id: payload.data.gender.id, type: payload.data.gender.type };
if (payload.data.civility !== null) { body.civility = {id: payload.data.civility.id, type: payload.data.civility.type }; } 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) makeFetch('PATCH', `/api/1.0/person/person/${payload.data.id}.json`, body)

View File

@ -153,7 +153,7 @@ export default {
body.mobilenumber = payload.data.mobilenumber; body.mobilenumber = payload.data.mobilenumber;
body.email = payload.data.email; body.email = payload.data.email;
body.altNames = payload.data.altNames; body.altNames = payload.data.altNames;
body.gender = payload.data.gender; body.gender = {id: payload.data.gender.id, type: payload.data.gender.type };
if (payload.data.civility !== null) { body.civility = {id: payload.data.civility.id, type: payload.data.civility.type}; } 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) makeFetch('PATCH', `/api/1.0/person/person/${payload.data.id}.json`, body)

View File

@ -73,17 +73,16 @@
<!-- TODO fix placeholder if undefined <!-- TODO fix placeholder if undefined
--> -->
<div class="form-floating mb-3"> <div class="form-floating mb-3">
<select <select
class="form-select form-select-lg" class="form-select form-select-lg"
id="gender" id="gender"
v-model="gender" v-model="gender"
@change="checkErrors" >
> <option selected disabled >{{ $t('person.gender.placeholder') }}</option>
<option selected disabled >{{ $t('person.gender.placeholder') }}</option> <option v-for="g in config.genders" :value="g.id" :key="g.id">
<option value="woman">{{ $t('person.gender.woman') }}</option> {{ g.label.fr }}
<option value="man">{{ $t('person.gender.man') }}</option> </option>
<option value="both">{{ $t('person.gender.both') }}</option> </select>
</select>
<label>{{ $t('person.gender.title') }}</label> <label>{{ $t('person.gender.title') }}</label>
</div> </div>
@ -178,7 +177,7 @@
</template> </template>
<script> <script>
import { getCentersForPersonCreation, getCivilities, getPerson, getPersonAltNames } from '../../_api/OnTheFly'; import { getCentersForPersonCreation, getCivilities, getGenders, getPerson, getPersonAltNames } from '../../_api/OnTheFly';
import PersonRenderBox from '../Entity/PersonRenderBox.vue'; import PersonRenderBox from '../Entity/PersonRenderBox.vue';
import AddAddress from "ChillMainAssets/vuejs/Address/components/AddAddress.vue"; import AddAddress from "ChillMainAssets/vuejs/Address/components/AddAddress.vue";
@ -204,6 +203,7 @@ export default {
altNames: [], altNames: [],
civilities: [], civilities: [],
centers: [], centers: [],
genders: []
}, },
showCenters: false, // NOTE: must remains false if the form is not in create mode showCenters: false, // NOTE: must remains false if the form is not in create mode
showAddressFormValue: false, showAddressFormValue: false,
@ -237,8 +237,8 @@ export default {
get() { return this.person.lastName; } get() { return this.person.lastName; }
}, },
gender: { gender: {
set(value) { this.person.gender = value; }, set(value) { this.person.gender = {id: value, type: 'chill_main_gender'}; },
get() { return this.person.gender; } get() { return this.person.gender ? this.person.gender.id : null; }
}, },
civility: { civility: {
set(value) { this.person.civility = {id: value, type: 'chill_main_civility'}; }, set(value) { this.person.civility = {id: value, type: 'chill_main_civility'}; },
@ -334,6 +334,12 @@ export default {
this.config.civilities = civilities.results; this.config.civilities = civilities.results;
} }
}); });
getGenders()
.then(genders => {
if ('results' in genders) {
this.config.genders = genders.results;
}
});
if (this.action !== 'create') { if (this.action !== 'create') {
this.loadData(); this.loadData();
} else { } else {