diff --git a/app/components/editable_champ/add_form_repetition_row_component.rb b/app/components/editable_champ/add_form_repetition_row_component.rb new file mode 100644 index 000000000..0d20824cc --- /dev/null +++ b/app/components/editable_champ/add_form_repetition_row_component.rb @@ -0,0 +1,11 @@ +# Display a form for adding a repetition row via a button, but since it might already nested within a form +# put this component before the actual form containing the editable champs +class EditableChamp::AddFormRepetitionRowComponent < ApplicationComponent + def self.form_id + ActionView::RecordIdentifier.dom_id(Champs::RepetitionChamp.new, :create) + end + + def call + form_tag('/champs/repetition/:id', method: :post, data: { 'turbo-method': :post, turbo: true }, id: self.class.form_id) {} + end +end diff --git a/app/components/editable_champ/repetition_component/repetition_component.en.yml b/app/components/editable_champ/repetition_component/repetition_component.en.yml new file mode 100644 index 000000000..b2ac2f0fa --- /dev/null +++ b/app/components/editable_champ/repetition_component/repetition_component.en.yml @@ -0,0 +1,4 @@ +--- +en: + add: "Add an element to « %{libelle} »" + add_title: "Add an element to « %{libelle} »" diff --git a/app/components/editable_champ/repetition_component/repetition_component.fr.yml b/app/components/editable_champ/repetition_component/repetition_component.fr.yml new file mode 100644 index 000000000..f4152793e --- /dev/null +++ b/app/components/editable_champ/repetition_component/repetition_component.fr.yml @@ -0,0 +1,4 @@ +--- +fr: + add: "Ajouter un élément pour « %{libelle} »" + add_title: Ajouter un élément pour « %{libelle} » diff --git a/app/components/editable_champ/repetition_component/repetition_component.html.haml b/app/components/editable_champ/repetition_component/repetition_component.html.haml index 572eee90c..392986d3c 100644 --- a/app/components/editable_champ/repetition_component/repetition_component.html.haml +++ b/app/components/editable_champ/repetition_component/repetition_component.html.haml @@ -3,5 +3,5 @@ = render EditableChamp::RepetitionRowComponent.new(form: @form, champ: @champ, row: champs, seen_at: @seen_at) .actions{ 'data-turbo': 'true' } - = link_to champs_repetition_path(@champ.id), data: { turbo_method: :post }, class: 'fr-btn fr-btn--secondary fr-btn--icon-left fr-icon-add-circle-line fr-mb-3w' do - Ajouter un élément pour « #{@champ.libelle} » + = button_tag(name: "action", formaction: champs_repetition_path(@champ.id), class: "fr-btn fr-btn--secondary fr-btn--icon-left fr-icon-add-circle-line fr-mb-3w", title: t(".add_title", libelle: @champ.libelle), form: EditableChamp::AddFormRepetitionRowComponent.form_id) do + = t(".add", libelle: @champ.libelle) diff --git a/app/components/editable_champ/repetition_row_component/repetition_row_component.html.haml b/app/components/editable_champ/repetition_row_component/repetition_row_component.html.haml index 000d76e14..c09a8748a 100644 --- a/app/components/editable_champ/repetition_row_component/repetition_row_component.html.haml +++ b/app/components/editable_champ/repetition_row_component/repetition_row_component.html.haml @@ -5,6 +5,5 @@ = render EditableChamp::EditableChampComponent.new form: form, champ: champ, seen_at: @seen_at .flex.row-reverse{ 'data-turbo': 'true' } - = button_tag(name: "action", formaction: champs_repetition_path(@champ.id, row_id: @row.first.row_id), class: "fr-btn fr-btn--sm fr-btn--tertiary fr-text-action-high--red-marianne", title: t(".delete_title", row_number: @champ.rows.find_index(@row)), form: EditableChamp::DeleteFormRepetitionRowComponent.form_id) do = t(".delete") diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index cace05d4f..b0f46deae 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -10,6 +10,7 @@ - else - form_options = { url: modifier_dossier_url(dossier), method: :patch } = render EditableChamp::DeleteFormRepetitionRowComponent.new + = render EditableChamp::AddFormRepetitionRowComponent.new = render Attachment::DeleteFormComponent.new = form_for dossier, form_options.merge({ html: { id: 'dossier-edit-form', class: 'form', multipart: true, novalidate: 'novalidate' } }) do |f| diff --git a/app/views/shared/dossiers/_edit_annotations.html.haml b/app/views/shared/dossiers/_edit_annotations.html.haml index 2d611f52a..678404fcf 100644 --- a/app/views/shared/dossiers/_edit_annotations.html.haml +++ b/app/views/shared/dossiers/_edit_annotations.html.haml @@ -1,6 +1,7 @@ .container.dossier-edit - if dossier.champs_private.present? %section.counter-start-header-section + = render EditableChamp::AddFormRepetitionRowComponent.new = render EditableChamp::DeleteFormRepetitionRowComponent.new = render Attachment::DeleteFormComponent.new = form_for dossier, url: annotations_instructeur_dossier_path(dossier.procedure, dossier), html: { class: 'form', multipart: true } do |f|