From d7ae279101d04878b342c9e72361fd2abb7ce1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 11 Oct 2021 14:03:46 +0200 Subject: [PATCH] Create thirdparty on the fly with institution / contact --- .../vuejs/OnTheFly/components/Create.vue | 7 ++- .../Entity/ThirdParty.php | 11 ++--- .../vuejs/_components/OnTheFly/ThirdParty.vue | 43 ++++++++++++++++++- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/Create.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/Create.vue index f8d221674..24f69a9fe 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/Create.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/Create.vue @@ -74,7 +74,12 @@ export default { case 'thirdparty': let data = this.$refs.castThirdparty.$data.thirdparty; data.name = data.text; - data.address = { id: data.address.address_id } + if (data.address !== undefined) { + data.address = { id: data.address.address_id } + } else { + data.address = null; + } + return data; default: throw Error('Invalid type of entity') diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index f2dd0301e..b309c4542 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -65,6 +65,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface /** * @ORM\Column(name="kind", type="string", length="20", options={"default":""}) + * @Groups({"write"}) */ private ?string $kind = ""; @@ -133,14 +134,14 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface * @ORM\JoinColumn(name="parent_id", referencedColumnName="id") * @Groups({"read"}) */ - private ?ThirdParty $parent; + private ?ThirdParty $parent = null; /** * @var Civility * @ORM\ManyToOne(targetEntity=Civility::class) * ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true) */ - private ?Civility $civility; + private ?Civility $civility = null; /** * [fr] Qualité @@ -148,7 +149,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface * @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyProfession") * ORM\JoinColumn(name="profession", referencedColumnName="id", nullable=true) */ - private ?ThirdPartyProfession $profession; + private ?ThirdPartyProfession $profession = null; /** * @var string|null @@ -463,10 +464,10 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface } /** - * @param Address $address + * @param Address|null $address * @return $this */ - public function setAddress(Address $address) + public function setAddress(?Address $address = null) { $this->address = $address; diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue index 21b79a1c7..401cf1fa8 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue @@ -20,6 +20,20 @@
+
+
+ + +
+
+ + +
+
@@ -59,6 +73,17 @@ import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue'; import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress'; import { getThirdparty } from '../../_api/OnTheFly'; +const i18n = { + messages: { + fr: { + tparty: { + contact: "Contact", + company: "Institution" + } + } + } +}; + export default { name: "OnTheFlyThirdParty", props: ['id', 'type', 'action'], @@ -66,11 +91,12 @@ export default { ThirdPartyRenderBox, AddAddress }, + i18n, data() { return { //context: {}, <-- thirdparty: { - type: 'thirdparty' + type: 'thirdparty', }, addAddress: { options: { @@ -88,6 +114,19 @@ export default { } }, computed: { + kind: { + get() { + // note: there are also default to 'institution' set in the "mounted" method + if (this.$data.thirdparty.kind !== undefined) { + return this.$data.thirdparty.kind; + } else { + return 'company'; + } + }, + set(v) { + this.$data.thirdparty.kind = v; + } + }, context() { let context = { target: { @@ -133,6 +172,8 @@ export default { mounted() { if (this.action !== 'create') { this.loadData(); + } else { + this.thirdparty.kind = 'company'; } }, }