Move proposals form partial to a component
Since now categories are loaded in both the investment form component and proposal form component, and their controllers are the only "commentable" controllers using the `@categories` instance variable, we can remove the `load_categories` call in `CommentableActions` affecting the create and update actions.
This commit is contained in:
109
app/components/proposals/form_component.html.erb
Normal file
109
app/components/proposals/form_component.html.erb
Normal file
@@ -0,0 +1,109 @@
|
||||
<%= render "shared/globalize_locales", resource: proposal %>
|
||||
|
||||
<%= translatable_form_for(proposal, url: url) do |f| %>
|
||||
|
||||
<%= render "shared/errors", resource: proposal %>
|
||||
|
||||
<div class="row column">
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
<div class="small-12 column">
|
||||
<%= translations_form.text_field :title,
|
||||
maxlength: Proposal.title_max_length,
|
||||
data: suggest_data(proposal) %>
|
||||
</div>
|
||||
<div class="js-suggest" data-locale="<%= translations_form.locale %>"></div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= translations_form.text_area :summary,
|
||||
rows: 4, maxlength: 200,
|
||||
hint: t("proposals.form.proposal_summary_note") %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= translations_form.text_area :description,
|
||||
maxlength: Proposal.description_max_length,
|
||||
class: "html-area" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= f.invisible_captcha :subtitle %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.text_field :video_url, hint: t("proposals.form.proposal_video_url_note") %>
|
||||
</div>
|
||||
|
||||
<% if feature?(:allow_images) %>
|
||||
<div class="images small-12 column">
|
||||
<%= render "images/nested_image", imageable: proposal, f: f %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if feature?(:allow_attached_documents) %>
|
||||
<div class="documents small-12 column">
|
||||
<%= render "documents/nested_documents", documentable: proposal, f: f %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.select :geozone_id, geozone_select_options,
|
||||
include_blank: t("geozones.none") %>
|
||||
</div>
|
||||
|
||||
<% if feature?(:map) %>
|
||||
<div class="small-12 column">
|
||||
<%= render "map_locations/form_fields",
|
||||
form: f,
|
||||
map_location: proposal.map_location || MapLocation.new,
|
||||
label: t("proposals.form.map_location"),
|
||||
help: t("proposals.form.map_location_instructions"),
|
||||
remove_marker_label: t("proposals.form.map_remove_marker"),
|
||||
parent_class: "proposal",
|
||||
i18n_namespace: "proposals" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :tag_list, t("proposals.form.tags_label") %>
|
||||
<p class="help-text" id="tag-list-help-text"><%= t("proposals.form.tags_instructions") %></p>
|
||||
|
||||
<div id="category_tags" class="tags">
|
||||
<%= f.label :category_tag_list, t("proposals.form.tag_category_label") %>
|
||||
<% categories.each do |tag| %>
|
||||
<a class="js-add-tag-link"><%= tag.name %></a>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<%= f.text_field :tag_list, value: proposal.tag_list.to_s,
|
||||
label: false,
|
||||
placeholder: t("proposals.form.tags_placeholder"),
|
||||
class: "js-tag-list tag-autocomplete",
|
||||
aria: { describedby: "tag-list-help-text" },
|
||||
data: { js_url: suggest_tags_path } %>
|
||||
</div>
|
||||
|
||||
<% if current_user.unverified? %>
|
||||
<div class="small-12 column">
|
||||
<%= f.text_field :responsible_name,
|
||||
hint: t("proposals.form.proposal_responsible_name_note") %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render SDG::RelatedListSelectorComponent.new(f) %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<% if proposal.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("proposals.#{action_name}.form.submit_button")) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
17
app/components/proposals/form_component.rb
Normal file
17
app/components/proposals/form_component.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
class Proposals::FormComponent < ApplicationComponent
|
||||
include TranslatableFormHelper
|
||||
include GlobalizeHelper
|
||||
attr_reader :proposal, :url
|
||||
delegate :current_user, :suggest_data, :geozone_select_options, to: :helpers
|
||||
|
||||
def initialize(proposal, url:)
|
||||
@proposal = proposal
|
||||
@url = url
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def categories
|
||||
Tag.category.order(:name)
|
||||
end
|
||||
end
|
||||
@@ -52,7 +52,6 @@ module CommentableActions
|
||||
redirect_path = url_for(controller: controller_name, action: :show, id: @resource.id)
|
||||
redirect_to redirect_path, notice: t("flash.actions.create.#{resource_name.underscore}")
|
||||
else
|
||||
load_categories
|
||||
load_geozones
|
||||
set_resource_instance
|
||||
render :new
|
||||
@@ -66,7 +65,6 @@ module CommentableActions
|
||||
if resource.update(strong_params)
|
||||
redirect_to resource, notice: t("flash.actions.update.#{resource_name.underscore}")
|
||||
else
|
||||
load_categories
|
||||
load_geozones
|
||||
set_resource_instance
|
||||
render :edit
|
||||
|
||||
@@ -7,7 +7,6 @@ class Management::ProposalsController < Management::BaseController
|
||||
before_action :only_verified_users, except: :print
|
||||
before_action :set_proposal, only: [:vote, :show]
|
||||
before_action :parse_search_terms, only: :index
|
||||
before_action :load_categories, only: [:new, :edit]
|
||||
before_action :load_geozones, only: [:edit]
|
||||
|
||||
has_orders %w[confidence_score hot_score created_at most_commented random], only: [:index, :print]
|
||||
@@ -22,7 +21,6 @@ class Management::ProposalsController < Management::BaseController
|
||||
redirect_path = url_for(controller: controller_name, action: :show, id: @resource.id)
|
||||
redirect_to redirect_path, notice: t("flash.actions.create.#{resource_name.underscore}")
|
||||
else
|
||||
load_categories
|
||||
load_geozones
|
||||
set_resource_instance
|
||||
render :new
|
||||
|
||||
@@ -7,7 +7,7 @@ class ProposalsController < ApplicationController
|
||||
include MapLocationAttributes
|
||||
include Translatable
|
||||
|
||||
before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary]
|
||||
before_action :load_categories, only: [:index, :map, :summary]
|
||||
before_action :load_geozones, only: [:edit, :map, :summary]
|
||||
before_action :authenticate_user!, except: [:index, :show, :map, :summary]
|
||||
before_action :destroy_map_location_association, only: :update
|
||||
|
||||
@@ -1,111 +1 @@
|
||||
<%= render "shared/globalize_locales", resource: @proposal %>
|
||||
|
||||
<%= translatable_form_for(@proposal, url: form_url) do |f| %>
|
||||
|
||||
<%= render "shared/errors", resource: @proposal %>
|
||||
|
||||
<div class="row column">
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
<div class="small-12 column">
|
||||
<%= translations_form.text_field :title,
|
||||
maxlength: Proposal.title_max_length,
|
||||
data: suggest_data(@proposal) %>
|
||||
</div>
|
||||
<div class="js-suggest" data-locale="<%= translations_form.locale %>"></div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= translations_form.text_area :summary,
|
||||
rows: 4, maxlength: 200,
|
||||
hint: t("proposals.form.proposal_summary_note") %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= translations_form.text_area :description,
|
||||
maxlength: Proposal.description_max_length,
|
||||
class: "html-area" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= f.invisible_captcha :subtitle %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.text_field :video_url, hint: t("proposals.form.proposal_video_url_note") %>
|
||||
</div>
|
||||
|
||||
<% if feature?(:allow_images) %>
|
||||
<div class="images small-12 column">
|
||||
<%= render "images/nested_image", imageable: @proposal, f: f %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if feature?(:allow_attached_documents) %>
|
||||
<div class="documents small-12 column">
|
||||
<%= render "documents/nested_documents", documentable: @proposal, f: f %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.select :geozone_id, geozone_select_options,
|
||||
include_blank: t("geozones.none") %>
|
||||
</div>
|
||||
|
||||
<% if feature?(:map) %>
|
||||
<div class="small-12 column">
|
||||
|
||||
<%= render "map_locations/form_fields",
|
||||
form: f,
|
||||
map_location: @proposal.map_location || MapLocation.new,
|
||||
label: t("proposals.form.map_location"),
|
||||
help: t("proposals.form.map_location_instructions"),
|
||||
remove_marker_label: t("proposals.form.map_remove_marker"),
|
||||
parent_class: "proposal",
|
||||
i18n_namespace: "proposals" %>
|
||||
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :tag_list, t("proposals.form.tags_label") %>
|
||||
<p class="help-text" id="tag-list-help-text"><%= t("proposals.form.tags_instructions") %></p>
|
||||
|
||||
<div id="category_tags" class="tags">
|
||||
<%= f.label :category_tag_list, t("proposals.form.tag_category_label") %>
|
||||
<% @categories.each do |tag| %>
|
||||
<a class="js-add-tag-link"><%= tag.name %></a>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<%= f.text_field :tag_list, value: @proposal.tag_list.to_s,
|
||||
label: false,
|
||||
placeholder: t("proposals.form.tags_placeholder"),
|
||||
class: "js-tag-list tag-autocomplete",
|
||||
aria: { describedby: "tag-list-help-text" },
|
||||
data: { js_url: suggest_tags_path } %>
|
||||
</div>
|
||||
|
||||
<% if current_user.unverified? %>
|
||||
<div class="small-12 column">
|
||||
<%= f.text_field :responsible_name,
|
||||
hint: t("proposals.form.proposal_responsible_name_note") %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render SDG::RelatedListSelectorComponent.new(f) %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<% if @proposal.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("proposals.#{action_name}.form.submit_button")) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= render Proposals::FormComponent.new(@proposal, url: form_url) %>
|
||||
|
||||
Reference in New Issue
Block a user