From f44566037cf95e2a9d6560f7c34e64e38f8a8a78 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 13 Oct 2021 12:17:51 +0200 Subject: [PATCH 01/14] person: fix showHide import/export --- .../ChillMainBundle/Resources/public/lib/show_hide/index.js | 6 +++++- .../Resources/public/lib/show_hide/show_hide.js | 2 +- .../ChillPersonBundle/Resources/views/Person/edit.html.twig | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/index.js b/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/index.js index 34f3b80b5..88890ab40 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/index.js @@ -1 +1,5 @@ -require("./show_hide.js"); \ No newline at end of file +//require("./show_hide.js"); + +import { ShowHide } from './show_hide.js' + +export { ShowHide } \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/show_hide.js b/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/show_hide.js index dd4dfd6db..ec6b796ec 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/show_hide.js +++ b/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/show_hide.js @@ -134,4 +134,4 @@ var ShowHide = function(options) { }; }; -export {ShowHide}; +export { ShowHide }; diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig index 2bb7fa4bb..b981eb31e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig @@ -142,5 +142,5 @@ {% endblock %} {% block js %} - {{ encore_entry_link_tags('page_person') }} + {{ encore_entry_script_tags('page_person') }} {% endblock %} From 6a1cf4eb9265a7d2b1b9b4e18d34d00444a04ca6 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 13 Oct 2021 16:22:33 +0200 Subject: [PATCH 02/14] person: capitalize entry in person form --- .../Resources/views/Person/edit.html.twig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig index b981eb31e..98ac7c5d0 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig @@ -135,7 +135,6 @@ - {{ form_end(form) }} @@ -144,3 +143,11 @@ {% block js %} {{ encore_entry_script_tags('page_person') }} {% endblock %} + +{% block css %} + +{% endblock %} \ No newline at end of file From b800b62e8892d214f69570b84f544cc8b561ffb3 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 14 Oct 2021 22:33:31 +0200 Subject: [PATCH 03/14] person: capitalise place of birth (frontend + backend) --- src/Bundle/ChillPersonBundle/Form/PersonType.php | 16 +++++++++++++++- .../Resources/views/Person/edit.html.twig | 8 -------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Form/PersonType.php b/src/Bundle/ChillPersonBundle/Form/PersonType.php index 8bc982713..f2fd8ea3a 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonType.php @@ -35,6 +35,7 @@ use Chill\PersonBundle\Form\Type\Select2MaritalStatusType; use Symfony\Component\Form\AbstractType; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\CommentType; +use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\TelType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -114,7 +115,19 @@ class PersonType extends AbstractType } if ($this->config['place_of_birth'] === 'visible') { - $builder->add('placeOfBirth', TextType::class, array('required' => false)); + $builder->add('placeOfBirth', TextType::class, array( + 'required' => false, + 'attr' => ['style' => 'text-transform: uppercase;'], + )); + + $builder->get('placeOfBirth')->addModelTransformer(new CallbackTransformer( + function ($string) { + return strtoupper($string); + }, + function ($string) { + return strtoupper($string); + } + )); } if ($this->config['contact_info'] === 'visible') { @@ -192,6 +205,7 @@ class PersonType extends AbstractType array('attr' => array('class' => 'cf-fields'), 'group' => $options['cFGroup'])) ; } + } /** diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig index 98ac7c5d0..fdbc0d8ad 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig @@ -143,11 +143,3 @@ {% block js %} {{ encore_entry_script_tags('page_person') }} {% endblock %} - -{% block css %} - -{% endblock %} \ No newline at end of file From 69ae252da63cda22ec26a648d7036cb6fad67dc7 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 15 Oct 2021 21:46:09 +0200 Subject: [PATCH 04/14] person: delete accept Email --- src/Bundle/ChillPersonBundle/Form/PersonType.php | 3 +-- .../ChillPersonBundle/Resources/views/Person/edit.html.twig | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Form/PersonType.php b/src/Bundle/ChillPersonBundle/Form/PersonType.php index f2fd8ea3a..85b8619c2 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonType.php @@ -163,8 +163,7 @@ class PersonType extends AbstractType if ($this->config['email'] === 'visible') { $builder - ->add('email', EmailType::class, array('required' => false)) - ->add('acceptEmail', CheckboxType::class, array('required' => false)); + ->add('email', EmailType::class, array('required' => false)); } if ($this->config['country_of_birth'] === 'visible') { diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig index fdbc0d8ad..a8fc88f5e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig @@ -95,9 +95,6 @@
{{ form_row(form.email, {'label': 'Email'}) }}
-
- {{ form_row(form.acceptEmail, {'label' : 'Accept emails ?'}) }} -
{%- endif -%} {%- if form.phonenumber is defined -%} From f6806f7743e355db643d197d61be06885853eb04 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 15 Oct 2021 21:56:49 +0200 Subject: [PATCH 05/14] person: new translation for accept SMS --- src/Bundle/ChillPersonBundle/translations/messages.fr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index a17bbc55f..2a82d8c09 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -47,8 +47,8 @@ Phonenumber: 'Numéro de téléphone' phonenumber: numéro de téléphone Mobilenumber: 'Numéro de téléphone portable' mobilenumber: numéro de téléphone portable -Accept short text message ?: Accepte les SMS? -Accept short text message: Accepte les SMS +Accept short text message ?: La personne a donné l'autorisation d'utiliser ce no de téléphone pour l'envoi de rappel par SMS +Accept short text message: La personne a donné l'autorisation d'utiliser ce no de téléphone pour l'envoi de rappel par SMS Other phonenumber: Autre numéro de téléphone Description: description Add new phone: Ajouter un numéro de téléphone From 816855e6f8020607eb2cf02b3cd1bc0acc396d2b Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 26 Oct 2021 14:12:53 +0200 Subject: [PATCH 06/14] mod input address: add an event listener to add this component for collections --- .../vuejs/Address/mod_input_address_index.js | 139 +++++++++--------- 1 file changed, 73 insertions(+), 66 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js index ad4a648f5..9c5f9eaa7 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js @@ -5,82 +5,89 @@ import App from './App.vue'; const i18n = _createI18n(addressMessages); -let inputs = document.querySelectorAll('input[type="hidden"][data-input-address]'); +const addAddressInput = (inputs) => { -const isNumeric = function(v) { return !isNaN(v); }; + inputs.forEach(el => { + let + addressId = el.value, + uniqid = el.dataset.inputAddress, + container = document.querySelector('div[data-input-address-container="' + uniqid + '"]'), + isEdit = addressId !== '', + addressIdInt = addressId !== '' ? parseInt(addressId) : null + ; -inputs.forEach(el => { - let - addressId = el.value, - uniqid = el.dataset.inputAddress, - container = document.querySelector('div[data-input-address-container="' + uniqid + '"]'), - isEdit = addressId !== '', - addressIdInt = addressId !== '' ? parseInt(addressId) : null - ; + if (container === null) { + throw Error("no container"); + } + console.log('useValidFrom', el.dataset.useValidFrom === '1'); - if (container === null) { - throw Error("no container"); - } - console.log('useValidFrom', el.dataset.useValidFrom === '1'); - - const app = createApp({ - template: ``, - data() { - return { - addAddress: { - context: { - // for legacy ? can be remove ? - target: { - name: 'input-address', - id: addressIdInt, - }, - edit: isEdit, - addressId: addressIdInt, - }, - options: { - /// Options override default. - /// null value take default component value defined in AddAddress data() - button: { - text: { - create: el.dataset.buttonTextCreate || null, - edit: el.dataset.buttonTextUpdate || null, + const app = createApp({ + template: ``, + data() { + return { + addAddress: { + context: { + // for legacy ? can be remove ? + target: { + name: 'input-address', + id: addressIdInt, }, - size: null, - displayText: true + edit: isEdit, + addressId: addressIdInt, }, + options: { + /// Options override default. + /// null value take default component value defined in AddAddress data() + button: { + text: { + create: el.dataset.buttonTextCreate || null, + edit: el.dataset.buttonTextUpdate || null, + }, + size: null, + displayText: true + }, - /// Modal title text if create or edit address (trans chain, see i18n) - title: { - create: null, - edit: null, - }, + /// Modal title text if create or edit address (trans chain, see i18n) + title: { + create: null, + edit: null, + }, - /// Display panes in Modal for step123 - openPanesInModal: true, + /// Display panes in Modal for step123 + openPanesInModal: true, - /// Display actions buttons of panes in a sticky-form-button navbar - stickyActions: false, - showMessageWhenNoAddress: true, + /// Display actions buttons of panes in a sticky-form-button navbar + stickyActions: false, + showMessageWhenNoAddress: true, - /// Use Date fields - useDate: { - validFrom: el.dataset.useValidFrom === '1' || false, //boolean, default: false - validTo: el.dataset.useValidTo === '1' || false, //boolean, default: false - }, + /// Use Date fields + useDate: { + validFrom: el.dataset.useValidFrom === '1' || false, //boolean, default: false + validTo: el.dataset.useValidTo === '1' || false, //boolean, default: false + }, - /// Don't display show renderbox Address: showPane display only a button - onlyButton: false, + /// Don't display show renderbox Address: showPane display only a button + onlyButton: false, + } } } + }, + methods: { + associateToInput(payload) { + el.value = payload.addressId; + } } - }, - methods: { - associateToInput(payload) { - el.value = payload.addressId; - } - } - }) - .use(i18n) - .component('app', App) - .mount(container); -}); + }) + .use(i18n) + .component('app', App) + .mount(container); + }); +}; + +document.addEventListener('DOMContentLoaded', (_e) => + addAddressInput(document.querySelectorAll('input[type="hidden"][data-input-address]')) +); + +window.addEventListener('collection-add-entry', (_e) => + addAddressInput(document.querySelectorAll('input[type="hidden"][data-input-address]')) +); \ No newline at end of file From c90f9ee5bc9b5b390622ec31eb9f298c2e5a68a0 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 28 Oct 2021 08:07:01 +0200 Subject: [PATCH 07/14] add mod_input_address_index to collection event: better addition of the event listener to the DOM --- .../Resources/public/vuejs/Address/mod_input_address_index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js index 9c5f9eaa7..0f39c5e75 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js @@ -88,6 +88,6 @@ document.addEventListener('DOMContentLoaded', (_e) => addAddressInput(document.querySelectorAll('input[type="hidden"][data-input-address]')) ); -window.addEventListener('collection-add-entry', (_e) => - addAddressInput(document.querySelectorAll('input[type="hidden"][data-input-address]')) +window.addEventListener('collection-add-entry', (e) => + addAddressInput(e.detail.entry.querySelectorAll('input[type="hidden"][data-input-address]')) ); \ No newline at end of file From 046f65f5ff408ad6e0862aae82666bf926144f56 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 28 Oct 2021 09:45:27 +0200 Subject: [PATCH 08/14] person: re-add accpet email and add possibility of hidding this field --- .../ChillPersonBundle/DependencyInjection/Configuration.php | 1 + src/Bundle/ChillPersonBundle/Form/PersonType.php | 5 +++++ .../ChillPersonBundle/Resources/views/Person/edit.html.twig | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php index bf2d18922..4218174eb 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php @@ -82,6 +82,7 @@ class Configuration implements ConfigurationInterface ->append($this->addFieldNode('accompanying_period')) ->append($this->addFieldNode('memo')) ->append($this->addFieldNode('number_of_children')) + ->append($this->addFieldNode('acceptEmail')) ->arrayNode('alt_names') ->defaultValue([]) ->arrayPrototype() diff --git a/src/Bundle/ChillPersonBundle/Form/PersonType.php b/src/Bundle/ChillPersonBundle/Form/PersonType.php index 85b8619c2..abe4750f2 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonType.php @@ -166,6 +166,11 @@ class PersonType extends AbstractType ->add('email', EmailType::class, array('required' => false)); } + if ($this->config['acceptEmail'] === 'visible') { + $builder + ->add('acceptEmail', CheckboxType::class, array('required' => false)); + } + if ($this->config['country_of_birth'] === 'visible') { $builder->add('countryOfBirth', Select2CountryType::class, array( 'required' => false diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig index a8fc88f5e..80c1e76f9 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig @@ -95,6 +95,11 @@
{{ form_row(form.email, {'label': 'Email'}) }}
+ {% endif %} + {%- if form.acceptEmail is defined -%} +
+ {{ form_row(form.acceptEmail, {'label' : 'Accept emails ?'}) }} +
{%- endif -%} {%- if form.phonenumber is defined -%} From 84ab4f8d1fb0b720b6e3b49800beb2ac96473d97 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 4 Nov 2021 15:56:15 +0100 Subject: [PATCH 09/14] person: add the possibility of form data is null on CommentType --- src/Bundle/ChillMainBundle/Form/Type/CommentType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Form/Type/CommentType.php b/src/Bundle/ChillMainBundle/Form/Type/CommentType.php index afcd061e6..3d3f2e9d8 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/CommentType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/CommentType.php @@ -54,7 +54,7 @@ class CommentType extends AbstractType $data = $event->getForm()->getData(); $comment = $event->getData() ?? ['comment' => '']; - if ($data->getComment() !== $comment['comment']) { + if (null !== $data && $data->getComment() !== $comment['comment']) { $data->setDate(new \DateTime()); $data->setUserId($this->user->getId()); $event->getForm()->setData($data); From 8de78c758464f576ece967f32d2ac4530d91a649 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 4 Nov 2021 16:20:08 +0100 Subject: [PATCH 10/14] person: add prefered_choices for language (WIP) --- .../DependencyInjection/Configuration.php | 4 +++ .../Form/Type/Select2LanguageType.php | 25 ++++++++----------- .../ChillMainBundle/config/services/form.yaml | 1 + 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index c711f911f..8965e7aaf 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -51,6 +51,10 @@ class Configuration implements ConfigurationInterface ->defaultValue(array('fr')) ->prototype('scalar')->end() ->end() // end of array 'available_languages' + ->arrayNode('available_countries') + ->defaultValue(array('fr')) + ->prototype('scalar')->end() + ->end() // end of array 'available_countries' ->arrayNode('routing') ->children() ->arrayNode('resources') diff --git a/src/Bundle/ChillMainBundle/Form/Type/Select2LanguageType.php b/src/Bundle/ChillMainBundle/Form/Type/Select2LanguageType.php index 2c8dea857..0583c2e03 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Select2LanguageType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/Select2LanguageType.php @@ -28,32 +28,26 @@ use Chill\MainBundle\Form\Type\DataTransformer\MultipleObjectsToIdTransformer; use Doctrine\Persistence\ObjectManager; use Chill\MainBundle\Form\Type\Select2ChoiceType; use Chill\MainBundle\Templating\TranslatableStringHelper; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; /** * Extends choice to allow adding select2 library on widget for languages (multiple) */ class Select2LanguageType extends AbstractType { - /** - * @var RequestStack - */ - private $requestStack; + private RequestStack $requestStack; - /** - * @var ObjectManager - */ - private $em; + private ObjectManager $em; - /** - * - * @var TranslatableStringHelper - */ - protected $translatableStringHelper; + protected TranslatableStringHelper $translatableStringHelper; + + protected ParameterBagInterface $parameterBag; public function __construct( RequestStack $requestStack, ObjectManager $em, - TranslatableStringHelper $translatableStringHelper + TranslatableStringHelper $translatableStringHelper, + ParameterBagInterface $parameterBag ) { $this->requestStack = $requestStack; @@ -91,7 +85,8 @@ class Select2LanguageType extends AbstractType $resolver->setDefaults(array( 'class' => 'Chill\MainBundle\Entity\Language', - 'choices' => array_combine(array_values($choices),array_keys($choices)) + 'choices' => array_combine(array_values($choices),array_keys($choices)), + 'preferred_choices' => ['FR'] //TODO use $parameterBag->get('available_languages') )); } } diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index f2e5b1fc4..1013d6d09 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -34,6 +34,7 @@ services: - "@request_stack" - "@doctrine.orm.entity_manager" - "@chill.main.helper.translatable_string" + - '@Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface' tags: - { name: form.type, alias: select2_chill_language } From bddcdd7de2ef630ef14573e19e87f181f7a8c085 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 8 Nov 2021 10:42:12 +0100 Subject: [PATCH 11/14] person: add preferrred_choices for countries and languages --- .../ChillMainExtension.php | 3 ++ .../DependencyInjection/Configuration.php | 2 +- .../Form/Type/Select2CountryType.php | 39 +++++++++++-------- .../Form/Type/Select2LanguageType.php | 13 +++++-- .../test/Fixtures/App/app/config/config.yml | 1 + .../ChillMainBundle/config/services/form.yaml | 1 + 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 8050fd9b6..3c1a61685 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -96,6 +96,9 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, $container->setParameter('chill_main.available_languages', $config['available_languages']); + $container->setParameter('chill_main.available_countries', + $config['available_countries']); + $container->setParameter('chill_main.routing.resources', $config['routing']['resources']); diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index 8965e7aaf..75dbd54b8 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -52,7 +52,7 @@ class Configuration implements ConfigurationInterface ->prototype('scalar')->end() ->end() // end of array 'available_languages' ->arrayNode('available_countries') - ->defaultValue(array('fr')) + ->defaultValue(array('FR')) ->prototype('scalar')->end() ->end() // end of array 'available_countries' ->arrayNode('routing') diff --git a/src/Bundle/ChillMainBundle/Form/Type/Select2CountryType.php b/src/Bundle/ChillMainBundle/Form/Type/Select2CountryType.php index 617d1afce..c8288d69d 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Select2CountryType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/Select2CountryType.php @@ -28,6 +28,7 @@ use Chill\MainBundle\Form\Type\DataTransformer\ObjectToIdTransformer; use Doctrine\Persistence\ObjectManager; use Chill\MainBundle\Form\Type\Select2ChoiceType; use Chill\MainBundle\Templating\TranslatableStringHelper; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; /** * Extends choice to allow adding select2 library on widget @@ -37,31 +38,25 @@ use Chill\MainBundle\Templating\TranslatableStringHelper; */ class Select2CountryType extends AbstractType { - /** - * @var RequestStack - */ - private $requestStack; + private RequestStack $requestStack; - /** - * - * @var TranslatableStringHelper - */ - protected $translatableStringHelper; + private ObjectManager $em; - /** - * @var ObjectManager - */ - private $em; + protected TranslatableStringHelper $translatableStringHelper; + + protected ParameterBagInterface $parameterBag; public function __construct( RequestStack $requestStack, ObjectManager $em, - TranslatableStringHelper $translatableStringHelper + TranslatableStringHelper $translatableStringHelper, + ParameterBagInterface $parameterBag ) { $this->requestStack = $requestStack; $this->em = $em; $this->translatableStringHelper = $translatableStringHelper; + $this->parameterBag = $parameterBag; } public function getBlockPrefix() @@ -82,19 +77,29 @@ class Select2CountryType extends AbstractType public function configureOptions(OptionsResolver $resolver) { - $locale = $this->requestStack->getCurrentRequest()->getLocale(); $countries = $this->em->getRepository('Chill\MainBundle\Entity\Country')->findAll(); - $choices = array(); + $choices = []; + $preferredCountries = $this->parameterBag->get('chill_main.available_countries'); + $preferredChoices = []; foreach ($countries as $c) { $choices[$c->getId()] = $this->translatableStringHelper->localize($c->getName()); } + foreach ($preferredCountries as $pc) { + foreach ($countries as $c) { + if ($c->getCountryCode() == $pc) { + $preferredChoices[$c->getId()] = $this->translatableStringHelper->localize($c->getName()); + } + } + } + asort($choices, SORT_STRING | SORT_FLAG_CASE); $resolver->setDefaults(array( 'class' => 'Chill\MainBundle\Entity\Country', - 'choices' => array_combine(array_values($choices),array_keys($choices)) + 'choices' => array_combine(array_values($choices),array_keys($choices)), + 'preferred_choices' => array_combine(array_values($preferredChoices), array_keys($preferredChoices)) )); } } diff --git a/src/Bundle/ChillMainBundle/Form/Type/Select2LanguageType.php b/src/Bundle/ChillMainBundle/Form/Type/Select2LanguageType.php index 0583c2e03..a50569967 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Select2LanguageType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/Select2LanguageType.php @@ -53,6 +53,7 @@ class Select2LanguageType extends AbstractType $this->requestStack = $requestStack; $this->em = $em; $this->translatableStringHelper = $translatableStringHelper; + $this->parameterBag = $parameterBag; } public function getBlockPrefix() @@ -73,20 +74,24 @@ class Select2LanguageType extends AbstractType public function configureOptions(OptionsResolver $resolver) { - $locale = $this->requestStack->getCurrentRequest()->getLocale(); $languages = $this->em->getRepository('Chill\MainBundle\Entity\Language')->findAll(); - $choices = array(); + $preferredLanguages = $this->parameterBag->get('chill_main.available_languages'); + $choices = []; + $preferredChoices = []; foreach ($languages as $l) { $choices[$l->getId()] = $this->translatableStringHelper->localize($l->getName()); } + foreach ($preferredLanguages as $l) { + $preferredChoices[$l] = $choices[$l]; + } asort($choices, SORT_STRING | SORT_FLAG_CASE); $resolver->setDefaults(array( 'class' => 'Chill\MainBundle\Entity\Language', - 'choices' => array_combine(array_values($choices),array_keys($choices)), - 'preferred_choices' => ['FR'] //TODO use $parameterBag->get('available_languages') + 'choices' => array_combine(array_values($choices), array_keys($choices)), + 'preferred_choices' => array_combine(array_values($preferredChoices), array_keys($preferredChoices)) )); } } diff --git a/src/Bundle/ChillMainBundle/Resources/test/Fixtures/App/app/config/config.yml b/src/Bundle/ChillMainBundle/Resources/test/Fixtures/App/app/config/config.yml index b16af4de1..530c29ee6 100644 --- a/src/Bundle/ChillMainBundle/Resources/test/Fixtures/App/app/config/config.yml +++ b/src/Bundle/ChillMainBundle/Resources/test/Fixtures/App/app/config/config.yml @@ -39,3 +39,4 @@ assetic: chill_main: available_languages: [fr, en] + available_countries: [FR] diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index 1013d6d09..f5302e52e 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -25,6 +25,7 @@ services: - "@request_stack" - "@doctrine.orm.entity_manager" - "@chill.main.helper.translatable_string" + - '@Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface' tags: - { name: form.type, alias: select2_chill_country } From 1dbf29beea4b04ccf99fa6fe72d28c510e56cf2b Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 8 Nov 2021 11:04:20 +0100 Subject: [PATCH 12/14] person: avoid js error when personAcceptEmail is null --- .../Resources/public/page/person/index.js | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/page/person/index.js b/src/Bundle/ChillPersonBundle/Resources/public/page/person/index.js index d641e3b36..28ae3380a 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/page/person/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/page/person/index.js @@ -7,7 +7,6 @@ const personAcceptEmail = document.getElementById("personAcceptEmail"); const personPhoneNumber = document.getElementById("personPhoneNumber"); const personAcceptSMS = document.getElementById("personAcceptSMS"); - new ShowHide({ froms: [maritalStatus], container: [maritalStatusDate], @@ -24,21 +23,24 @@ new ShowHide({ event_name: 'change' }); -new ShowHide({ - froms: [personEmail], - container: [personAcceptEmail], - test: function(froms) { - for (let f of froms.values()) { - for (let input of f.querySelectorAll('input').values()) { - if (input.value) { - return true +if (personAcceptEmail) { + new ShowHide({ + froms: [personEmail], + container: [personAcceptEmail], + test: function(froms) { + for (let f of froms.values()) { + for (let input of f.querySelectorAll('input').values()) { + if (input.value) { + return true + } } } - } - return false; - }, - event_name: 'input' -}); + return false; + }, + event_name: 'input' + }); +} + new ShowHide({ froms: [personPhoneNumber], From fa05a6856abda486e96d773452317f1d7b699985 Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 8 Nov 2021 11:41:45 +0100 Subject: [PATCH 13/14] person: add civility: entity, migration, form, twig, config --- .../DependencyInjection/Configuration.php | 1 + .../ChillPersonBundle/Entity/Person.php | 32 ++++++++++++++++++ .../ChillPersonBundle/Form/PersonType.php | 28 +++++++++++++++- .../config/config_test_with_hidden_fields.yml | 3 +- .../Resources/views/Person/edit.html.twig | 3 ++ .../Resources/views/Person/view.html.twig | 9 +++++ .../config/services/form.yaml | 5 +-- .../migrations/Version20211108100849.php | 33 +++++++++++++++++++ .../translations/messages.fr.yml | 2 ++ 9 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20211108100849.php diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php index 4218174eb..2c53af0fe 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/Configuration.php @@ -77,6 +77,7 @@ class Configuration implements ConfigurationInterface ->append($this->addFieldNode('nationality')) ->append($this->addFieldNode('country_of_birth')) ->append($this->addFieldNode('marital_status')) + ->append($this->addFieldNode('civility')) ->append($this->addFieldNode('spoken_languages')) ->append($this->addFieldNode('address')) ->append($this->addFieldNode('accompanying_period')) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 9aaad8c04..0ae5d2a79 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -34,6 +34,7 @@ use Chill\PersonBundle\Entity\MaritalStatus; use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\MainBundle\Entity\HasCenterInterface; use Chill\MainBundle\Entity\Address; +use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\PersonBundle\Entity\Person\PersonCurrentAddress; use DateTime; @@ -212,6 +213,15 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI */ private $maritalStatus; + /** + * The marital status of the person + * @var Civility + * + * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Civility") + * @ORM\JoinColumn(nullable=true) + */ + private $civility; + /** * The date of the last marital status change of the person * @var \DateTime @@ -962,6 +972,28 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->maritalStatus; } + /** + * Set civility + * + * @param Civility $civility + * @return Person + */ + public function setCivility(Civility $civility = null) + { + $this->civility = $civility; + return $this; + } + + /** + * Get civility + * + * @return Civility + */ + public function getCivility() + { + return $this->civility; + } + /** * Set contactInfo * diff --git a/src/Bundle/ChillPersonBundle/Form/PersonType.php b/src/Bundle/ChillPersonBundle/Form/PersonType.php index abe4750f2..521d9a9d9 100644 --- a/src/Bundle/ChillPersonBundle/Form/PersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/PersonType.php @@ -22,6 +22,7 @@ namespace Chill\PersonBundle\Form; use Chill\CustomFieldsBundle\Form\Type\CustomFieldType; +use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Form\Type\ChillCollectionType; use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\Select2CountryType; @@ -35,6 +36,10 @@ use Chill\PersonBundle\Form\Type\Select2MaritalStatusType; use Symfony\Component\Form\AbstractType; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\CommentType; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\EntityRepository; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\TelType; @@ -63,16 +68,20 @@ class PersonType extends AbstractType */ protected $configAltNamesHelper; + protected TranslatableStringHelper $translatableStringHelper; + /** * * @param string[] $personFieldsConfiguration configuration of visibility of some fields */ public function __construct( array $personFieldsConfiguration, - ConfigPersonAltNamesHelper $configAltNamesHelper + ConfigPersonAltNamesHelper $configAltNamesHelper, + TranslatableStringHelper $translatableStringHelper ) { $this->config = $personFieldsConfiguration; $this->configAltNamesHelper = $configAltNamesHelper; + $this->translatableStringHelper = $translatableStringHelper; } /** @@ -190,6 +199,23 @@ class PersonType extends AbstractType )); } + if ($this->config['civility'] === 'visible'){ + $builder + ->add('civility', EntityType::class, [ + 'label' => 'Civility', + 'class' => Civility::class, + 'choice_label' => function (Civility $civility): string { + return $this->translatableStringHelper->localize($civility->getName()); + }, + 'query_builder' => function (EntityRepository $er): QueryBuilder { + return $er->createQueryBuilder('c') + ->where('c.active = true'); + }, + 'placeholder' => 'choose civility', + 'required' => false + ]); + } + if ($this->config['marital_status'] === 'visible'){ $builder ->add('maritalStatus', Select2MaritalStatusType::class, array( diff --git a/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml b/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml index e11599661..0b12be8d0 100644 --- a/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml +++ b/src/Bundle/ChillPersonBundle/Resources/test/Fixtures/App/app/config/config_test_with_hidden_fields.yml @@ -15,4 +15,5 @@ chill_person: phonenumber: hidden country_of_birth: hidden marital_status: hidden - spoken_languages: hidden \ No newline at end of file + spoken_languages: hidden + civility: hidden \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig index 80c1e76f9..d394a75a8 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig @@ -37,6 +37,9 @@

{{ 'General information'|trans }}

+ {%- if form.civility is defined -%} + {{ form_row(form.civility, {'label' : 'Civility'}) }} + {% endif %} {{ form_row(form.firstName, {'label' : 'First name'}) }} {{ form_row(form.lastName, {'label' : 'Last name'}) }} {% if form.altNames is defined %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig index a67723f27..adc6a49ce 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig @@ -51,6 +51,15 @@ This view should receive those arguments:

{{ 'General information'|trans }}

+ {% if person.civility is not null %} +
{{ 'Civility'|trans }} :
+
+ {% if person.civility.name|length > 0 %} + {{ person.civility.name|first }} + {% endif %} +
+ {% endif %} +
{{ 'First name'|trans }} :
{{ person.firstName }}
diff --git a/src/Bundle/ChillPersonBundle/config/services/form.yaml b/src/Bundle/ChillPersonBundle/config/services/form.yaml index dacfa41de..2390005cf 100644 --- a/src/Bundle/ChillPersonBundle/config/services/form.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/form.yaml @@ -7,8 +7,9 @@ services: Chill\PersonBundle\Form\PersonType: arguments: - - '%chill_person.person_fields%' - - '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper' + $personFieldsConfiguration: '%chill_person.person_fields%' + $configAltNamesHelper: '@Chill\PersonBundle\Config\ConfigPersonAltNamesHelper' + $translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper' tags: - { name: form.type, alias: '@chill.person.form.person_creation' } diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20211108100849.php b/src/Bundle/ChillPersonBundle/migrations/Version20211108100849.php new file mode 100644 index 000000000..49395dfae --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20211108100849.php @@ -0,0 +1,33 @@ +addSql('ALTER TABLE chill_person_person ADD civility_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_person_person ADD CONSTRAINT FK_BF210A1423D6A298 FOREIGN KEY (civility_id) REFERENCES chill_main_civility (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_BF210A1423D6A298 ON chill_person_person (civility_id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_person DROP CONSTRAINT FK_BF210A1423D6A298'); + $this->addSql('DROP INDEX IDX_BF210A1423D6A298'); + $this->addSql('ALTER TABLE chill_person_person DROP civility_id'); + } +} diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 2a82d8c09..af3ca6f05 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -80,6 +80,8 @@ Married: Marié(e) 'Contact information': 'Informations de contact' 'Administrative information': Administratif File number: Dossier n° +Civility: Civilité +choose civility: -- # dédoublonnage Old person: Doublon From 061197e52ed9a8cce12e9f1cb9e435a403287e9d Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 8 Nov 2021 12:21:06 +0100 Subject: [PATCH 14/14] upd CHANGELOG --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fb7d4680..7037840b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,9 @@ and this project adheres to - +* [person]: Add civility to the person +* [person]: Various improvements on the edit person form +* [person]: Set available_languages and available_countries as parameters for use in the edit person form ## Test releases