From c23ada3533c606d9e7b64a491986e00d400c8162 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 24 Jun 2021 08:25:55 +0200 Subject: [PATCH] person: add show/hide on marital status date --- .../Resources/public/js/person.js | 19 +++++++++++++++++++ .../Resources/views/Person/edit.html.twig | 18 ++++++++++++++---- .../Resources/views/Person/view.html.twig | 4 ++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/js/person.js b/src/Bundle/ChillPersonBundle/Resources/public/js/person.js index 6ebd8d7cc..da40dddc7 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/js/person.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/js/person.js @@ -1,10 +1,29 @@ import { ShowHide } from 'ShowHide/show_hide.js'; +const maritalStatus = document.getElementById("maritalStatus"); +const maritalStatusDate = document.getElementById("maritalStatusDate"); const personEmail = document.getElementById("personEmail"); const personAcceptEmail = document.getElementById("personAcceptEmail"); const personPhoneNumber = document.getElementById("personPhoneNumber"); const personAcceptSMS = document.getElementById("personAcceptSMS"); + +new ShowHide({ + froms: [maritalStatus], + container: [maritalStatusDate], + test: function(froms) { + for (let f of froms.values()) { + for (let input of f.querySelectorAll('select').values()) { + if (input.value) { + return true + } + } + } + return false; + }, + event_name: 'change' +}); + new ShowHide({ froms: [personEmail], container: [personAcceptEmail], diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig index 95b4e6f62..549025429 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig @@ -60,7 +60,7 @@ {%- endif -%} -{%- if form.nationality is defined or form.spokenLanguages is defined or form.maritalStatus is defined -%} +{%- if form.nationality is defined or form.spokenLanguages is defined -%}

{{ 'Administrative information'|trans }}

{%- if form.nationality is defined -%} @@ -69,11 +69,21 @@ {%- if form.spokenLanguages is defined -%} {{ form_row(form.spokenLanguages, {'label' : 'Spoken languages'}) }} {%- endif -%} +
+{%- endif -%} + +{%- if form.numberOfChildren is defined or form.maritalStatus is defined -%} +
+

{{ 'Marital status'|trans }}

{{ form_row(form.numberOfChildren, {'label' : 'Number of children'}) }} {%- if form.maritalStatus is defined -%} - {{ form_row(form.maritalStatus, { 'label' : 'Marital status'} ) }} - {{ form_row(form.maritalStatusDate, { 'label' : 'Date of last marital status change'} ) }} - {{ form_row(form.maritalStatusComment, { 'label' : 'Comment on the marital status'} ) }} +
+ {{ form_row(form.maritalStatus, { 'label' : 'Marital status'} ) }} +
+
+ {{ form_row(form.maritalStatusDate, { 'label' : 'Date of last marital status change'} ) }} + {{ form_row(form.maritalStatusComment, { 'label' : 'Comment on the marital status'} ) }} +
{%- endif -%}
{%- endif -%} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig index 6176864a0..76c6437d5 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig @@ -185,12 +185,16 @@ This view should receive those arguments: {{ 'No data given'|trans }} {% endif %} + +
{{'Date of last marital status change'|trans}} :
{% if person.maritalStatusDate is not null %}
{{ person.maritalStatusDate|format_date('long') }}
{% endif %} +
+
{% if not person.maritalStatusComment.isEmpty %}
{{'Comment on the marital status'|trans}} :