correctif(attachement_edit): ajoute le cmmposant <form> pour supprimer un attachment via le nouveau <button>

This commit is contained in:
Martin 2023-02-21 15:49:13 +01:00 committed by mfo
parent 99b1bc718b
commit f6fb1ceca5
10 changed files with 17 additions and 7 deletions

View file

@ -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

View file

@ -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|

View file

@ -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',

View file

@ -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

View file

@ -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)

View file

@ -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",

View file

@ -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)

View file

@ -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",

View file

@ -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

View file

@ -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')