<%# TODO: This is mostly just copy pasta from the field_field partial. # Should we just try to make that partial aware of images? # If not, should we make a new dedicated stimulus controler for this partial, # instead of hijacking the "fields--file-field" controller? %> <% form ||= current_fields_form options ||= {} other_options ||= {} options[:multiple] ||= false if defined?(multiple) options[:multiple] = multiple ActiveSupport::Deprecation.new.warn( "The `multiple` attribute will be removed in a later version. " \ "Please pass `options: {multiple: true}` to `render` instead." ) end persisted_files = options[:multiple] ? form.object.send(method) : [form.object.send(method)] options[:width] ||= 100 options[:height] ||= 100 # options[:resize_to_limit] ||= [options[:width], options[:height]] %> <%= render 'shared/fields/field', form: form, method: method, helper: :file_field, options: options, other_options: other_options do %> <% content_for :field do %>
<%= form.file_field method, class: 'file-upload hidden', multiple: options[:multiple], direct_upload: true, data: {'fields--file-field-target': 'fileField', action: 'change->fields--file-field#handleFileSelected'} %>
<% if form.object.send(method).attached? %>
<% persisted_files.each do |file| %>
<%= form.hidden_field "#{method}_removal".to_sym, multiple: options[:multiple], value: nil, data: {'fields--file-item-target': 'removeFileFlag'} %> <%= image_tag photo_url_for_active_storage_attachment(file, options), class: 'mb-1.5 mr-auto', data: {'fields--file-item-target': "fileName"} %> <%= link_to url_for(file), class: 'button download-file mr-3', data: {'fields--file-item-target': 'downloadFileButton'} do %> <%= t('fields.download_image') %> <% end %>
<%= t('fields.remove_image') %>
<% end %>
<% end %>
<% if form.object.send(method).attached? && !options[:multiple] %> <%= t('fields.replace_image') %> <% elsif form.object.send(method).attached? && options[:multiple] %> <%= t('fields.add_another_image') %> <% elsif options[:multiple] %> <%= t('fields.upload_images') %> <% else %> <%= t('fields.upload_image') %> <% end %>
<% end %> <% end %>