Move debate form partial to a component
We're going to rewrite most of the code, so we might as well treat it like we treat new files.
This commit is contained in:
50
app/components/debates/form_component.html.erb
Normal file
50
app/components/debates/form_component.html.erb
Normal file
@@ -0,0 +1,50 @@
|
||||
<%= render "shared/globalize_locales", resource: debate %>
|
||||
|
||||
<%= translatable_form_for(debate) do |f| %>
|
||||
|
||||
<%= render "shared/errors", resource: debate %>
|
||||
|
||||
<div class="row column">
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
<div class="small-12 column">
|
||||
<%= translations_form.text_field :title,
|
||||
maxlength: Debate.title_max_length,
|
||||
data: suggest_data(debate) %>
|
||||
</div>
|
||||
<div class="js-suggest" data-locale="<%= translations_form.locale %>"></div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= translations_form.text_area :description,
|
||||
maxlength: Debate.description_max_length,
|
||||
class: "html-area" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= f.invisible_captcha :subtitle %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.text_field :tag_list, value: debate.tag_list.to_s,
|
||||
hint: t("debates.form.tags_instructions"),
|
||||
placeholder: t("debates.form.tags_placeholder"),
|
||||
data: { js_url: suggest_tags_path },
|
||||
class: "tag-autocomplete" %>
|
||||
</div>
|
||||
|
||||
<%= render SDG::RelatedListSelectorComponent.new(f) %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<% if debate.new_record? %>
|
||||
<%= f.check_box :terms_of_service,
|
||||
title: t("form.accept_terms_title"),
|
||||
label: t("form.accept_terms",
|
||||
policy: link_to(t("form.policy"), "/privacy", target: "blank"),
|
||||
conditions: link_to(t("form.conditions"), "/conditions", target: "blank")
|
||||
) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="actions small-12 column">
|
||||
<%= f.submit(class: "button", value: t("debates.#{action_name}.form.submit_button")) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
10
app/components/debates/form_component.rb
Normal file
10
app/components/debates/form_component.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class Debates::FormComponent < ApplicationComponent
|
||||
include TranslatableFormHelper
|
||||
include GlobalizeHelper
|
||||
attr_reader :debate
|
||||
delegate :suggest_data, to: :helpers
|
||||
|
||||
def initialize(debate)
|
||||
@debate = debate
|
||||
end
|
||||
end
|
||||
@@ -1,50 +1 @@
|
||||
<%= render "shared/globalize_locales", resource: @debate %>
|
||||
|
||||
<%= translatable_form_for(@debate) do |f| %>
|
||||
|
||||
<%= render "shared/errors", resource: @debate %>
|
||||
|
||||
<div class="row column">
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
<div class="small-12 column">
|
||||
<%= translations_form.text_field :title,
|
||||
maxlength: Debate.title_max_length,
|
||||
data: suggest_data(@debate) %>
|
||||
</div>
|
||||
<div class="js-suggest" data-locale="<%= translations_form.locale %>"></div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= translations_form.text_area :description,
|
||||
maxlength: Debate.description_max_length,
|
||||
class: "html-area" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= f.invisible_captcha :subtitle %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.text_field :tag_list, value: @debate.tag_list.to_s,
|
||||
hint: t("debates.form.tags_instructions"),
|
||||
placeholder: t("debates.form.tags_placeholder"),
|
||||
data: { js_url: suggest_tags_path },
|
||||
class: "tag-autocomplete" %>
|
||||
</div>
|
||||
|
||||
<%= render SDG::RelatedListSelectorComponent.new(f) %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<% if @debate.new_record? %>
|
||||
<%= f.check_box :terms_of_service,
|
||||
title: t("form.accept_terms_title"),
|
||||
label: t("form.accept_terms",
|
||||
policy: link_to(t("form.policy"), "/privacy", target: "blank"),
|
||||
conditions: link_to(t("form.conditions"), "/conditions", target: "blank")
|
||||
) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="actions small-12 column">
|
||||
<%= f.submit(class: "button", value: t("debates.#{action_name}.form.submit_button")) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= render Debates::FormComponent.new(@debate) %>
|
||||
|
||||
Reference in New Issue
Block a user