refactor(attachment): rename user_can_download -> explicit view_as

- link: shows a simple link to open attachment
- download: shows complete DSFR download UI
This commit is contained in:
Colin Darie 2022-12-08 00:15:05 +01:00
parent 7c5d27d8e9
commit 4824363879
12 changed files with 43 additions and 32 deletions

View file

@ -1,2 +1,17 @@
class EditableChamp::PieceJustificativeComponent < EditableChamp::EditableChampBaseComponent
def view_as
if @champ.dossier.brouillon?
:link
else
:download
end
end
def user_can_destroy?
!@champ.mandatory? || @champ.dossier.brouillon?
end
def max
[true, nil].include?(@champ.procedure&.piece_justificative_multiple?) ? Attachment::MultipleComponent::DEFAULT_MAX_ATTACHMENTS : 1
end
end

View file

@ -1,7 +1,4 @@
- user_can_destroy = !@champ.mandatory? || @champ.dossier.brouillon?
- user_can_download = !@champ.dossier.brouillon?
- max = [true, nil].include?(@champ.procedure&.piece_justificative_multiple?) ? Attachment::MultipleComponent::DEFAULT_MAX_ATTACHMENTS : 1
= render Attachment::MultipleComponent.new(champ: @champ, attached_file: @champ.piece_justificative_file, form_object_name: @form.object_name, user_can_destroy:, user_can_download:, max:) do |c|
= render Attachment::MultipleComponent.new(champ: @champ, attached_file: @champ.piece_justificative_file, form_object_name: @form.object_name, view_as:, user_can_destroy: user_can_destroy?, max:) do |c|
- if @champ.type_de_champ.piece_justificative_template&.attached?
- c.with_template do
= render partial: "shared/piece_justificative_template", locals: { champ: @champ }