Extract components to render custom image table actions
This way it'll be easier to refactor them. We're also giving a proper title to the images index page.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<%= header %>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("admin.site_customization.images.index.image") %></th>
|
||||
<th><%= t("admin.actions.actions") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% images.each do |image| %>
|
||||
<tr id="image_<%= image.name %>">
|
||||
<td class="small-12 medium-4">
|
||||
<strong><%= image.name %></strong> (<%= image.required_width %>x<%= image.required_height %>)
|
||||
</td>
|
||||
<td class="small-12 medium-8">
|
||||
<%= render Admin::SiteCustomization::Images::TableActionsComponent.new(image) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -0,0 +1,14 @@
|
||||
class Admin::SiteCustomization::Images::IndexComponent < ApplicationComponent
|
||||
include Header
|
||||
attr_reader :images
|
||||
|
||||
def initialize(images)
|
||||
@images = images
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def title
|
||||
t("admin.site_customization.images.index.title")
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
<div class="site-customization-images-table-actions">
|
||||
<%= form_for([:admin, image], html: { id: "edit_#{dom_id(image)}" }) do |f| %>
|
||||
<div class="small-12 medium-6 large-6 column">
|
||||
<%= image_tag image.image if image.persisted_attachment? %>
|
||||
<%= f.file_field :image, label: false %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 large-6 column">
|
||||
<%= f.submit(t("admin.site_customization.images.index.update"), class: "button hollow") %>
|
||||
<%= link_to t("admin.site_customization.images.index.delete"), admin_site_customization_image_path(image), method: :delete, class: "button hollow alert" if image.persisted_attachment? %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -0,0 +1,7 @@
|
||||
class Admin::SiteCustomization::Images::TableActionsComponent < ApplicationComponent
|
||||
attr_reader :image
|
||||
|
||||
def initialize(image)
|
||||
@image = image
|
||||
end
|
||||
end
|
||||
@@ -1,31 +1 @@
|
||||
<h2><%= t("admin.site_customization.images.index.title") %></h2>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("admin.site_customization.images.index.image") %></th>
|
||||
<th><%= t("admin.actions.actions") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @images.each do |image| %>
|
||||
<tr id="image_<%= image.name %>">
|
||||
<td class="small-12 medium-4">
|
||||
<strong><%= image.name %></strong> (<%= image.required_width %>x<%= image.required_height %>)
|
||||
</td>
|
||||
<td class="small-12 medium-8">
|
||||
<%= form_for([:admin, image], html: { id: "edit_#{dom_id(image)}" }) do |f| %>
|
||||
<div class="small-12 medium-6 large-6 column">
|
||||
<%= image_tag image.image if image.persisted_attachment? %>
|
||||
<%= f.file_field :image, label: false %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 large-6 column">
|
||||
<%= f.submit(t("admin.site_customization.images.index.update"), class: "button hollow") %>
|
||||
<%= link_to t("admin.site_customization.images.index.delete"), admin_site_customization_image_path(image), method: :delete, class: "button hollow alert" if image.persisted_attachment? %>
|
||||
</div>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<%= render Admin::SiteCustomization::Images::IndexComponent.new(@images) %>
|
||||
|
||||
Reference in New Issue
Block a user