Merge branch 'issue345_internal_thirdparty_contact' into 'master'

Add contact to thirdparty from within modal

See merge request Chill-Projet/chill-bundles!284
This commit is contained in:
Julien Fastré 2022-02-28 13:28:13 +00:00
commit 8e1f3a5cc0
20 changed files with 358 additions and 103 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to
* date versioning for test releases
## Unreleased
* AddPersons: remove ul-li html tags from AddPersons (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/419)
<!-- write down unreleased development here -->
* [person] Order social issues by the field "ordering" (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/388)
@ -28,6 +29,7 @@ and this project adheres to
* [person]: AddPersons: add suggestion of name when creating new person or thirdparty (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/422)
* [main] Address: fix small bug: when modifying an address without street (isNoAddress), also check errors if street is an empty string as back-end change null value to empty string for street (and streetNumber)
* [main] Address: stronger client-side validation of addresses (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/449)
* [thirdparty] Add a contact to a thirdparty from within onTheFly (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/345)
* [person] accompanying course: filter suggested entities by open participations (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/415)
[activity] can click through the cross icon for removing person in concerned group (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/476)
[activity] correct associated persons by considering only open participations (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/476)
@ -86,7 +88,19 @@ and this project adheres to
* [AddAddress] disable multiselect search, and rely only on most pertinent Cities and Street computed backend
* [fast_actions] improve fast-actions buttons override mechanism, fix https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/413
* [homepage widget] add vue homepage_widget with asynchone loading, give a global view resume of the user concerned actions, notifications, etc.
* [thirdparty] Add a contact to a thirdparty from within onTheFly (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/345)
## Test releases
=======
* [homepage widget] add vue homepage_widget with asynchone loading, give a global view resume of the user concerned actions, notifications, etc.
>>>>>>> issue422_and_others_on_AddPersons
=======
* [homepage widget] add vue homepage_widget with asynchone loading, give a global view resume of the user concerned actions, notifications, etc.
* [thirdparty] Add a contact to a thirdparty from within onTheFly (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/345)
>>>>>>> b0d50d315c8e00959a967badac9cf5057ab2b4bc
### test release 2021-01-31
* [person] accompanying course: optimisation: do not fetch some resources for the banner (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/409)

View File

@ -0,0 +1,24 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Controller;
use Chill\MainBundle\CRUD\Controller\ApiController;
use Chill\MainBundle\Pagination\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
class CivilityApiController extends ApiController
{
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator, $_format)
{
return $query->addOrderBy('e.order', 'ASC');
}
}

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\DependencyInjection;
use Chill\MainBundle\Controller\AddressApiController;
use Chill\MainBundle\Controller\CivilityApiController;
use Chill\MainBundle\Controller\LocationController;
use Chill\MainBundle\Controller\LocationTypeController;
use Chill\MainBundle\Controller\UserController;
@ -559,6 +560,21 @@ class ChillMainExtension extends Extension implements
],
],
],
[
'class' => \Chill\MainBundle\Entity\Civility::class,
'name' => 'civility',
'base_path' => '/api/1.0/main/civility',
'base_role' => 'ROLE_USER',
'controller' => CivilityApiController::class,
'actions' => [
'_index' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true,
],
],
],
],
],
]);
}

View File

