1c61f2de58
Make it more reusable, by: - Renaming `attachment/update` to `attachment/edit` - Refactoring the CSS styles into their own stylesheet - Allow to specify the 'accept' option
29 lines
1.3 KiB
Text
29 lines
1.3 KiB
Text
-# Display a widget for uploading, editing and deleting a file attachment
|
|
|
|
- attachment = attached_file.attachment
|
|
- attachment_id = attachment ? attachment.id : SecureRandom.uuid
|
|
- persisted = attachment && attachment.persisted?
|
|
- accept = defined?(accept) ? accept : nil
|
|
- user_can_destroy = defined?(user_can_destroy) ? user_can_destroy : false
|
|
|
|
.attachment
|
|
- if defined?(template) && template.attached?
|
|
%p.mb-1
|
|
Veuillez télécharger, remplir et joindre
|
|
= link_to('le modèle suivant', url_for(template), target: '_blank', rel: 'noopener')
|
|
|
|
- if persisted
|
|
.attachment-actions{ id: "attachment_#{attachment_id}" }
|
|
.attachment-action
|
|
= render partial: "shared/attachment/show", locals: { attachment: attachment, user_can_upload: true }
|
|
- if user_can_destroy
|
|
.attachment-action
|
|
= link_to 'Supprimer', attachment_url(attachment.id, { signed_id: attachment.blob.signed_id }), remote: true, method: :delete, class: 'button small danger'
|
|
.attachment-action
|
|
= button_tag 'Remplacer', type: 'button', class: 'button small', data: { 'toggle-target': "#attachment_file_#{attachment_id}" }
|
|
|
|
= form.file_field attached_file.name,
|
|
id: "attachment_file_#{attachment_id}",
|
|
class: "attachment-input #{'hidden' if persisted}",
|
|
accept: accept,
|
|
direct_upload: true
|