Refactor attachment view

This commit is contained in:
Paul Chavard 2019-05-21 14:21:13 +02:00
parent b55fae440b
commit f6421e081a
10 changed files with 37 additions and 40 deletions

View file

@ -0,0 +1,26 @@
- should_display_link = attachment.virus_scanner.safe? || !attachment.virus_scanner.started?
- user_can_upload = defined?(user_can_upload) ? user_can_upload : false
- if should_display_link
- attachment_check_url = false
- else
- attachment_check_url = attachment_url(attachment.id, { signed_id: attachment.blob.signed_id, user_can_upload: user_can_upload })
.pj-link{ 'data-attachment-id': attachment.id, 'data-attachment-check-url': attachment_check_url }
- if should_display_link
= link_to url_for(attachment.blob), target: '_blank', rel: 'noopener', title: "Télécharger la pièce jointe" do
%span.icon.attachment
= attachment.filename.to_s
- if !attachment.virus_scanner.started?
(ce fichier na pas été analysé par notre antivirus, téléchargez-le avec précaution)
- else
= attachment.filename.to_s
- if attachment.virus_scanner.pending?
(analyse antivirus en cours
= link_to "rafraichir", request.path
)
- elsif attachment.virus_scanner.infected?
- if user_can_upload
(virus détecté, merci denvoyer un autre fichier)
- else
(virus détecté, le téléchargement de ce fichier est bloqué)

View file

@ -2,7 +2,7 @@
- if pj.attached?
.piece-justificative-actions{ id: "piece_justificative_#{object.id}" }
.piece-justificative-action
= render partial: "shared/piece_jointe/pj_link", locals: { pj: pj, user_can_upload: true }
= render partial: "shared/attachment/show", locals: { attachment: pj.attachment, user_can_upload: true }
.piece-justificative-action
= button_tag 'Remplacer', type: 'button', class: 'button small', data: { 'toggle-target': "#champs_#{object.id}" }

View file

@ -1,5 +1,5 @@
- pj = champ.piece_justificative_file
- if pj.attached?
= render partial: "shared/piece_jointe/pj_link", locals: { pj: pj, user_can_upload: false }
= render partial: "shared/attachment/show", locals: { attachment: pj.attachment }
- else
Pièce justificative non fournie

View file

@ -8,4 +8,4 @@
%th.libelle Justificatif :
%td
.action
= render partial: 'shared/piece_jointe/pj_link', locals: { object: dossier, pj: dossier.justificatif_motivation }
= render partial: 'shared/attachment/show', locals: { attachment: dossier.justificatif_motivation.attachment }

View file

@ -9,7 +9,7 @@
- if pj.attached?
.piece-justificative-actions{ id: "piece_justificative_#{champ.id}" }
.piece-justificative-action
= render partial: "shared/piece_jointe/pj_link", locals: { pj: pj, user_can_upload: true }
= render partial: "shared/attachment/show", locals: { attachment: pj.attachment, user_can_upload: true }
.piece-justificative-action
- if champ.private?
= link_to 'Supprimer', gestionnaire_champ_purge_champ_piece_justificative_path(procedure_id: champ.dossier.procedure_id, dossier_id: champ.dossier_id, champ_id: champ.id), remote: true, method: :delete, class: 'button small danger'

View file

@ -1,20 +0,0 @@
- if pj.attached?
.pj-link
- if pj.virus_scanner.safe? || !pj.virus_scanner.started?
= link_to url_for(pj), target: '_blank', rel: 'noopener', title: "Télécharger la pièce jointe" do
%span.icon.attachment
= pj.filename.to_s
- if !pj.virus_scanner.started?
(ce fichier na pas été analysé par notre antivirus, téléchargez-le avec précaution)
- else
= pj.filename.to_s
- if pj.virus_scanner.pending?
(analyse antivirus en cours
= link_to "rafraichir", request.path
)
- elsif pj.virus_scanner.infected?
- if user_can_upload
(virus détecté, merci denvoyer un autre fichier)
- else
(virus détecté, le téléchargement de ce fichier est bloqué)