From 1a58dd69c2cfc601721dc9988461af7d6acc44e9 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Thu, 5 Mar 2020 16:57:08 +0100 Subject: [PATCH] replace html labels with h2 elements Some elements should not be html labels, for example when they include sub-elements that contain labels (ex: a radio button that has a label on its own). Those are replaced with title elements --- app/assets/stylesheets/new_design/forms.scss | 6 ++++++ app/helpers/champ_helper.rb | 6 ++++++ .../editable_champs/_champ_label.html.haml | 15 +++++++-------- .../_champ_label_content.html.haml | 7 +++++++ 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 app/views/shared/dossiers/editable_champs/_champ_label_content.html.haml diff --git a/app/assets/stylesheets/new_design/forms.scss b/app/assets/stylesheets/new_design/forms.scss index aa201b22d..0b4c3ae83 100644 --- a/app/assets/stylesheets/new_design/forms.scss +++ b/app/assets/stylesheets/new_design/forms.scss @@ -373,6 +373,12 @@ margin-bottom: $default-padding; } + .label-not-label { + font-weight: bold; + font-size: 18px; + margin-bottom: $default-padding; + } + .explication { margin-bottom: $default-fields-spacer; padding: $default-padding / 2; diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb index a31ca1b58..67c50e4c9 100644 --- a/app/helpers/champ_helper.rb +++ b/app/helpers/champ_helper.rb @@ -4,6 +4,12 @@ module ChampHelper !types_without_label.include?(champ.type_champ) end + def has_html_label?(champ) + types_with_no_html_label = [TypeDeChamp.type_champs.fetch(:civilite), TypeDeChamp.type_champs.fetch(:yes_no), TypeDeChamp.type_champs.fetch(:datetime), TypeDeChamp.type_champs.fetch(:piece_justificative) + ] + types_with_no_html_label.include?(champ.type_champ) + end + def geo_data(champ) # rubocop:disable Rails/OutputSafety raw(champ.to_render_data.to_json) diff --git a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml index 4ca8243dc..127198463 100644 --- a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml +++ b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml @@ -1,11 +1,10 @@ -= form.label champ.main_value_name do - #{champ.libelle} - - if champ.mandatory? - %span.mandatory * - - - if champ.updated_at.present? && seen_at.present? - %span.updated-at{ class: highlight_if_unseen_class(seen_at, champ.updated_at) } - = "modifié le #{try_format_datetime(champ.updated_at)}" += # we do this trick because some html elements should use 'label' and some should be plain paragraphs +- if has_html_label?(champ) + %h2.label-not-label + = render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at } +- else + = form.label champ.main_value_name do + = render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at } - if champ.description.present? .notice{ id: describedby_id(champ) }= string_to_html(champ.description) diff --git a/app/views/shared/dossiers/editable_champs/_champ_label_content.html.haml b/app/views/shared/dossiers/editable_champs/_champ_label_content.html.haml new file mode 100644 index 000000000..7174f7ee5 --- /dev/null +++ b/app/views/shared/dossiers/editable_champs/_champ_label_content.html.haml @@ -0,0 +1,7 @@ +#{champ.libelle} +- if champ.mandatory? + %span.mandatory * + +- if champ.updated_at.present? && seen_at.present? + %span.updated-at{ class: highlight_if_unseen_class(seen_at, champ.updated_at) } + = "modifié le #{try_format_datetime(champ.updated_at)}"