<% slides = post.slides.to_a %> <% max_size = Setting.get("slideshow_max_size", 5).to_i %> <% ordered_ids = slides.map(&:id) %>

Slideshow

Ordered localized images for this post.

<%= slides.size %> / <%= max_size %>

<% if slides.size >= max_size %>
Slideshow limit reached
<% else %> <%= form_with url: admin_post_slides_path(post, locale: I18n.locale), scope: :slide, method: :post, local: true, html: { multipart: true, class: "space-y-4 rounded-lg border border-dashed border-gray-300 p-4" } do |form| %>
<%= form.label :image, "Slide image", class: "block text-sm font-semibold text-gray-700" %> <%= form.file_field :image, accept: "image/jpeg,image/png,image/webp,image/gif", class: "mt-1 block w-full text-sm text-gray-700" %>
<% I18n.available_locales.each do |locale| %>

<%= locale %>

<%= label_tag "slide_translations_#{locale}_caption", "Caption", class: "block text-xs font-semibold text-gray-600" %> <%= text_field_tag "slide[translations][#{locale}][caption]", nil, id: "slide_translations_#{locale}_caption", class: "mt-1 block w-full rounded-lg border-gray-300 text-sm" %> <%= label_tag "slide_translations_#{locale}_alt_text", "Alt text", class: "mt-3 block text-xs font-semibold text-gray-600" %> <%= text_field_tag "slide[translations][#{locale}][alt_text]", nil, id: "slide_translations_#{locale}_alt_text", class: "mt-1 block w-full rounded-lg border-gray-300 text-sm" %>
<% end %>
<%= form.submit "Add slide", class: "rounded-lg bg-indigo-600 px-4 py-2 text-sm font-semibold text-white" %> <% end %> <% end %>
<% slides.each_with_index do |slide, index| %>
<%= image_tag slide.image, alt: slide.alt_text_for(I18n.locale).to_s, class: "aspect-video w-full rounded-lg object-cover" %>

Position <%= slide.position %>

<%= form_with model: [:admin, post, slide], local: true, class: "space-y-4" do |form| %>
<%= form.label :image, "Replace image", class: "block text-sm font-semibold text-gray-700" %> <%= form.file_field :image, accept: "image/jpeg,image/png,image/webp,image/gif", class: "mt-1 block w-full text-sm text-gray-700" %>
<% I18n.available_locales.each do |locale| %> <% caption = Mobility.with_locale(locale) { slide.caption(fallback: false) } %> <% alt_text = Mobility.with_locale(locale) { slide.alt_text(fallback: false) } %>

<%= locale %>

<%= label_tag "slide_#{slide.id}_#{locale}_caption", "Caption", class: "block text-xs font-semibold text-gray-600" %> <%= text_field_tag "slide[translations][#{locale}][caption]", caption, id: "slide_#{slide.id}_#{locale}_caption", class: "mt-1 block w-full rounded-lg border-gray-300 text-sm" %> <%= label_tag "slide_#{slide.id}_#{locale}_alt_text", "Alt text", class: "mt-3 block text-xs font-semibold text-gray-600" %> <%= text_field_tag "slide[translations][#{locale}][alt_text]", alt_text, id: "slide_#{slide.id}_#{locale}_alt_text", class: "mt-1 block w-full rounded-lg border-gray-300 text-sm" %>
<% end %>
<%= form.submit "Save slide", class: "rounded-lg bg-indigo-600 px-4 py-2 text-sm font-semibold text-white" %> <% end %>
<% if index.positive? %> <% up_ids = ordered_ids.dup.tap { |ids| ids[index - 1], ids[index] = ids[index], ids[index - 1] } %> <%= form_with url: reorder_admin_post_slides_path(post, locale: I18n.locale), method: :patch, local: true do %> <% up_ids.each do |slide_id| %> <%= hidden_field_tag "slide_ids[]", slide_id %> <% end %> <%= submit_tag "Move up", class: "rounded-lg border border-gray-300 px-3 py-2 text-sm font-semibold text-gray-700" %> <% end %> <% end %> <% if index < slides.length - 1 %> <% down_ids = ordered_ids.dup.tap { |ids| ids[index], ids[index + 1] = ids[index + 1], ids[index] } %> <%= form_with url: reorder_admin_post_slides_path(post, locale: I18n.locale), method: :patch, local: true do %> <% down_ids.each do |slide_id| %> <%= hidden_field_tag "slide_ids[]", slide_id %> <% end %> <%= submit_tag "Move down", class: "rounded-lg border border-gray-300 px-3 py-2 text-sm font-semibold text-gray-700" %> <% end %> <% end %> <%= button_to "Delete slide", admin_post_slide_path(post, slide, locale: I18n.locale), method: :delete, class: "rounded-lg px-3 py-2 text-sm font-semibold text-rose-700" %>
<% end %>