diff --git a/app/components/editable_champ/delete_form_repetition_row_component.rb b/app/components/editable_champ/delete_form_repetition_row_component.rb new file mode 100644 index 000000000..e9e8f6ef6 --- /dev/null +++ b/app/components/editable_champ/delete_form_repetition_row_component.rb @@ -0,0 +1,11 @@ +# Display a form for destroying a repetition row via a button, but since it might already be nested within a form +# put this component before the actual form containing the editable champs +class EditableChamp::DeleteFormRepetitionRowComponent < ApplicationComponent + def self.form_id + ActionView::RecordIdentifier.dom_id(Champs::RepetitionChamp.new, :delete) + end + + def call + form_tag('/champs/repetition/:id', method: :delete, data: { 'turbo-method': :delete, turbo: true }, id: self.class.form_id) {} + end +end diff --git a/app/components/editable_champ/multiple_drop_down_list_component/multiple_drop_down_list_component.html.haml b/app/components/editable_champ/multiple_drop_down_list_component/multiple_drop_down_list_component.html.haml index b4434a232..276ee8c47 100644 --- a/app/components/editable_champ/multiple_drop_down_list_component/multiple_drop_down_list_component.html.haml +++ b/app/components/editable_champ/multiple_drop_down_list_component/multiple_drop_down_list_component.html.haml @@ -1,4 +1,3 @@ -- # TODO, manage input id for focus on add repetition - if @champ.options? - if @champ.render_as_checkboxes? = @form.collection_check_boxes(:value, @champ.enabled_non_empty_options, :to_s, :to_s) do |b| diff --git a/app/components/editable_champ/repetition_row_component/repetition_row_component.en.yml b/app/components/editable_champ/repetition_row_component/repetition_row_component.en.yml new file mode 100644 index 000000000..92be3099b --- /dev/null +++ b/app/components/editable_champ/repetition_row_component/repetition_row_component.en.yml @@ -0,0 +1,4 @@ +--- +en: + delete: Destroy element + delete_title: "Destroy the n°%{row_number} element" diff --git a/app/components/editable_champ/repetition_row_component/repetition_row_component.fr.yml b/app/components/editable_champ/repetition_row_component/repetition_row_component.fr.yml new file mode 100644 index 000000000..bfcf389c9 --- /dev/null +++ b/app/components/editable_champ/repetition_row_component/repetition_row_component.fr.yml @@ -0,0 +1,4 @@ +--- +fr: + delete: Supprimer l’élément + delete_title: "Supprimer l’élément n°%{row_number}" 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 02b0bb3ce..000d76e14 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,5 +5,6 @@ = render EditableChamp::EditableChampComponent.new form: form, champ: champ, seen_at: @seen_at .flex.row-reverse{ 'data-turbo': 'true' } - = link_to champs_repetition_path(@champ.id, row_id: @row.first.row_id), data: { turbo_method: :delete }, class: 'fr-btn fr-btn--sm fr-btn--tertiary fr-text-action-high--red-marianne' do - Supprimer l’élément + + = 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/models/champs/repetition_champ.rb b/app/models/champs/repetition_champ.rb index 0de614413..d2dc460bc 100644 --- a/app/models/champs/repetition_champ.rb +++ b/app/models/champs/repetition_champ.rb @@ -28,7 +28,6 @@ class Champs::RepetitionChamp < Champ champs.group_by(&:row_id).values end - def add_row(revision) added_champs = [] transaction do diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index e6eab415f..cace05d4f 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -9,6 +9,7 @@ - form_options = { url: brouillon_dossier_url(dossier), method: :patch } - else - form_options = { url: modifier_dossier_url(dossier), method: :patch } + = render EditableChamp::DeleteFormRepetitionRowComponent.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 9b70a1d36..2d611f52a 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::DeleteFormRepetitionRowComponent.new = render Attachment::DeleteFormComponent.new = form_for dossier, url: annotations_instructeur_dossier_path(dossier.procedure, dossier), html: { class: 'form', multipart: true } do |f| - dossier.champs_private.each do |champ|