From 94c9505c05b3fa51094115a8541c4060b2fa0dcb Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 19 Jan 2022 09:48:39 +0100 Subject: [PATCH] js files put in place + select menus added for selecting person/thirdparty/... show-hide not working yet --- .../Controller/PersonResourceController.php | 24 ++++++++++- .../Entity/Person/PersonResourceKind.php | 10 ++--- .../Form/PersonResourceType.php | 40 ++++++++++++++++--- .../public/page/person_resource/index.js | 33 +++++++++++++++ .../views/PersonResource/create.html.twig | 14 ++++++- .../views/PersonResource/list.html.twig | 6 ++- .../ChillPersonBundle/chill.webpack.config.js | 1 + .../translations/messages.fr.yml | 4 +- 8 files changed, 116 insertions(+), 16 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/page/person_resource/index.js diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php index 6db871e5b..799967c82 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php @@ -11,30 +11,50 @@ declare(strict_types=1); namespace Chill\PersonBundle\Controller; +use Chill\PersonBundle\Entity\Person\PersonResource; use Chill\PersonBundle\Form\PersonResourceType; use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Repository\PersonResourceRepository; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; final class PersonResourceController extends AbstractController { private PersonResourceRepository $personResourceRepository; + private PersonRepository $personRepository; + private EntityManagerInterface $em; public function __construct( PersonResourceRepository $personResourceRepository, - PersonRepository $personRepository + PersonRepository $personRepository, + EntityManagerInterface $em ) { $this->personResourceRepository = $personResourceRepository; $this->personRepository = $personRepository; + $this->em = $em; } - public function listAction($person_id) + public function listAction(Request $request, $person_id) { $person = $this->personRepository->find($person_id); + $personResource = new PersonResource(); $form = $this->createForm(PersonResourceType::class); + $form->handleRequest($request); + + if ($request->getMethod() === Request::METHOD_POST && $form->isValid()) { + $this->em->persist($personResource); + $this->em->flush(); + + return $this->redirectToRoute( + 'chill_person_resource', + ['person_id' => $person->getId()] + ); + } + return $this->render( 'ChillPersonBundle:PersonResource:list.html.twig', [ diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResourceKind.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResourceKind.php index 03b2aa858..619382f68 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResourceKind.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResourceKind.php @@ -31,7 +31,7 @@ class PersonResourceKind /** * @ORM\Column(type="json", length=255) */ - private array $label; + private array $title; /** * @ORM\Column(type="boolean") @@ -48,14 +48,14 @@ class PersonResourceKind return $this->isActive; } - public function getLabel(): ?array + public function getTitle(): ?array { - return $this->label; + return $this->title; } - public function setLabel(array $label): self + public function setTitle(array $title): self { - $this->label = $label; + $this->title = $title; return $this; } diff --git a/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php b/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php index 8863d705c..fabc30e5e 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonResourceType.php @@ -13,8 +13,12 @@ namespace Chill\PersonBundle\Form; use Chill\AsideActivityBundle\Templating\Entity\CategoryRender; use Chill\MainBundle\Form\Type\ChillTextareaType; +use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person\PersonResource; use Chill\PersonBundle\Entity\Person\PersonResourceKind; +use Chill\PersonBundle\Templating\Entity\PersonRender; +use Chill\ThirdPartyBundle\Entity\ThirdParty; +use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender; use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; @@ -26,10 +30,14 @@ use Symfony\Component\OptionsResolver\OptionsResolver; final class PersonResourceType extends AbstractType { private CategoryRender $categoryRender; + private PersonRender $personRender; + private ThirdPartyRender $thirdPartyRender; - public function __construct(CategoryRender $categoryRender) + public function __construct(CategoryRender $categoryRender, PersonRender $personRender, ThirdPartyRender $thirdPartyRender) { $this->categoryRender = $categoryRender; + $this->personRender = $personRender; + $this->thirdPartyRender = $thirdPartyRender; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -58,6 +66,28 @@ final class PersonResourceType extends AbstractType 'expanded' => true, 'label' => 'Associer un' ]) + ->add('person', EntityType::class, [ + 'label' => 'Usager', + 'class' => Person::class, + 'required' => false, + 'choice_label' => function (Person $person) { + $options = []; + return $this->personRender->renderString($person, $options); + } + ]) + ->add('thirdparty', EntityType::class, [ + 'label' => 'Tiers', + 'class' => ThirdParty::class, + 'required' => false, + 'choice_label' => function (ThirdParty $thirdParty) { + $options = []; + return $this->thirdPartyRender->renderString($thirdParty, $options); + } + ]) + ->add('freetext', ChillTextareaType::class, [ + 'label' => 'Description libre', + 'required' => false + ]) ->add('comment', ChillTextareaType::class, [ 'label' => 'Note', 'required' => false @@ -71,9 +101,9 @@ final class PersonResourceType extends AbstractType ]); } - // public function getBlockPrefix(): string - // { - // return 'chill_personbundle_personresource'; - // } + public function getBlockPrefix(): string + { + return 'chill_personbundle_person_resource'; + } } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Resources/public/page/person_resource/index.js b/src/Bundle/ChillPersonBundle/Resources/public/page/person_resource/index.js new file mode 100644 index 000000000..8ef2021f1 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/public/page/person_resource/index.js @@ -0,0 +1,33 @@ +import {ShowHide} from 'ChillMainAssets/lib/show_hide/show_hide.js'; + +window.addEventListener('DOMContentLoaded', function() { + let + linkedEntityContainer = document.querySelector('#linked-entity'), + personContainer = document.querySelector('#person-entity'), + thirdpartyContainer = document.querySelector('#thirdparty-entity'), + freetextContainer = document.querySelector('#freetext-entity') + ; + + if (null === linkedEntityContainer) { + return; + } + + new ShowHide({ + debug: true, + load_event: null, + froms: [linkedEntityContainer], + container: [personContainer, thirdpartyContainer, freetextContainer], + test: function(containers, arg2, arg3) { + for (let container of containers) { + for (let input of container.querySelectorAll('input')) { + if (!input.checked) { + return true; + } else { + return false; + } + } + } + + }, + }) +}); diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig index 9ba297d8b..74bdeb57e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig @@ -6,7 +6,19 @@ {{ form_row(form.kind) }} - {{ form_row(form.linkedEntity) }} +
+ {{ form_row(form.linkedEntity) }} +
+ +
+ {{ form_row(form.person) }} +
+
+ {{ form_row(form.thirdparty) }} +
+
+ {{ form_row(form.freetext) }} +
{{ form_row(form.comment) }} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig index b931c4f95..844f39d41 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig @@ -20,7 +20,7 @@
comment zone
-
doing
+
....
{#
today
#} @@ -31,4 +31,8 @@ {% include "@ChillPerson/PersonResource/create.html.twig" %} +{% endblock %} + +{% block js %} + {# {{ encore_entry_script_tags('page_person_resource') }} #} {% endblock %} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/chill.webpack.config.js b/src/Bundle/ChillPersonBundle/chill.webpack.config.js index 0b83f8e41..968c0a751 100644 --- a/src/Bundle/ChillPersonBundle/chill.webpack.config.js +++ b/src/Bundle/ChillPersonBundle/chill.webpack.config.js @@ -19,4 +19,5 @@ module.exports = function(encore, entries) encore.addEntry('page_accompanying_course_index_person_locate', __dirname + '/Resources/public/page/accompanying_course_index/person_locate.js'); encore.addEntry('page_accompanying_course_index_masonry', __dirname + '/Resources/public/page/accompanying_course_index/masonry.js'); encore.addEntry('page_suggest_names', __dirname + '/Resources/public/page/person/suggest-names.js'); + encore.addEntry('page_person_resource', __dirname + '/Resources/public/page/person_resource/index.js'); }; diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 0a674f404..517b80f1d 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -226,8 +226,8 @@ Concerned scopes: Services concernés # person resource person_resources_menu: "Ressources" -Person resources: "Réssources de la personne" -Add a person resource: "Ajouter une réssource" +Person resources: "Ressources de la personne" +Add a person resource: "Ajouter une ressource" # pickAPersonType Pick a person: Choisir une personne