onTheFly modal to add contact to thirdparty - form fields for profession,civility, and comment added - no saving possible yet

This commit is contained in:
Julie Lenaerts 2022-01-13 14:35:53 +01:00
parent c4a859f2d2
commit 95547e961e
3 changed files with 119 additions and 56 deletions

View File

@ -51,13 +51,12 @@
</div> </div>
</template> </template>
<template v-slot:body v-else-if="action === 'addContact'"> <template v-slot:body v-else-if="parent">
<on-the-fly-thirdparty <on-the-fly-thirdparty
:parent="parent" :parent="parent"
:action="action"
type="thirdparty" type="thirdparty"
action="create" ref="castNew">
kind="child"
ref="castThirdparty">
</on-the-fly-thirdparty> </on-the-fly-thirdparty>
</template> </template>
@ -139,6 +138,8 @@ export default {
return 'action.edit'; return 'action.edit';
case 'create': case 'create':
return 'action.create'; return 'action.create';
case 'addContact':
return 'action.addContact';
} }
}, },
titleModal() { titleModal() {
@ -149,6 +150,8 @@ export default {
return 'onthefly.edit.' + this.type; return 'onthefly.edit.' + this.type;
case 'create': case 'create':
return 'onthefly.create.title'; return 'onthefly.create.title';
case 'addContact':
return 'onthefly.addContact.title';
} }
}, },
titleMessage() { titleMessage() {
@ -231,4 +234,8 @@ export default {
a { a {
cursor: pointer; cursor: pointer;
} }
/* .btn-add-contact {
background-color: pink;
} */
</style> </style>

View File

@ -24,8 +24,8 @@
:options="{ displayLong: true }"> :options="{ displayLong: true }">
</badge-entity> </badge-entity>
<on-the-fly <on-the-fly
v-bind:parent="item.result"
action="addContact" action="addContact"
:parent="item.result"
></on-the-fly> ></on-the-fly>
<on-the-fly <on-the-fly
type="thirdparty" type="thirdparty"

View File

@ -19,9 +19,15 @@
></third-party-render-box> ></third-party-render-box>
</div> </div>
</div> </div>
<div v-else-if="action === 'edit' || action === 'create'"> <div v-else-if="action === 'edit' || action === 'create' || action === 'addContact'">
<div v-if="parent">
<div class="form-floating mb-3" v-if="thirdparty.kind !== 'child'"> <div class="parent-info">
<i class="fa fa-li fa-hand-o-right"></i>
<b class="me-2">{{ $t('child_of') }}</b>
<span class="chill-entity badge-thirdparty">{{ parent.text }}</span>
</div>
</div>
<div class="form-floating mb-3" v-else-if="thirdparty.kind !== 'child'">
<div class="form-check"> <div class="form-check">
<input class="form-check-input mt-0" type="radio" v-model="kind" value="company" id="tpartyKindInstitution"> <input class="form-check-input mt-0" type="radio" v-model="kind" value="company" id="tpartyKindInstitution">
<label for="tpartyKindInstitution" class="required"> <label for="tpartyKindInstitution" class="required">
@ -42,23 +48,9 @@
</div> </div>
</div> </div>
<div v-else> <div v-else>
<p>Contact de&nbsp;:</p> <!-- <p>Contact de&nbsp;:</p> -->
<third-party-render-box v-if="thirdparty.parent" <third-party-render-box
:thirdparty="thirdparty.parent" :thirdparty="thirdparty"
:options="{
addInfo: true,
addEntity: false,
addAltNames: true,
addId: false,
addLink: false,
addAge: false,
hLevel: 4,
addCenter: false,
addNoData: true,
isMultiline: false
}"></third-party-render-box>
<third-party-render-box v-else
:thirdparty="parent"
:options="{ :options="{
addInfo: true, addInfo: true,
addEntity: false, addEntity: false,
@ -72,13 +64,31 @@
isMultiline: false isMultiline: false
}"></third-party-render-box> }"></third-party-render-box>
</div> </div>
<div v-if="parent" id="child-info">
<div class="input-group mb-3">
<span class="input-group-text" id="comment"><i class="fa fa-fw fa-user-circle-o"></i></span>
<select class="form-select form-select-lg" id="civility">
<option selected disabled >{{ $t('thirdparty.profession') }}</option>
<option v-for="profession in professions" :key="profession.id" :value="profession.id">{{ profession.name.fr }}</option>
</select>
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="comment"><i class="fa fa-fw fa-briefcase"></i></span>
<select class="form-select form-select-lg" id="profession">
<option selected disabled >{{ $t('thirdparty.civility') }}</option>
<option v-for="civility in civilities" :key="civility.id" :value="civility.id">{{ civility.name.fr }}</option>
</select>
</div>
</div>
<div class="form-floating mb-3"> <div class="form-floating mb-3">
<input class="form-control form-control-lg" id="name" v-model="thirdparty.text" v-bind:placeholder="$t('thirdparty.name')" /> <input class="form-control form-control-lg" id="name" v-model="thirdparty.text" v-bind:placeholder="$t('thirdparty.name')" />
<label for="name">{{ $t('thirdparty.name') }}</label> <label for="name">{{ $t('thirdparty.name') }}</label>
</div> </div>
<template <template
v-if="thirdparty.kind !== 'child'"> v-if="thirdparty.kind !== 'child' || parent">
<add-address <add-address
key="thirdparty" key="thirdparty"
:context="context" :context="context"
@ -106,6 +116,14 @@
aria-describedby="phonenumber" /> aria-describedby="phonenumber" />
</div> </div>
<div v-if="parent">
<div class="input-group mb-3">
<span class="input-group-text" id="comment"><i class="fa fa-fw fa-pencil"></i></span>
<textarea class="form-control form-control-lg"
v-bind:placeholder="$t('thirdparty.comment')"
></textarea>
</div>
</div>
</div> </div>
</template> </template>
@ -114,10 +132,11 @@ import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue';
import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress'; import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress';
import { getThirdparty } from '../../_api/OnTheFly'; import { getThirdparty } from '../../_api/OnTheFly';
import BadgeEntity from 'ChillMainAssets/vuejs/_components/BadgeEntity.vue'; import BadgeEntity from 'ChillMainAssets/vuejs/_components/BadgeEntity.vue';
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
export default { export default {
name: "OnTheFlyThirdParty", name: "OnTheFlyThirdParty",
props: ['id', 'type', 'action'], props: ['id', 'type', 'action', 'parent'],
components: { components: {
ThirdPartyRenderBox, ThirdPartyRenderBox,
AddAddress, AddAddress,
@ -129,6 +148,8 @@ export default {
thirdparty: { thirdparty: {
type: 'thirdparty', type: 'thirdparty',
}, },
professions: [],
civilities: [],
addAddress: { addAddress: {
options: { options: {
openPanesInModal: true, openPanesInModal: true,
@ -137,27 +158,27 @@ export default {
size: 'btn-sm' size: 'btn-sm'
}, },
title: { title: {
create: 'add_an_address_title', create: 'add_an_address_title',
edit: 'edit_address' edit: 'edit_address'
} }
} }
} }
} }
}, },
computed: { computed: {
kind: { kind: {
get() { get() {
// note: there are also default to 'institution' set in the "mounted" method // note: there are also default to 'institution' set in the "mounted" method
if (this.$data.thirdparty.kind !== undefined) { if (this.$data.thirdparty.kind !== undefined) {
return this.$data.thirdparty.kind; return this.$data.thirdparty.kind;
} else { } else {
return 'company'; return 'company';
} }
}, },
set(v) { set(v) {
this.$data.thirdparty.kind = v; this.$data.thirdparty.kind = v;
} }
}, },
context() { context() {
let context = { let context = {
target: { target: {
@ -168,10 +189,10 @@ export default {
addressId: null addressId: null
}; };
if ( !(this.thirdparty.address === undefined || this.thirdparty.address === null) if ( !(this.thirdparty.address === undefined || this.thirdparty.address === null)
&& this.thirdparty.address.address_id !== null && this.thirdparty.address.address_id !== null
) { // to complete ) { // to complete
context.addressId = this.thirdparty.address.address_id; context.addressId = this.thirdparty.address.address_id;
context.edit = true; context.edit = true;
} }
console.log('context', context); console.log('context', context);
//this.context = context; <-- //this.context = context; <--
@ -185,30 +206,58 @@ export default {
this.thirdparty.kind = thirdparty.kind; this.thirdparty.kind = thirdparty.kind;
//console.log('get thirdparty', thirdparty); //console.log('get thirdparty', thirdparty);
if (this.action !== 'show') { if (this.action !== 'show') {
if (thirdparty.address !== null) { if (thirdparty.address !== null) {
// bof! we force getInitialAddress because addressId not available when mounted // bof! we force getInitialAddress because addressId not available when mounted
this.$refs.addAddress.getInitialAddress(thirdparty.address.address_id); this.$refs.addAddress.getInitialAddress(thirdparty.address.address_id);
} }
} }
resolve(); resolve();
})); }));
}, },
loadCivilities() {
const url = `/api/1.0/main/civility.json`;
makeFetch('GET', url)
.then(response => {
console.log(response)
this.$data.civilities = response.results;
})
.catch((error) => {
console.log(error)
// this.$toast.open({message: error.body})
})
},
loadProfessions() {
const url = `/api/1.0/thirdparty/professions.json`;
makeFetch('GET', url)
.then(response => {
console.log(response)
this.$data.professions = response.results;
})
.catch((error) => {
console.log(error)
// this.$toast.open({message: error.body})
})
},
submitAddress(payload) { submitAddress(payload) {
console.log('submitAddress', payload); console.log('submitAddress', payload);
if (typeof payload.addressId !== 'undefined') { // <-- if (typeof payload.addressId !== 'undefined') { // <--
this.context.edit = true; this.context.edit = true;
this.context.addressId = payload.addressId; // bof! use legacy and not legacy in payload this.context.addressId = payload.addressId; // bof! use legacy and not legacy in payload
this.thirdparty.address = payload.address; // <-- this.thirdparty.address = payload.address; // <--
console.log('switch address to edit mode', this.context); console.log('switch address to edit mode', this.context);
} }
} }
}, },
mounted() { mounted() {
//console.log('mounted', this.action); console.log('mounted', this.action);
if (this.action !== 'create') { if (this.action !== 'create') {
this.loadData(); this.loadData();
if (this.action === 'addContact') {
this.loadProfessions();
this.loadCivilities();
}
} else { } else {
this.thirdparty.kind = 'company'; this.thirdparty.kind = 'company';
} }
}, },
} }
@ -229,5 +278,12 @@ dl {
margin-left: 1em; margin-left: 1em;
} }
} }
.parent-info {
margin-bottom: 1rem;
}
#child-info {
display: flex;
}
</style> </style>