diff --git a/app/components/attachment/delete_form_component.rb b/app/components/attachment/delete_form_component.rb new file mode 100644 index 000000000..2be43262e --- /dev/null +++ b/app/components/attachment/delete_form_component.rb @@ -0,0 +1,7 @@ +# Display a form for destroying a file attachment via a button, but since it might already be nested within a form +# put this component before the actual form containing the editcomponent +class Attachment::DeleteFormComponent < ApplicationComponent + def call + form_tag('/attachments/:id', method: :delete, data: { 'turbo-method': :delete, turbo: true }, id: dom_id(ActiveStorage::Attachment.new, :delete)) {} + end +end diff --git a/app/views/administrateurs/attestation_templates/edit.html.haml b/app/views/administrateurs/attestation_templates/edit.html.haml index 5fac6a715..4dbeede52 100644 --- a/app/views/administrateurs/attestation_templates/edit.html.haml +++ b/app/views/administrateurs/attestation_templates/edit.html.haml @@ -7,6 +7,7 @@ .procedure-form#attestation-template-edit .procedure-form__columns.container + = render Attachment::DeleteFormComponent.new = form_for @attestation_template, url: admin_procedure_attestation_template_path(@procedure), html: { multipart: true, class: 'form form-ds-fr-white procedure-form__column--form' } do |f| diff --git a/app/views/administrateurs/procedures/edit.html.haml b/app/views/administrateurs/procedures/edit.html.haml index a46cdd144..5bbb0508c 100644 --- a/app/views/administrateurs/procedures/edit.html.haml +++ b/app/views/administrateurs/procedures/edit.html.haml @@ -6,6 +6,7 @@ ['Description']] } .procedure-form .procedure-form__columns.container + = render Attachment::DeleteFormComponent.new = form_for @procedure, url: url_for({ controller: 'administrateurs/procedures', action: :update, id: @procedure.id }), html: { class: 'form procedure-form__column--form', diff --git a/app/views/administrateurs/procedures/new.html.haml b/app/views/administrateurs/procedures/new.html.haml index 6fa4ee0c7..43d196bf6 100644 --- a/app/views/administrateurs/procedures/new.html.haml +++ b/app/views/administrateurs/procedures/new.html.haml @@ -6,12 +6,14 @@ .procedure-form .procedure-form__columns.container + = render Attachment::DeleteFormComponent.new = form_for @procedure, url: url_for({ controller: 'administrateurs/procedures', action: :create, id: @procedure.id }), html: { class: 'form procedure-form__column--form', multipart: true } do |f| %h1.page-title Nouvelle démarche + = render partial: 'administrateurs/procedures/informations', locals: { f: f } .procedure-form__actions.sticky--bottom diff --git a/app/views/experts/avis/instruction.html.haml b/app/views/experts/avis/instruction.html.haml index 0075ee54e..0772abd9d 100644 --- a/app/views/experts/avis/instruction.html.haml +++ b/app/views/experts/avis/instruction.html.haml @@ -14,7 +14,7 @@ - if @avis.introduction_file.attached? = render Attachment::ShowComponent.new(attachment: @avis.introduction_file.attachment) %br/ - + = render Attachment::DeleteFormComponent.new = form_for @avis, url: expert_avis_path(@avis.procedure, @avis), html: { class: 'form', data: { controller: 'persisted-form', persisted_form_key_value: dom_id(@avis) }, multipart: true } do |f| = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true = render Attachment::EditComponent.new(attached_file: @avis.piece_justificative_file, view_as: :download) diff --git a/app/views/experts/shared/avis/_form.html.haml b/app/views/experts/shared/avis/_form.html.haml index 1d6b70ab5..f0bec0090 100644 --- a/app/views/experts/shared/avis/_form.html.haml +++ b/app/views/experts/shared/avis/_form.html.haml @@ -2,7 +2,7 @@ %section.ask-avis %h1.tab-title Inviter des personnes à donner leur avis %p.avis-notice Les invités pourront consulter le dossier, donner un avis et contribuer au fil de messagerie. Ils ne pourront pas modifier le dossier. - + = render Attachment::DeleteFormComponent.new = form_for avis, url: url, html: { class: 'form', multipart: true, data: { controller: 'persisted-form', persisted_form_key_value: dom_id(@avis.dossier, :avis_by_expert) } } do |f| = hidden_field_tag 'avis[emails]', nil = react_component("ComboMultiple", diff --git a/app/views/instructeurs/avis/instruction.html.haml b/app/views/instructeurs/avis/instruction.html.haml index fb9c18335..93deba394 100644 --- a/app/views/instructeurs/avis/instruction.html.haml +++ b/app/views/instructeurs/avis/instruction.html.haml @@ -15,6 +15,7 @@ = render Attachment::ShowComponent.new(attachment: @avis.introduction_file.attachment) %br/ + = render Attachment::DeleteFormComponent.new = form_for @avis, url: instructeur_avis_path(@avis.procedure, @avis), html: { class: 'form' } do |f| = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true = render Attachment::EditComponent.new(attached_file: @avis.piece_justificative_file) diff --git a/app/views/instructeurs/shared/avis/_form.html.haml b/app/views/instructeurs/shared/avis/_form.html.haml index 90248d0f6..99f99c666 100644 --- a/app/views/instructeurs/shared/avis/_form.html.haml +++ b/app/views/instructeurs/shared/avis/_form.html.haml @@ -8,6 +8,7 @@ %p#avis-emails-description.avis-notice Entrez les adresses email des experts à qui vous souhaitez demander un avis + = render Attachment::DeleteFormComponent.new = form_for avis, url: url, html: { class: 'form', multipart: true, data: { controller: 'persisted-form', persisted_form_key_value: dom_id(@dossier, :avis_by_instructeur) } } do |f| = hidden_field_tag 'avis[emails]', nil = react_component("ComboMultiple", diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index b659a126d..0892c575b 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -9,11 +9,7 @@ - form_options = { url: brouillon_dossier_url(dossier), method: :patch, data: { save_on_input: true } } - else - form_options = { url: modifier_dossier_url(dossier), method: :patch } - - %div - = form_tag('/attachments/:id', method: :delete, data: { 'turbo-method': :delete, turbo: true }, id: dom_id(ActiveStorage::Attachment.new, :delete)) do - -# otherwise the closing tag bugs - + = render Attachment::DeleteFormComponent.new = form_for dossier, form_options.merge({ html: { id: 'dossier-edit-form', class: 'form', multipart: true, novalidate: 'novalidate' } }) do |f| %header.mb-6 diff --git a/app/views/shared/dossiers/messages/_form.html.haml b/app/views/shared/dossiers/messages/_form.html.haml index 6d04822bd..2d3845451 100644 --- a/app/views/shared/dossiers/messages/_form.html.haml +++ b/app/views/shared/dossiers/messages/_form.html.haml @@ -1,3 +1,4 @@ += render Attachment::DeleteFormComponent.new = form_for(commentaire, url: form_url, html: { class: 'form', multipart: true, data: { controller: 'persisted-form', persisted_form_key_value: @dossier.present? ? dom_id(@dossier) : dom_id(@procedure, :bulk_message) } }) do |f| - dossier = commentaire.dossier - placeholder = t('views.shared.dossiers.messages.form.write_message_to_administration_placeholder')