diff --git a/app/components/attachment/show_component.rb b/app/components/attachment/show_component.rb index abb263a7b..4bc8416e7 100644 --- a/app/components/attachment/show_component.rb +++ b/app/components/attachment/show_component.rb @@ -1,9 +1,10 @@ class Attachment::ShowComponent < ApplicationComponent - def initialize(attachment:) + def initialize(attachment:, new_tab: false) @attachment = attachment + @new_tab = new_tab end - attr_reader :attachment + attr_reader :attachment, :new_tab def should_display_link? (attachment.virus_scanner.safe? || !attachment.virus_scanner.started?) && !attachment.watermark_pending? diff --git a/app/components/attachment/show_component/show_component.html.haml b/app/components/attachment/show_component/show_component.html.haml index ecbe23e66..7a91132fa 100644 --- a/app/components/attachment/show_component/show_component.html.haml +++ b/app/components/attachment/show_component/show_component.html.haml @@ -1,6 +1,6 @@ %div{ id: dom_id(attachment, :show), class: class_names("attachment-error": error?, "fr-mb-2w": !should_display_link?) } - if should_display_link? - = render Dsfr::DownloadComponent.new(attachment: attachment) do |c| + = render Dsfr::DownloadComponent.new(attachment: attachment, new_tab: new_tab) do |c| - if !attachment.virus_scanner.started? - c.right do = "(#{t(".virus_not_analyzed")})" diff --git a/app/components/dsfr/download_component.rb b/app/components/dsfr/download_component.rb index edcc15d39..2b92ca77c 100644 --- a/app/components/dsfr/download_component.rb +++ b/app/components/dsfr/download_component.rb @@ -4,11 +4,13 @@ class Dsfr::DownloadComponent < ApplicationComponent attr_reader :attachment attr_reader :html_class attr_reader :name + attr_reader :new_tab - def initialize(attachment:, name: nil, url: nil) + def initialize(attachment:, name: nil, url: nil, new_tab: false) @attachment = attachment @name = name || attachment.filename.to_s @url = url + @new_tab = new_tab end def title diff --git a/app/components/dsfr/download_component/download_component.html.haml b/app/components/dsfr/download_component/download_component.html.haml index f2ea95bcd..aed3645c3 100644 --- a/app/components/dsfr/download_component/download_component.html.haml +++ b/app/components/dsfr/download_component/download_component.html.haml @@ -1,6 +1,6 @@ .fr-download %p - = link_to url, download: "", class: "fr-download__link", title: title do + = link_to url, {class: "fr-download__link", title: title}.merge(new_tab ? { target: '_blank' } : { download: '' }) do = name %span.fr-download__detail = helpers.download_details(attachment) diff --git a/app/views/shared/champs/piece_justificative/_show.html.haml b/app/views/shared/champs/piece_justificative/_show.html.haml index ca4d4bd43..2b2eac563 100644 --- a/app/views/shared/champs/piece_justificative/_show.html.haml +++ b/app/views/shared/champs/piece_justificative/_show.html.haml @@ -3,6 +3,6 @@ .fr-downloads-group %ul - pj.attachments.each do |attachment| - %li= render Attachment::ShowComponent.new(attachment:) + %li= render Attachment::ShowComponent.new(attachment:, new_tab: true) - else Pièce justificative non fournie