From 8d543be5cc47cebc423872c90e84c0e05c4b49bb Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 11 Jul 2024 15:15:04 +0200 Subject: [PATCH 1/4] Add configuration on id_document_types to avoid errors --- .../ChillMainExtension.php | 5 +++++ .../DependencyInjection/Configuration.php | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 4dde2076c..bf041b5b3 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -193,6 +193,11 @@ class ChillMainExtension extends Extension implements [] ); + $container->setParameter( + 'chill_main.id_document_kinds', + $config['id_document_kinds'] + ); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); $loader->load('services.yaml'); $loader->load('services/doctrine.yaml'); diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index 8bd3e35f4..9c890d9fe 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -151,6 +151,28 @@ class Configuration implements ConfigurationInterface ->append($this->addWidgetsConfiguration('homepage', $this->containerBuilder)) ->end() // end of widgets/children ->end() // end of widgets + ->arrayNode('id_document_kinds')->defaultValue([]) + ->arrayPrototype() + ->children() + ->scalarNode('key')->isRequired()->cannotBeEmpty() + ->info('the key stored in database') + ->example('id_card') + ->end() + ->arrayNode('labels')->isRequired()->requiresAtLeastOneElement() + ->arrayPrototype() + ->children() + ->scalarNode('lang')->isRequired()->cannotBeEmpty() + ->example('fr') + ->end() + ->scalarNode('label')->isRequired()->cannotBeEmpty() + ->example('Carte de séjour') + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() // end of document types ->arrayNode('cruds') ->defaultValue([]) ->arrayPrototype() From 52a3d1be1b2317afd79c5821ba35b733201d52fc Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 11 Jul 2024 15:15:41 +0200 Subject: [PATCH 2/4] Implement show and hide logic within workflow form --- .../ChillMainBundle/Form/WorkflowStepType.php | 26 ++++++ .../public/page/workflow-show/index.js | 86 +++++++++++++++++-- .../views/Workflow/_decision.html.twig | 23 ++++- 3 files changed, 126 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php index 284781d54..8949432b2 100644 --- a/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php +++ b/src/Bundle/ChillMainBundle/Form/WorkflowStepType.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO; +use Chill\PersonBundle\Form\Type\PickPersonDynamicType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\EmailType; @@ -102,6 +103,7 @@ class WorkflowStepType extends AbstractType 'choice_attr' => static function (Transition $transition) use ($workflow) { $toFinal = true; $isForward = 'neutral'; + $isSignature = []; $metadata = $workflow->getMetadataStore()->getTransitionMetadata($transition); @@ -121,15 +123,38 @@ class WorkflowStepType extends AbstractType ) { $toFinal = false; } + + if (\array_key_exists('isSignature', $meta)) { + $isSignature = $meta['isSignature']; + } } return [ 'data-is-transition' => 'data-is-transition', 'data-to-final' => $toFinal ? '1' : '0', 'data-is-forward' => $isForward, + 'data-is-signature' => json_encode($isSignature), ]; }, ]) + ->add('isPersonOrUserSignature', ChoiceType::class, [ + 'mapped' => false, + 'multiple' => false, + 'expanded' => true, + 'label' => 'workflow.Type of signature', + 'choices' => [ + 'person' => 'person', + 'user' => 'user', + ], + ]) + ->add('futurePersonSignatures', PickPersonDynamicType::class, [ + 'label' => 'workflow.person signatures', + 'multiple' => true, + ]) + ->add('futureUserSignature', PickUserDynamicType::class, [ + 'label' => 'workflow.user signatures', + 'multiple' => false, + ]) ->add('futureDestUsers', PickUserDynamicType::class, [ 'label' => 'workflow.dest for next steps', 'multiple' => true, @@ -140,6 +165,7 @@ class WorkflowStepType extends AbstractType 'multiple' => true, 'required' => false, 'suggested' => $options['suggested_users'], + 'attr' => ['class' => 'future-cc-users'], ]) ->add('futureDestEmails', ChillCollectionType::class, [ 'label' => 'workflow.dest by email', diff --git a/src/Bundle/ChillMainBundle/Resources/public/page/workflow-show/index.js b/src/Bundle/ChillMainBundle/Resources/public/page/workflow-show/index.js index 2f91c7777..6829dad8e 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/page/workflow-show/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/page/workflow-show/index.js @@ -4,8 +4,86 @@ window.addEventListener('DOMContentLoaded', function() { let divTransitions = document.querySelector('#transitions'), futureDestUsersContainer = document.querySelector('#futureDests') + personSignatureField = document.querySelector('#person-signature-field'); + userSignatureField = document.querySelector('#user-signature-field'); + signatureTypeChoices = document.querySelector('#signature-type-choice'); ; + console.log('signature type', signatureTypeChoices); + + let + transitionFilterContainer = document.querySelector('#transitionFilter'), + transitionsContainer = document.querySelector('#transitions') + ; + + personSignatureField.style.display = 'none'; + userSignatureField.style.display = 'none'; + futureDestUsersContainer.style.display = 'none'; + signatureTypeChoices.style.display = 'none'; + + // ShowHide instance for signatureTypeChoices and futureDestUsersContainer + new ShowHide({ + load_event: null, + froms: [transitionsContainer], + container: [signatureTypeChoices, futureDestUsersContainer], + test: function() { + const selectedTransition = document.querySelector('input[name="workflow_step[transition]"]:checked'); + console.log('transition', selectedTransition) + if (!selectedTransition) { + return false; // No transition selected, hide all + } + + const isSignature = JSON.parse(selectedTransition.getAttribute('data-is-signature') || '[]'); + + if (isSignature.includes('person') && isSignature.includes('user')) { + signatureTypeChoices.style.display = ''; + } else { + signatureTypeChoices.style.display = 'none'; + } + + if (!isSignature.length) { + futureDestUsersContainer.style.display = ''; + personSignatureField.style.display = 'none'; + userSignatureField.style.display = 'none'; + } else { + futureDestUsersContainer.style.display = 'none'; + } + + return true; // Always return true to ensure ShowHide manages visibility + } + }); + + // Event listener for changes in signature type selection + signatureTypeChoices.addEventListener('change', function() { + // ShowHide instance for personSignatureField and userSignatureField + new ShowHide({ + load_event: null, + froms: [signatureTypeChoices], + container: [personSignatureField, userSignatureField], + test: function() { + console.log(signatureTypeChoices) + const selectedSignatureType = document.querySelector('input[name="workflow_step[isPersonOrUserSignature]"]:checked'); + console.log('signataure type', selectedSignatureType) + if (!selectedSignatureType) { + return false; // No signature type selected, hide both fields + } + + if (selectedSignatureType.value === 'person') { + personSignatureField.style.display = ''; + userSignatureField.style.display = 'none'; + } else if (selectedSignatureType.value === 'user') { + personSignatureField.style.display = 'none'; + userSignatureField.style.display = ''; + } else { + personSignatureField.style.display = 'none'; + userSignatureField.style.display = 'none'; + } + + return true; // Always return true to ensure ShowHide manages visibility + } + }); + }); + if (null !== divTransitions) { new ShowHide({ load_event: null, @@ -29,13 +107,8 @@ window.addEventListener('DOMContentLoaded', function() { }); } - let - transitionFilterContainer = document.querySelector('#transitionFilter'), - transitions = document.querySelector('#transitions') - ; - if (null !== transitionFilterContainer) { - transitions.querySelectorAll('.form-check').forEach(function(row) { + transitionsContainer.querySelectorAll('.form-check').forEach(function(row) { const isForward = row.querySelector('input').dataset.isForward; @@ -66,5 +139,4 @@ window.addEventListener('DOMContentLoaded', function() { }); }); } - }); diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/_decision.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/_decision.html.twig index 35f587e38..391e42324 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/_decision.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/_decision.html.twig @@ -58,15 +58,34 @@ {{ form_row(transition_form.transition) }} +
+
+ {{ form_row(transition_form.isPersonOrUserSignature) }} + {{ form_errors(transition_form.isPersonOrUserSignature) }} +
+
+ {{ form_row(transition_form.futureUserSignature) }} + {{ form_errors(transition_form.futureUserSignature) }} +
+
+ {{ form_row(transition_form.futurePersonSignatures) }} + {{ form_errors(transition_form.futurePersonSignatures) }} +
+
+
+
{{ form_row(transition_form.futureDestUsers) }} {{ form_errors(transition_form.futureDestUsers) }} - +
+
{{ form_row(transition_form.futureCcUsers) }} {{ form_errors(transition_form.futureCcUsers) }} - +
+
{{ form_row(transition_form.futureDestEmails) }} {{ form_errors(transition_form.futureDestEmails) }} +

