This commit is contained in:
Kara Diaby 2024-02-13 07:04:27 +00:00
parent bec9af90e8
commit 7092583b0a
5 changed files with 57 additions and 36 deletions

View file

@ -1,4 +1,24 @@
.attachment.fr-upload-group{ { id: attachment ? dom_id(attachment, :edit) : nil, class: class_names("fr-mb-1w": !(as_multiple? && downloadable?)) }.compact }
.attachment.fr-upload-group{ id: (attachment ? dom_id(attachment, :edit) : nil), class: class_names("fr-mb-1w": !(as_multiple? && attachments.any?(&:persisted?))) }
- if as_multiple?
- attachments.each do |attachment|
- if attachment.persisted?
%div{ id: dom_id(attachment, :persisted_row) }
.flex.flex-gap-2{ class: class_names("attachment-error": attachment.virus_scanner_error?) }
- if user_can_destroy?
= render NestedForms::OwnedButtonComponent.new(formaction: destroy_attachment_path, http_method: :delete, opt: {class: "fr-btn fr-btn--tertiary fr-btn--sm fr-icon-delete-line", title: t(".delete_file", filename: attachment.filename)}) do
= t('.delete')
- if downloadable?(attachment)
= render Dsfr::DownloadComponent.new(attachment: attachment)
- else
.fr-py-1v
%span.attachment-filename.fr-mr-1w= link_to_if(viewable?(attachment), attachment.filename.to_s, helpers.url_for(attachment.blob), title: t(".open_file", filename: attachment.filename), **helpers.external_link_attributes)
= render Attachment::ProgressComponent.new(attachment: attachment, ignore_antivirus: true)
- if error?(attachment)
%p.fr-error-text= error_message(attachment)
- else
- if persisted?
%div{ id: dom_id(attachment, :persisted_row) }
.flex.flex-gap-2{ class: class_names("attachment-error": attachment.virus_scanner_error?) }
@ -6,30 +26,30 @@
= render NestedForms::OwnedButtonComponent.new(formaction: destroy_attachment_path, http_method: :delete, opt: {class: "fr-btn fr-btn--tertiary fr-btn--sm fr-icon-delete-line", title: t(".delete_file", filename: attachment.filename)}) do
= t('.delete')
- if downloadable?
- if downloadable?(attachment)
= render Dsfr::DownloadComponent.new(attachment:)
- else
.fr-py-1v
%span.attachment-filename.fr-mr-1w= link_to_if(viewable?, attachment.filename.to_s, helpers.url_for(attachment.blob), title: t(".open_file", filename: attachment.filename), **helpers.external_link_attributes)
%span.attachment-filename.fr-mr-1w= link_to_if(viewable?(attachment), attachment.filename.to_s, helpers.url_for(attachment.blob), title: t(".open_file", filename: attachment.filename), **helpers.external_link_attributes)
= render Attachment::ProgressComponent.new(attachment: attachment, ignore_antivirus: true)
- if error?
%p.fr-error-text= error_message
- if error?(attachment)
%p.fr-error-text= error_message(attachment)
- elsif first?
- if first? && !persisted?
%p.fr-hint-text.fr-mb-1w
- if max_file_size.present?
= t('.max_file_size', max_file_size: number_to_human_size(max_file_size))
- if allowed_formats.present?
= t('.allowed_formats', formats: allowed_formats.join(', '))
- if !as_multiple?
- if !persisted? || champ.present? && champ.titre_identite?
= file_field(champ, field_name, **file_field_options)
- if persisted?
- Attachment::PendingPollComponent.new(attachment: attachment, poll_url:, context: poll_context).then do |component|
- attachments.filter(&:persisted?).each do |attachment|
- if attachment.persisted?
- Attachment::PendingPollComponent.new(attachment: attachment, poll_url: poll_url, context: poll_context).then do |component|
.fr-mt-2w
= render component

View file

@ -5,10 +5,10 @@
%ul.fr-my-1v
- each_attachment do |attachment, index|
%li{ id: dom_id(attachment) }
= render Attachment::EditComponent.new(champ:, attached_file:, attachment:, index:, as_multiple: true, view_as:, user_can_destroy:, form_object_name:)
= render Attachment::EditComponent.new(champ:, attached_file:, attachment:, index:, view_as:, user_can_destroy:, form_object_name:)
%div{ id: empty_component_id, class: class_names("hidden": !can_attach_next?), data: { turbo_force: :server } }
= render Attachment::EditComponent.new(champ:, attached_file:, attachment: nil, index: attachments_count, user_can_destroy:, form_object_name:)
= render Attachment::EditComponent.new(champ:, as_multiple: champ.present? ? champ.allow_multiple_attachments? : true, attached_file:, attachment: nil, index: attachments_count, user_can_destroy:, form_object_name:)
// single poll and refresh message for all attachments
= render Attachment::PendingPollComponent.new(attachments: attachments, poll_url:, context: poll_context)

View file

@ -27,7 +27,9 @@
- if groupe_gestionnaire.nil? && commentaire.piece_jointe.attached?
.fr-ml-2w
= render Attachment::ShowComponent.new(attachment: commentaire.piece_jointe.attachment, new_tab: true)
- commentaire.piece_jointe.each do |attachment|
= render Attachment::ShowComponent.new(attachment: attachment, new_tab: true)
- if show_reply_button?
= button_tag type: 'button', class: 'fr-btn fr-btn--sm fr-btn--secondary fr-icon-arrow-go-back-line fr-btn--icon-left', onclick: 'document.querySelector("#commentaire_body").focus()' do

View file

@ -8,12 +8,10 @@
%p.mandatory-explanation= t('asterisk_html', scope: [:utils])
= render Dsfr::InputComponent.new(form: f, attribute: :body, input_type: :text_area, opts: { rows: 5, placeholder: placeholder, title: placeholder, class: 'fr-input message-textarea'})
- if local_assigns.has_key?(:dossier)
.fr-mt-3w{ data: { controller: "file-input-reset" } }
= render Attachment::EditComponent.new(attached_file: commentaire.piece_jointe)
%button.hidden.fr-btn.fr-btn--tertiary-no-outline.fr-btn--icon-left.fr-icon-delete-line{ data: { 'file-input-reset-target': 'reset', action: 'file-input-reset#reset' } }
= t('views.shared.messages.remove_file')
.fr-mt-3w{ data: { controller: "file-input-reset", delete_label: t('views.shared.messages.remove_file') } }
= render Attachment::MultipleComponent.new(attached_file: commentaire.piece_jointe)
%ul{ data: { 'file-input-reset-target': 'fileList' } }
.fr-mt-3w
= f.submit t('views.shared.dossiers.messages.form.send_message'), class: 'fr-btn', data: { disable: true }

View file

@ -23,3 +23,4 @@ fr:
signin: 'Se connecter'
messages:
remove_file: 'Supprimer le fichier'
remove_all: "Supprimer tous les fichiers"