person: add address when creating a person

This commit is contained in:
nobohan 2022-04-15 11:11:41 +02:00
parent 946ae31d11
commit ae45f5f40b
4 changed files with 43 additions and 2 deletions

View File

@ -240,6 +240,13 @@ export default {
if (typeof data.profession !== 'undefined' && null !== data.profession) {
data.profession = data.profession !== null ? {type: 'third_party_profession', id: data.profession.id} : null;
}
if (null !== data.addressId) {
console.log(data)
//TODO make a good address object
// attach the addressId
// test if this condition is safe
}
// console.log('onthefly data', data);
}
} else {

View File

@ -278,6 +278,7 @@ export default {
},
saveFormOnTheFly({ type, data }) {
console.log('saveFormOnTheFly from addPersons, type', type, ', data', data);
//TODO: create a household if address in data.
if (type === 'person') {
makeFetch('POST', '/api/1.0/person/person.json', data)
.then(response => {

View File

@ -138,6 +138,16 @@
aria-describedby="email" />
</div>
<div v-if="action === 'create'" class="form-floating mb-3">
<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>
@ -150,24 +160,41 @@
<script>
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: [],
civilities: []
},
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: []
}
},
@ -299,6 +326,9 @@ export default {
this.person.firstName = queryItem;
break;
}
},
submitNewAddress(payload) {
this.person.addressId = payload.addressId;
}
}
}

View File

@ -42,6 +42,9 @@ const personMessages = {
civility: {
title: "Civilité",
placeholder: "Choisissez la civilité",
},
address: {
create_address: "Ajouter une adresse"
}
},
error_only_one_person: "Une seule personne peut être sélectionnée !"