Move banner form partial to a component

Other than simplifying the controller, this'll make it easier to write
tests for this code.
This commit is contained in:
Javi Martín
2024-10-11 19:58:10 +02:00
parent 16fc9998c4
commit e850ae2ff9
5 changed files with 22 additions and 13 deletions

View File

@@ -0,0 +1,84 @@
<%= render "shared/globalize_locales", resource: banner %>
<%= translatable_form_for [:admin, banner] do |f| %>
<%= render "shared/errors", resource: banner %>
<div class="row">
<div class="small-12 medium-3 column">
<%= f.date_field :post_started_at, id: "post_started_at" %>
</div>
<div class="small-12 medium-3 column end">
<%= f.date_field :post_ended_at, id: "post_ended_at" %>
</div>
</div>
<div class="row">
<%= f.translatable_fields do |translations_form| %>
<div class="small-12 medium-6 column">
<%= translations_form.text_field :title,
data: { js_banner_title: "js_banner_title" } %>
</div>
<div class="small-12 column">
<%= translations_form.text_field :description,
data: { js_banner_description: "js_banner_description" } %>
</div>
<% end %>
</div>
<div class="row">
<div class="small-12 medium-6 column">
<%= f.text_field :target_url %>
</div>
</div>
<div class="row">
<fieldset class="small-12 column">
<legend><%= t("admin.banners.banner.sections_label") %></legend>
<%= f.collection_check_boxes(:web_section_ids, sections, :id, :name) do |b| %>
<%= b.label do %>
<%= b.check_box + t("admin.banners.banner.sections.#{b.text}") %>
<% end %>
<% end %>
</fieldset>
</div>
<div class="row">
<div class="small-12 medium-6 large-3 column">
<%= f.label :background_color, nil, for: "background_color_input" %>
<p class="help-text"><%= t("admin.shared.color_help") %></p>
<div class="row collapse">
<div class="small-12 medium-6 column">
<%= f.text_field :background_color, label: false, type: :color %>
</div>
<div class="small-12 medium-6 column">
<%= f.text_field :background_color, label: false, id: "background_color_input" %>
</div>
</div>
</div>
<div class="small-12 medium-6 large-3 column end">
<%= f.label :font_color, nil, for: "font_color_input" %>
<p class="help-text"><%= t("admin.shared.color_help") %></p>
<div class="row collapse">
<div class="small-12 medium-6 column">
<%= f.text_field :font_color, label: false, type: :color %>
</div>
<div class="small-12 medium-6 column">
<%= f.text_field :font_color, label: false, id: "font_color_input" %>
</div>
</div>
</div>
</div>
<div class="row">
<div class="actions small-12 medium-3 column">
<%= f.submit(class: "button expanded", value: t("admin.banners.edit.form.submit_button")) %>
</div>
</div>
<div class="row">
<%= render Shared::BannerComponent.new(banner) %>
</div>
<% end %>

View File

@@ -0,0 +1,15 @@
class Admin::Banners::FormComponent < ApplicationComponent
include TranslatableFormHelper
include GlobalizeHelper
attr_reader :banner
def initialize(banner)
@banner = banner
end
private
def sections
WebSection.all
end
end