@ -17,6 +17,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Table(name="chill_main_civility")
* @ORM\Entity
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={"chill_main_civility": Civility::class})
*/
class Civility
{
@ -29,6 +30,7 @@ class Civility
/**
* @ORM\Column(type="boolean")
* @Serializer\Groups({"read"})
*/
private bool $active = true;

View File

@ -77,14 +77,11 @@ export default {
return this.$refs.castPerson.$data.person;
case 'thirdparty':
let data = this.$refs.castThirdparty.$data.thirdparty;
data.name = data.text;
/*
if (data.address !== undefined && data.address !== null) {
data.address = { id: data.address.address_id }
} else {
data.address = null;
}
*/
return data;
default:

View File

@ -18,7 +18,8 @@
@close="modal.showModal = false">
<template v-slot:header>
<h3 class="modal-title">{{ $t(titleModal) }}</h3>
<h3 v-if="parent" class="modal-title">{{ $t(titleModal, {q: parent.text}) }}</h3>
<h3 v-else class="modal-title">{{ $t(titleModal) }}</h3>
</template>
<template v-slot:body v-if="type === 'person'">
@ -29,10 +30,10 @@
ref="castPerson">
</on-the-fly-person>
<div v-if="hasResourceComment">
<h3>{{ $t('onthefly.resource_comment_title') }}</h3>
<blockquote class="chill-user-quote">
{{ parent.comment }}
</blockquote>
<h3>{{ $t('onthefly.resource_comment_title') }}</h3>
<blockquote class="chill-user-quote">
{{ parent.comment }}
</blockquote>
</div>
</template>
@ -44,13 +45,22 @@
ref="castThirdparty">
</on-the-fly-thirdparty>
<div v-if="hasResourceComment">
<h3>{{ $t('onthefly.resource_comment_title') }}</h3>
<blockquote class="chill-user-quote">
{{ parent.comment }}
</blockquote>
<h3>{{ $t('onthefly.resource_comment_title') }}</h3>
<blockquote class="chill-user-quote">
{{ parent.comment }}
</blockquote>
</div>
</template>
<template v-slot:body v-else-if="parent">
<on-the-fly-thirdparty
:parent="parent"
:action="action"
type="thirdparty"
ref="castThirdparty">
</on-the-fly-thirdparty>
</template>
<template v-slot:body v-else>
<on-the-fly-create
:action="action"
@ -83,6 +93,7 @@ import Modal from 'ChillMainAssets/vuejs/_components/Modal.vue';
import OnTheFlyCreate from './Create.vue';
import OnTheFlyPerson from 'ChillPersonAssets/vuejs/_components/OnTheFly/Person.vue';
import OnTheFlyThirdparty from 'ChillThirdPartyAssets/vuejs/_components/OnTheFly/ThirdParty.vue';
import { postThirdparty } from "ChillThirdPartyAssets/vuejs/_api/OnTheFly";
export default {
name: 'OnTheFly',
@ -105,11 +116,11 @@ export default {
computed: {
hasResourceComment() {
//console.log('hasResourceComment', this.parent);
return (typeof this.parent !== 'undefined' && this.parent !== null)
&& this.action === 'show'
&& this.parent.type === 'accompanying_period_resource'
&& (this.parent.comment !== null && this.parent.comment !== '')
;
return (typeof this.parent !== 'undefined' && this.parent !== null)
&& this.action === 'show'
&& this.parent.type === 'accompanying_period_resource'
&& (this.parent.comment !== null && this.parent.comment !== '')
;
},
classAction() {
switch (this.action) {
@ -119,6 +130,8 @@ export default {
return 'btn-update';
case 'create':
return 'btn-create';
case 'addContact':
return 'btn-tpchild';
}
},
titleAction() {
@ -129,6 +142,8 @@ export default {
return 'action.edit';
case 'create':
return 'action.create';
case 'addContact':
return 'action.addContact';
}
},
titleCreate() {
@ -146,6 +161,8 @@ export default {
return 'onthefly.edit.' + this.type;
case 'create':
return this.titleCreate;
case 'addContact':
return 'onthefly.addContact.title';
}
},
titleMessage() {
@ -179,8 +196,8 @@ export default {
this.modal.showModal = false;
},
openModal() {
//console.log('## OPEN ON THE FLY MODAL');
//console.log('## type:', this.type, ', action:', this.action);
// console.log('## OPEN ON THE FLY MODAL');
// console.log('## type:', this.type, ', action:', this.action);
this.modal.showModal = true;
this.$nextTick(function() {
//this.$refs.search.focus();
@ -190,7 +207,7 @@ export default {
this.$data.action = action;
},
saveAction() {
console.log('saveAction button: create/edit action with', this.type);
// console.log('saveAction button: create/edit action with', this.type);
let
type = this.type,
data = {} ;
@ -202,17 +219,28 @@ export default {
case 'thirdparty':
data = this.$refs.castThirdparty.$data.thirdparty;
/* never executed ? */
break;
default:
if (typeof this.type === 'undefined') { // action=create
type = this.$refs.castNew.radioType;
data = this.$refs.castNew.castDataByType();
if (typeof this.type === 'undefined') { // action=create or addContact
console.log('will rewrite data');
if (this.action === 'addContact') {
type = 'thirdparty'
data = this.$refs.castThirdparty.$data.thirdparty;
console.log('data original', data);
data.parent = {type: "thirdparty", id: this.parent.id};
} else {
type = this.$refs.castNew.radioType;
data = this.$refs.castNew.castDataByType();
console.log(data)
}
} else {
throw 'error with object type';
}
}
console.log('type', type);
console.log('data', data);
// pass datas to parent
this.$emit('saveFormOnTheFly', { type: type, data: data });
},
@ -232,4 +260,8 @@ export default {
a {
cursor: pointer;
}
/* .btn-add-contact {
background-color: pink;
} */
</style>

View File

@ -21,7 +21,13 @@ const ontheflyMessages = {
person: "un nouvel usager",
thirdparty: "un nouveau tiers professionnel"
},
resource_comment_title: "Un commentaire est associé à cet interlocuteur"
addContact: {
title: "Créer un contact pour {q}"
},
resource_comment_title: "Un commentaire est associé à cet interlocuteur",
addContact: {
title: "Créer un contact pour {q}"
}
}
}
}

View File

@ -46,7 +46,8 @@ const messages = {
person: "Quitter la page et ouvrir la fiche de l'usager",
thirdparty: "Quitter la page et voir le tiers",
},
refresh: 'Rafraîchir'
refresh: 'Rafraîchir',
addContact: 'Ajouter un contact'
},
nav: {
next: "Suivant",

View File

@ -788,6 +788,16 @@ paths:
description: "accepted"
403:
description: "unauthorized"
/1.0/main/civility.json:
get:
tags:
- civility
summary: Return all civility types
responses:
200:
description: "ok"
401:
description: "Unauthorized"
/1.0/main/user-job.json:
get:
tags:

View File

@ -159,10 +159,10 @@ export default {
.catch((error) => {
if (error.name === 'ValidationException') {
for (let v of error.violations) {
this.$toast.open({message: v });
this.$toast.open({message: v });
}
} else {
this.$toast.open({message: 'An error occurred'});
this.$toast.open({message: 'An error occurred'});
}
})
}
@ -171,9 +171,7 @@ export default {
body.name = payload.data.text;
body.email = payload.data.email;
body.telephone = payload.data.phonenumber;
body.address = payload.data.address ? { id: payload.data.address.address_id } : null;
console.log('body', body)
body.address = payload.data.address ? { id: payload.data.address.address_id } : null;
makeFetch('PATCH', `/api/1.0/thirdparty/thirdparty/${payload.data.id}.json`, body)
.then(response => {
@ -183,10 +181,10 @@ export default {
.catch((error) => {
if (error.name === 'ValidationException') {
for (let v of error.violations) {
this.$toast.open({message: v });
this.$toast.open({message: v });
}
} else {
this.$toast.open({message: 'An error occurred'});
this.$toast.open({message: 'An error occurred'});
}
})
}

View File

@ -57,6 +57,8 @@
v-bind:item="item"
v-bind:search="search"
v-bind:type="checkUniq"
@saveFormOnTheFly="saveFormOnTheFly"
@newPriorSuggestion="newPriorSuggestion"
@updateSelected="updateSelected">
</person-suggestion>
@ -249,7 +251,7 @@ export default {
}
},
newPriorSuggestion(entity) {
console.log('newPriorSuggestion', entity);
// console.log('newPriorSuggestion', entity);
if (entity !== null) {
let suggestion = {
key: entity.type + entity.id,

View File

@ -18,6 +18,7 @@
<suggestion-third-party
v-if="item.result.type === 'thirdparty'"
@newPriorSuggestion="newPriorSuggestion"
v-bind:item="item">
</suggestion-third-party>
@ -26,10 +27,10 @@
v-bind:item="item">
</suggestion-user>
<suggestion-household
v-if="item.result.type === 'household'"
v-bind:item="item">
</suggestion-household>
<suggestion-household
v-if="item.result.type === 'household'"
v-bind:item="item">
</suggestion-household>
</label>
</div>
@ -54,7 +55,7 @@ export default {
'search',
'type'
],
emits: ['updateSelected'],
emits: ['updateSelected', 'newPriorSuggestion'],
computed: {
selected: {
set(value) {
@ -72,6 +73,9 @@ export default {
methods: {
setValueByType(value, type) {
return (type === 'radio')? [value] : value;
},
newPriorSuggestion(response) {
this.$emit('newPriorSuggestion', response)
}
}
};

View File

@ -2,12 +2,12 @@
<div class="container tpartycontainer">
<div class="tparty-identification">
<span class="name">
{{ item.result.text }}&nbsp;
{{ item.result.text }}&nbsp;
</span>
<span class="location">
<template v-if="hasAddress">
{{ getAddress.text }} -
{{ getAddress.postcode.name }}
{{ getAddress.text }} -
{{ getAddress.postcode.name }}
</template>
</span>
</div>
@ -19,21 +19,28 @@
</div>
<div class="right_actions">
<badge-entity
:entity="item.result"
:options="{ displayLong: true }">
</badge-entity>
<on-the-fly
type="thirdparty"
v-bind:id="item.result.id"
action="show">
</on-the-fly>
<badge-entity
:entity="item.result"
:options="{ displayLong: true }">
</badge-entity>
<on-the-fly v-if="item.result.kind === 'company'"
v-bind:parent="item.result"
@saveFormOnTheFly="saveFormOnTheFly"
action="addContact"
ref="onTheFly"
></on-the-fly>
<on-the-fly
type="thirdparty"
v-bind:id="item.result.id"
action="show">
</on-the-fly>
</div>
</template>
<script>
import OnTheFly from 'ChillMainAssets/vuejs/OnTheFly/components/OnTheFly.vue';
import BadgeEntity from 'ChillMainAssets/vuejs/_components/BadgeEntity.vue';
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
const i18n = {
messages: {
@ -48,36 +55,56 @@ const i18n = {
};
export default {
name: 'SuggestionThirdParty',
components: {
OnTheFly,
BadgeEntity
},
props: ['item'],
i18n,
computed: {
hasAddress() {
if (this.$props.item.result.address !== null) {
return true;
}
if (this.$props.item.result.parent !== null) {
this.$props.item.result.parent.address !== null;
}
},
hasParent() {
return this.$props.item.result.parent !== null;
},
getAddress() {
if (this.$props.item.result.address !== null) {
return this.$props.item.result.address;
}
if (this.$props.item.result.parent.address !== null) {
return this.$props.item.result.parent.address;
}
name: 'SuggestionThirdParty',
components: {
OnTheFly,
BadgeEntity
},
props: ['item'],
emits: ['newPriorSuggestion'],
i18n,
computed: {
hasAddress() {
if (this.$props.item.result.address !== null) {
return true;
}
if (this.$props.item.result.parent !== null) {
this.$props.item.result.parent.address !== null;
}
},
hasParent() {
return this.$props.item.result.parent !== null;
},
getAddress() {
if (this.$props.item.result.address !== null) {
return this.$props.item.result.address;
}
if (this.$props.item.result.parent.address !== null) {
return this.$props.item.result.parent.address;
}
return null;
}
}
return null;
}
},
methods: {
saveFormOnTheFly({data, type}) {
makeFetch('POST', '/api/1.0/thirdparty/thirdparty.json', data)
.then(response => {
this.$emit('newPriorSuggestion', response);
this.$refs.onTheFly.closeModal();
})
.catch((error) => {
if (error.name === 'ValidationException') {
for (let v of error.violations) {
this.$toast.open({message: v });
}
} else {
this.$toast.open({message: 'An error occurred'});
}
})
}
}
}
</script>

View File

@ -126,6 +126,21 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
],
],
],
[
'class' => \Chill\ThirdPartyBundle\Entity\ThirdPartyProfession::class,
// 'controller' => \Chill\MainBundle\Controller\ProfessionApiController::class,
'name' => 'profession',
'base_path' => '/api/1.0/thirdparty/professions',
'base_role' => 'ROLE_USER',
'actions' => [
'_index' => [
'methods' => [
Request::METHOD_GET => true,
Request::METHOD_HEAD => true,
],
],
],
],
],
]);
}

View File

@ -161,13 +161,14 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var Civility
* @ORM\ManyToOne(targetEntity=Civility::class)
* ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true)
* @Groups({"docgen:read", "read", "docgen:read:3party:parent"})
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/
private ?Civility $civility = null;
/**
* @ORM\Column(name="comment", type="text", nullable=true)
* @Groups({"read", "write"})
*/
private ?string $comment = null;
@ -200,7 +201,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
* @Groups({"read", "docgen:read", "docgen:read:3party:parent"})
*/
private ?int $id = null;
@ -235,7 +236,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
*
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
* @Groups({"read", "docgen:read"})
* @Groups({"read", "write", "docgen:read"})
* @Context(normalizationContext={"groups": "docgen:read:3party:parent"}, groups={"docgen:read"})
*/
private ?ThirdParty $parent = null;
@ -246,7 +247,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @var ThirdPartyProfession
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession")
* ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true)
* @Groups({"docgen:read", "docgen:read:3party:parent"})
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/
private ?ThirdPartyProfession $profession = null;
@ -706,7 +707,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
/**
* @return $this
*/
public function setCivility(Civility $civility): ThirdParty
public function setCivility(?Civility $civility): ThirdParty
{
$this->civility = $civility;
@ -811,7 +812,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
/**
* @return $this
*/
public function setProfession(ThirdPartyProfession $profession): ThirdParty
public function setProfession(?ThirdPartyProfession $profession): ThirdParty
{
$this->profession = $profession;

View File

@ -18,11 +18,14 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Table(name="chill_3party.party_profession")
* @ORM\Entity(repositoryClass=ThirdPartyProfessionRepository::class)
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "third_party_profession": ThirdPartyProfession::class})
*/
class ThirdPartyProfession
{
/**
* @ORM\Column(type="boolean")
* @Serializer\Groups({"read"})
*/
private bool $active = true;
@ -30,13 +33,13 @@ class ThirdPartyProfession
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"docgen:read"})
* @Serializer\Groups({"docgen:read", "read", "write"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
* @Serializer\Groups({"docgen:read"})
* @Serializer\Groups({"docgen:read", "read"})
*/
private array $name = [];

View File

@ -19,9 +19,15 @@
></third-party-render-box>
</div>
</div>
<div v-else-if="action === 'edit' || action === 'create'">
<div class="form-floating mb-3" v-if="thirdparty.kind !== 'child'">
<div v-else-if="action === 'edit' || action === 'create' || action === 'addContact'">
<div v-if="parent">
<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="kind !== 'child'">
<div class="form-check">
<input class="form-check-input mt-0" type="radio" v-model="kind" value="company" id="tpartyKindInstitution">
<label for="tpartyKindInstitution" class="required">
@ -55,10 +61,30 @@
addCenter: false,
addNoData: true,
isMultiline: false
}"></third-party-render-box>
}"></third-party-render-box>
</div>
<div v-if="thirdparty.kind === 'child' || thirdparty.kind === 'contact'">
<div id="child-info">
<div class="input-group mb-3">
<select class="form-select form-select-lg" id="profession"
v-model="thirdparty.civility">
<option selected disabled :value="null" >{{ $t('thirdparty.civility') }}</option>
<option v-for="civility in civilities" :key="civility.id" :value="{type: 'chill_main_civility', id: civility.id }">{{ civility.name.fr }}</option>
</select>
</div>
<div class="input-group mb-3">
<select class="form-select form-select-lg" id="civility"
v-model="thirdparty.profession">
<option selected disabled :value="null">{{ $t('thirdparty.profession') }}</option>
<option v-for="profession in professions" :key="profession.id" :value="{type: 'third_party_profession', id: profession.id }">{{ profession.name.fr }}</option>
</select>
</div>
</div>
</div>
<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.name" v-bind:placeholder="$t('thirdparty.name')" />
<label for="name">{{ $t('thirdparty.name') }}</label>
</div>
<div v-if="query">
@ -98,6 +124,15 @@
aria-describedby="phonenumber" />
</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')"
v-model="thirdparty.comment"
></textarea>
</div>
</div>
</div>
</template>
@ -106,10 +141,11 @@ import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue';
import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress';
import { getThirdparty } from '../../_api/OnTheFly';
import BadgeEntity from 'ChillMainAssets/vuejs/_components/BadgeEntity.vue';
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
export default {
name: "OnTheFlyThirdParty",
props: ['id', 'type', 'action', 'query'],
props: ['id', 'type', 'action', 'query', 'parent'],
components: {
ThirdPartyRenderBox,
AddAddress,
@ -124,8 +160,11 @@ export default {
kind: 'company',
name: '',
telephone: '',
civility: null,
profession: null,
},
professions: [],
civilities: [],
addAddress: {
options: {
openPanesInModal: true,
@ -177,10 +216,10 @@ export default {
},
methods: {
loadData(){
getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => {
return getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => {
this.thirdparty = thirdparty;
this.thirdparty.kind = thirdparty.kind;
//console.log('get thirdparty', thirdparty);
console.log('get thirdparty', thirdparty);
if (this.action !== 'show') {
if (thirdparty.address !== null) {
// bof! we force getInitialAddress because addressId not available when mounted
@ -190,6 +229,30 @@ export default {
resolve();
}));
},
loadCivilities() {
const url = `/api/1.0/main/civility.json`;
return makeFetch('GET', url)
.then(response => {
this.$data.civilities = response.results;
return Promise.resolve();
})
.catch((error) => {
console.log(error)
this.$toast.open({message: error.body})
})
},
loadProfessions() {
const url = `/api/1.0/thirdparty/professions.json`;
return makeFetch('GET', url)
.then(response => {
this.$data.professions = response.results;
return Promise.resolve();
})
.catch((error) => {
console.log(error)
this.$toast.open({message: error.body})
})
},
submitAddress(payload) {
console.log('submitAddress', payload);
if (typeof payload.addressId !== 'undefined') { // <--
@ -200,13 +263,24 @@ export default {
}
},
addQuery(query) {
this.thirdparty.text = query;
}
this.thirdparty.name = query;
},
},
mounted() {
//console.log('mounted', this.action);
mounted() {
let dependencies = [];
dependencies.push(this.loadProfessions());
dependencies.push(this.loadCivilities());
if (this.action !== 'create') {
this.loadData();
if (this.id) {
dependencies.push(this.loadData());
// here we can do something when all promises are resolve, with
// Promise.all(dependencies).then(() => { /* do something */ });
}
if (this.action === 'addContact') {
this.$data.thirdparty.kind = 'child'
// this.$data.thirdparty.parent = this.parent.id
this.$data.thirdparty.address = null
}
} else {
this.thirdparty.kind = 'company';
}
@ -229,5 +303,16 @@ dl {
margin-left: 1em;
}
}
.parent-info {
margin-bottom: 1rem;
}
#child-info {
display: flex;
justify-content: space-between;
div {
width: 49%;
}
}
</style>

View File

@ -4,7 +4,12 @@ const thirdpartyMessages = {
name: "Dénomination",
email: "Courriel",
phonenumber: "Téléphone",
}
comment: "Commentaire",
profession: "Qualité",
civility: "Civilité"
},
child_of: "Contact de: ",
children: "Personnes de contact: ",
}
};

View File

@ -36,6 +36,7 @@ class ThirdPartyNormalizer implements NormalizerAwareInterface, NormalizerInterf
{
return [
'type' => 'thirdparty',
'name' => $thirdParty->getName(),
'text' => $this->thirdPartyRender->renderString($thirdParty, []),
'id' => $thirdParty->getId(),
'kind' => $thirdParty->getKind(),
@ -45,6 +46,7 @@ class ThirdPartyNormalizer implements NormalizerAwareInterface, NormalizerInterf
'isChild' => $thirdParty->isChild(),
'parent' => $this->normalizer->normalize($thirdParty->getParent(), $format, $context),
'civility' => $this->normalizer->normalize($thirdParty->getCivility(), $format, $context),
'profession' => $this->normalizer->normalize($thirdParty->getProfession(), $format, $context),
'contactDataAnonymous' => $thirdParty->isContactDataAnonymous(),
];
}

View File

@ -110,3 +110,14 @@ paths:
description: "OK"
422:
description: "Object with validation errors"
/1.0/thirdparty/professions.json:
get:
tags:
- thirdparty
summary: Return all thirdparty professions
responses:
200:
description: "ok"
401:
description: "Unauthorized"