From 9766a48d6422496141a784141155cbbcd2c1ff1c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 14 Dec 2017 16:23:15 +0100 Subject: [PATCH] Mutualize a duplicated render instruction --- app/helpers/champ_helper.rb | 5 +++++ .../new_gestionnaire/dossiers/champs/_address.html.haml | 2 -- app/views/new_gestionnaire/dossiers/champs/_champ.html.haml | 5 ++++- .../new_gestionnaire/dossiers/champs/_checkbox.html.haml | 2 -- .../new_gestionnaire/dossiers/champs/_civilite.html.haml | 2 -- app/views/new_gestionnaire/dossiers/champs/_date.html.haml | 2 -- .../new_gestionnaire/dossiers/champs/_datetime.html.haml | 2 -- .../new_gestionnaire/dossiers/champs/_departements.html.haml | 2 -- .../new_gestionnaire/dossiers/champs/_dossier_link.html.haml | 2 -- .../dossiers/champs/_drop_down_list.html.haml | 2 -- app/views/new_gestionnaire/dossiers/champs/_email.html.haml | 2 -- .../new_gestionnaire/dossiers/champs/_engagement.html.haml | 2 -- .../dossiers/champs/_multiple_drop_down_list.html.haml | 2 -- app/views/new_gestionnaire/dossiers/champs/_number.html.haml | 2 -- app/views/new_gestionnaire/dossiers/champs/_pays.html.haml | 2 -- app/views/new_gestionnaire/dossiers/champs/_phone.html.haml | 2 -- .../new_gestionnaire/dossiers/champs/_regions.html.haml | 2 -- app/views/new_gestionnaire/dossiers/champs/_text.html.haml | 2 -- .../new_gestionnaire/dossiers/champs/_textarea.html.haml | 2 -- app/views/new_gestionnaire/dossiers/champs/_yes_no.html.haml | 2 -- 20 files changed, 9 insertions(+), 37 deletions(-) create mode 100644 app/helpers/champ_helper.rb diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb new file mode 100644 index 000000000..b9145628a --- /dev/null +++ b/app/helpers/champ_helper.rb @@ -0,0 +1,5 @@ +module ChampHelper + def is_not_header_nor_explication?(champ) + !['header_section', 'explication'].include?(champ.type_champ) + end +end diff --git a/app/views/new_gestionnaire/dossiers/champs/_address.html.haml b/app/views/new_gestionnaire/dossiers/champs/_address.html.haml index e4ed08e33..24ee6b39b 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_address.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_address.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.text_field :value, 'data-address': 'true', placeholder: champ.libelle, diff --git a/app/views/new_gestionnaire/dossiers/champs/_champ.html.haml b/app/views/new_gestionnaire/dossiers/champs/_champ.html.haml index e852d1674..6b0985b12 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_champ.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_champ.html.haml @@ -1,3 +1,6 @@ .champ + - if is_not_header_nor_explication?(champ) + = render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } + = render partial: "new_gestionnaire/dossiers/champs/#{champ.type_champ}", - locals: { champ: champ, form: form, seen_at: seen_at } + locals: { champ: champ, form: form } diff --git a/app/views/new_gestionnaire/dossiers/champs/_checkbox.html.haml b/app/views/new_gestionnaire/dossiers/champs/_checkbox.html.haml index 882404c2e..3dfe83c16 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_checkbox.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_checkbox.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.check_box :value, { required: champ.mandatory }, 'on', diff --git a/app/views/new_gestionnaire/dossiers/champs/_civilite.html.haml b/app/views/new_gestionnaire/dossiers/champs/_civilite.html.haml index 456af953e..b7df8d6d0 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_civilite.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_civilite.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - .radios %label = form.radio_button :value, 'M.' diff --git a/app/views/new_gestionnaire/dossiers/champs/_date.html.haml b/app/views/new_gestionnaire/dossiers/champs/_date.html.haml index 86b27120a..40794faef 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_date.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_date.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.date_field :value, value: champ.value, placeholder: 'JJ/MM/AAAA', diff --git a/app/views/new_gestionnaire/dossiers/champs/_datetime.html.haml b/app/views/new_gestionnaire/dossiers/champs/_datetime.html.haml index e6a92eceb..a1fe5e0a9 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_datetime.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_datetime.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - - parsed_value = champ.value.present? ? DateTime.parse(champ.value) : DateTime.now .datetime diff --git a/app/views/new_gestionnaire/dossiers/champs/_departements.html.haml b/app/views/new_gestionnaire/dossiers/champs/_departements.html.haml index bd1bf253d..790e22f07 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_departements.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_departements.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.select :value, Champ.departements, required: champ.mandatory diff --git a/app/views/new_gestionnaire/dossiers/champs/_dossier_link.html.haml b/app/views/new_gestionnaire/dossiers/champs/_dossier_link.html.haml index cbf2dea64..4c6fd69b3 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_dossier_link.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_dossier_link.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - - dossier = Dossier.find_by(id: champ.value) - show_text_summary = dossier.present? - show_warning = !show_text_summary && champ.value.present? diff --git a/app/views/new_gestionnaire/dossiers/champs/_drop_down_list.html.haml b/app/views/new_gestionnaire/dossiers/champs/_drop_down_list.html.haml index 2f36bceb8..fbe889285 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_drop_down_list.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_drop_down_list.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - - if champ.drop_down_list && champ.drop_down_list.options.any? = form.select :value, champ.drop_down_list.options, diff --git a/app/views/new_gestionnaire/dossiers/champs/_email.html.haml b/app/views/new_gestionnaire/dossiers/champs/_email.html.haml index f065cb6ca..8cdac1a75 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_email.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_email.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.email_field :value, placeholder: champ.libelle, required: champ.mandatory diff --git a/app/views/new_gestionnaire/dossiers/champs/_engagement.html.haml b/app/views/new_gestionnaire/dossiers/champs/_engagement.html.haml index 882404c2e..3dfe83c16 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_engagement.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_engagement.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.check_box :value, { required: champ.mandatory }, 'on', diff --git a/app/views/new_gestionnaire/dossiers/champs/_multiple_drop_down_list.html.haml b/app/views/new_gestionnaire/dossiers/champs/_multiple_drop_down_list.html.haml index cc8617eaf..8a49cf26e 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_multiple_drop_down_list.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_multiple_drop_down_list.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - - if champ.drop_down_list && champ.drop_down_list.options.any? = form.select :value, champ.drop_down_list.options, diff --git a/app/views/new_gestionnaire/dossiers/champs/_number.html.haml b/app/views/new_gestionnaire/dossiers/champs/_number.html.haml index f020980b9..956daca53 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_number.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_number.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.number_field :value, placeholder: champ.libelle, required: champ.mandatory diff --git a/app/views/new_gestionnaire/dossiers/champs/_pays.html.haml b/app/views/new_gestionnaire/dossiers/champs/_pays.html.haml index f52c146e9..678a06eff 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_pays.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_pays.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.select :value, Champ.pays, required: champ.mandatory diff --git a/app/views/new_gestionnaire/dossiers/champs/_phone.html.haml b/app/views/new_gestionnaire/dossiers/champs/_phone.html.haml index 7888eff8c..32f36f5f8 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_phone.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_phone.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.phone_field :value, placeholder: champ.libelle, required: champ.mandatory diff --git a/app/views/new_gestionnaire/dossiers/champs/_regions.html.haml b/app/views/new_gestionnaire/dossiers/champs/_regions.html.haml index 5946d812c..24863e110 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_regions.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_regions.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.select :value, Champ.regions, required: champ.mandatory diff --git a/app/views/new_gestionnaire/dossiers/champs/_text.html.haml b/app/views/new_gestionnaire/dossiers/champs/_text.html.haml index bef083c2f..6134a07b1 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_text.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_text.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - = form.text_field :value, placeholder: champ.libelle, required: champ.mandatory diff --git a/app/views/new_gestionnaire/dossiers/champs/_textarea.html.haml b/app/views/new_gestionnaire/dossiers/champs/_textarea.html.haml index 4b3b832c8..5f67724f5 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_textarea.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_textarea.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - ~ form.text_area :value, row: 6, placeholder: champ.description, diff --git a/app/views/new_gestionnaire/dossiers/champs/_yes_no.html.haml b/app/views/new_gestionnaire/dossiers/champs/_yes_no.html.haml index 9daf80548..0d8b3bcb0 100644 --- a/app/views/new_gestionnaire/dossiers/champs/_yes_no.html.haml +++ b/app/views/new_gestionnaire/dossiers/champs/_yes_no.html.haml @@ -1,5 +1,3 @@ -= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ, seen_at: seen_at } - .radios %label = form.radio_button :value, true