{{ form_label(transition_form.comment) }}

From 3836622d2733040ef7c76fa8ed85675dcceec876 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 18 Jul 2024 16:03:45 +0200 Subject: [PATCH 3/4] Use better namespacing for configuring workflow signature documents --- .../ChillMainExtension.php | 4 +- .../DependencyInjection/Configuration.php | 48 ++++++++++--------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index bf041b5b3..0d90854b4 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -194,8 +194,8 @@ class ChillMainExtension extends Extension implements ); $container->setParameter( - 'chill_main.id_document_kinds', - $config['id_document_kinds'] + 'chill_main.workflow_signatures.base_signer.document_kinds', + $config['workflow_signature']['base_signer']['document_kinds'] ); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index 9c890d9fe..2185375b6 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -151,28 +151,6 @@ class Configuration implements ConfigurationInterface ->append($this->addWidgetsConfiguration('homepage', $this->containerBuilder)) ->end() // end of widgets/children ->end() // end of widgets - ->arrayNode('id_document_kinds')->defaultValue([]) - ->arrayPrototype() - ->children() - ->scalarNode('key')->isRequired()->cannotBeEmpty() - ->info('the key stored in database') - ->example('id_card') - ->end() - ->arrayNode('labels')->isRequired()->requiresAtLeastOneElement() - ->arrayPrototype() - ->children() - ->scalarNode('lang')->isRequired()->cannotBeEmpty() - ->example('fr') - ->end() - ->scalarNode('label')->isRequired()->cannotBeEmpty() - ->example('Carte de séjour') - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() // end of document types ->arrayNode('cruds') ->defaultValue([]) ->arrayPrototype() @@ -299,6 +277,32 @@ class Configuration implements ConfigurationInterface ->end() // end of root ; + $rootNode->children() + ->arrayNode('workflow_signature') + ->children() + ->arrayNode('base_signer') + ->children() + ->arrayNode('document_kinds') + ->arrayPrototype() + ->children() + ->scalarNode('key')->cannotBeEmpty()->end() + ->arrayNode('labels') + ->arrayPrototype() + ->children() + ->scalarNode('lang')->cannotBeEmpty()->end() + ->scalarNode('label')->cannotBeEmpty()->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end() + ->end(); + $rootNode->children() ->arrayNode('add_address')->addDefaultsIfNotSet()->children() ->scalarNode('default_country')->cannotBeEmpty()->defaultValue('BE')->end() From 0a46b5304ddfc51196aaf8bb53b6d2ee7ca13524 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 23 Jul 2024 12:18:14 +0200 Subject: [PATCH 4/4] Adjust implementation of showHide (wip) --- .../public/page/workflow-show/index.js | 59 +++++++------------ 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/page/workflow-show/index.js b/src/Bundle/ChillMainBundle/Resources/public/page/workflow-show/index.js index 6829dad8e..93096a910 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/page/workflow-show/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/page/workflow-show/index.js @@ -9,8 +9,6 @@ window.addEventListener('DOMContentLoaded', function() { signatureTypeChoices = document.querySelector('#signature-type-choice'); ; - console.log('signature type', signatureTypeChoices); - let transitionFilterContainer = document.querySelector('#transitionFilter'), transitionsContainer = document.querySelector('#transitions') @@ -21,39 +19,26 @@ window.addEventListener('DOMContentLoaded', function() { futureDestUsersContainer.style.display = 'none'; signatureTypeChoices.style.display = 'none'; - // ShowHide instance for signatureTypeChoices and futureDestUsersContainer - new ShowHide({ - load_event: null, - froms: [transitionsContainer], - container: [signatureTypeChoices, futureDestUsersContainer], - test: function() { - const selectedTransition = document.querySelector('input[name="workflow_step[transition]"]:checked'); - console.log('transition', selectedTransition) - if (!selectedTransition) { - return false; // No transition selected, hide all + // ShowHide instance for signatureTypeChoices + new ShowHide({ + debug: true, + froms: [divTransitions], + container: [signatureTypeChoices], + test: function(transitions) { + for (let transition of transitions) { + for (let input of transition.querySelectorAll('input')) { + if (input.checked) { + const inputData = JSON.parse(input.getAttribute('data-is-signature')) + return inputData.includes('person') || inputData.includes('user'); + } } - - const isSignature = JSON.parse(selectedTransition.getAttribute('data-is-signature') || '[]'); - - if (isSignature.includes('person') && isSignature.includes('user')) { - signatureTypeChoices.style.display = ''; - } else { - signatureTypeChoices.style.display = 'none'; - } - - if (!isSignature.length) { - futureDestUsersContainer.style.display = ''; - personSignatureField.style.display = 'none'; - userSignatureField.style.display = 'none'; - } else { - futureDestUsersContainer.style.display = 'none'; - } - - return true; // Always return true to ensure ShowHide manages visibility } - }); - // Event listener for changes in signature type selection + return true; + } + }); + +/* // Event listener for changes in signature type selection signatureTypeChoices.addEventListener('change', function() { // ShowHide instance for personSignatureField and userSignatureField new ShowHide({ @@ -61,9 +46,7 @@ window.addEventListener('DOMContentLoaded', function() { froms: [signatureTypeChoices], container: [personSignatureField, userSignatureField], test: function() { - console.log(signatureTypeChoices) const selectedSignatureType = document.querySelector('input[name="workflow_step[isPersonOrUserSignature]"]:checked'); - console.log('signataure type', selectedSignatureType) if (!selectedSignatureType) { return false; // No signature type selected, hide both fields } @@ -82,15 +65,15 @@ window.addEventListener('DOMContentLoaded', function() { return true; // Always return true to ensure ShowHide manages visibility } }); - }); + });*/ - if (null !== divTransitions) { +/* if (null !== divTransitions) { new ShowHide({ load_event: null, froms: [divTransitions], container: [futureDestUsersContainer], test: function(divs, arg2, arg3) { - for (let div of divs) { + for (let div of divs) { for (let input of div.querySelectorAll('input')) { if (input.checked) { if (input.dataset.toFinal === "1") { @@ -105,7 +88,7 @@ window.addEventListener('DOMContentLoaded', function() { return true; }, }); - } + }*/ if (null !== transitionFilterContainer) { transitionsContainer.querySelectorAll('.form-check').forEach(function(row) {