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) { 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;
} }
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); // console.log('onthefly data', data);
} }
} else { } else {

View File

@ -278,6 +278,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);
//TODO: create a household if address in 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

@ -138,6 +138,16 @@
aria-describedby="email" /> aria-describedby="email" />
</div> </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"> <div class="alert alert-warning" v-if="errors.length">
<ul> <ul>
<li v-for="(e, i) in errors" :key="i">{{ e }}</li> <li v-for="(e, i) in errors" :key="i">{{ e }}</li>
@ -150,24 +160,41 @@
<script> <script>
import { getCivilities, getPerson, getPersonAltNames } from '../../_api/OnTheFly'; import { getCivilities, 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";
export default { export default {
name: "OnTheFlyPerson", name: "OnTheFlyPerson",
props: ['id', 'type', 'action', 'query'], props: ['id', 'type', 'action', 'query'],
//emits: ['createAction'], //emits: ['createAction'],
components: { components: {
PersonRenderBox PersonRenderBox,
AddAddress
}, },
data() { data() {
return { return {
person: { person: {
type: 'person', type: 'person',
altNames: [] altNames: [],
addressId: null
}, },
config: { config: {
altNames: [], altNames: [],
civilities: [] 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: [] errors: []
} }
}, },
@ -299,6 +326,9 @@ export default {
this.person.firstName = queryItem; this.person.firstName = queryItem;
break; break;
} }
},
submitNewAddress(payload) {
this.person.addressId = payload.addressId;
} }
} }
} }

View File

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