Add proposals translation interface

* Convert proposal form into translatable one.
 * Adapt translatable shared spec to define an owner when running at
   frontend feature specs.
 * Remove old attributes from strong parameters.
This commit is contained in:
Senén Rodero Rodríguez
2018-12-23 17:40:10 +01:00
committed by voodoorai2000
parent 4ce006ec96
commit bd3bb72370
5 changed files with 60 additions and 31 deletions

View File

@@ -1,6 +1,7 @@
class Management::ProposalsController < Management::BaseController class Management::ProposalsController < Management::BaseController
include HasOrders include HasOrders
include CommentableActions include CommentableActions
include Translatable
before_action :only_verified_users, except: :print before_action :only_verified_users, except: :print
before_action :set_proposal, only: [:vote, :show] before_action :set_proposal, only: [:vote, :show]
@@ -52,10 +53,10 @@ class Management::ProposalsController < Management::BaseController
end end
def proposal_params def proposal_params
params.require(:proposal).permit(:title, :summary, :description, :video_url, attributes = [:video_url, :responsible_name, :tag_list,
:responsible_name, :tag_list, :terms_of_service, :geozone_id, :terms_of_service, :geozone_id,
:skip_map, :skip_map, map_location_attributes: [:latitude, :longitude, :zoom]]
map_location_attributes: [:latitude, :longitude, :zoom]) params.require(:proposal).permit(attributes, translation_params(Proposal))
end end
def resource_model def resource_model

View File

@@ -3,6 +3,7 @@ class ProposalsController < ApplicationController
include CommentableActions include CommentableActions
include FlagActions include FlagActions
include ImageAttributes include ImageAttributes
include Translatable
before_action :parse_tag_filter, only: :index before_action :parse_tag_filter, only: :index
before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary] before_action :load_categories, only: [:index, :new, :create, :edit, :map, :summary]
@@ -37,7 +38,6 @@ class ProposalsController < ApplicationController
def create def create
@proposal = Proposal.new(proposal_params.merge(author: current_user)) @proposal = Proposal.new(proposal_params.merge(author: current_user))
if @proposal.save if @proposal.save
redirect_to created_proposal_path(@proposal), notice: I18n.t("flash.actions.create.proposal") redirect_to created_proposal_path(@proposal), notice: I18n.t("flash.actions.create.proposal")
else else
@@ -98,12 +98,13 @@ class ProposalsController < ApplicationController
private private
def proposal_params def proposal_params
params.require(:proposal).permit(:title, :summary, :description, :video_url, attributes = [:video_url,:responsible_name, :tag_list,
:responsible_name, :tag_list, :terms_of_service, :terms_of_service, :geozone_id, :skip_map,
:geozone_id, :skip_map, image_attributes: image_attributes, image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, documents_attributes: [:id, :title, :attachment, :cached_attachment,
:cached_attachment, :user_id, :_destroy], :user_id, :_destroy],
map_location_attributes: [:latitude, :longitude, :zoom]) map_location_attributes: [:latitude, :longitude, :zoom]]
params.require(:proposal).permit(attributes, translation_params(Proposal))
end end
def retired_params def retired_params

View File

@@ -64,6 +64,10 @@ module ProposalsHelper
proposals_current_view == "default" ? "minimal" : "default" proposals_current_view == "default" ? "minimal" : "default"
end end
def summary_help_text_id(translations_form)
"summary-help-text-#{translations_form.locale}"
end
def link_to_toggle_proposal_selection(proposal) def link_to_toggle_proposal_selection(proposal)
if proposal.selected? if proposal.selected?
button_text = t("admin.proposals.index.selected") button_text = t("admin.proposals.index.selected")

View File

@@ -1,32 +1,50 @@
<%= form_for(@proposal, url: form_url) do |f| %> <%= render "admin/shared/globalize_locales", resource: @proposal %>
<%= translatable_form_for(@proposal, url: form_url) do |f| %>
<%= render "shared/errors", resource: @proposal %> <%= render "shared/errors", resource: @proposal %>
<div class="row"> <div class="row">
<%= f.translatable_fields do |translations_form| %>
<div class="small-12 column"> <div class="small-12 column">
<%= f.label :title, t("proposals.form.proposal_title") %> <%= translations_form.text_field :title,
<%= f.text_field :title, maxlength: Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false, data: {js_suggest_result: "js_suggest_result", js_suggest: "#js-suggest", js_url: suggest_proposals_path}%> maxlength: Proposal.title_max_length,
placeholder: t("proposals.form.proposal_title"),
label: t("proposals.form.proposal_title"),
data: { js_suggest_result: "js_suggest_result",
js_suggest: "#js-suggest",
js_url: suggest_proposals_path } %>
</div> </div>
<div id="js-suggest"></div> <div id="js-suggest"></div>
<div class="small-12 column">
<%= translations_form.label :summary %>
<p class="help-text" id=<%= summary_help_text_id(translations_form) %>>
<%= t("proposals.form.proposal_summary_note") %>
</p>
<%= translations_form.text_area :summary,
rows: 4, maxlength: 200,
label: false,
placeholder: t("proposals.form.proposal_summary"),
aria: {describedby: summary_help_text_id(translations_form)} %>
</div>
<div class="ckeditor small-12 column">
<%= translations_form.cktext_area :description,
maxlength: Proposal.description_max_length,
ckeditor: { language: I18n.locale },
label: t("proposals.form.proposal_text") %>
</div>
<% end %>
<%= f.invisible_captcha :subtitle %> <%= f.invisible_captcha :subtitle %>
<div class="small-12 column">
<%= f.label :summary, t("proposals.form.proposal_summary") %>
<p class="help-text" id="summary-help-text"><%= t("proposals.form.proposal_summary_note") %></p>
<%= f.text_area :summary, rows: 4, maxlength: 200, label: false,
placeholder: t("proposals.form.proposal_summary"),
aria: {describedby: "summary-help-text"} %>
</div>
<div class="ckeditor small-12 column">
<%= f.label :description, t("proposals.form.proposal_text") %>
<%= f.cktext_area :description, maxlength: Proposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
</div>
<div class="small-12 column"> <div class="small-12 column">
<%= f.label :video_url, t("proposals.form.proposal_video_url") %> <%= f.label :video_url, t("proposals.form.proposal_video_url") %>
<p class="help-text" id="video-url-help-text"><%= t("proposals.form.proposal_video_url_note") %></p> <p class="help-text" id="video-url-help-text"><%= t("proposals.form.proposal_video_url_note") %></p>
<%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), label: false, <%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"),
label: false,
aria: {describedby: "video-url-help-text"} %> aria: {describedby: "video-url-help-text"} %>
</div> </div>

View File

@@ -15,6 +15,11 @@ describe "Proposals" do
context "Concerns" do context "Concerns" do
it_behaves_like "notifiable in-app", Proposal it_behaves_like "notifiable in-app", Proposal
it_behaves_like "relationable", Proposal it_behaves_like "relationable", Proposal
it_behaves_like "translatable",
"proposal",
"edit_proposal_path",
%w[title summary],
{ "description" => :ckeditor }
end end
context "Index" do context "Index" do