diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index 31f7575df..a5d2ee21a 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -3,6 +3,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController include CommentableActions include DownloadSettingsHelper include ChangeLogHelper + include Translatable feature_flag :budgets @@ -87,10 +88,10 @@ class Admin::BudgetInvestmentsController < Admin::BaseController end def budget_investment_params - params.require(:budget_investment) - .permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list, + attributes = [:external_url, :heading_id, :administrator_id, :tag_list, :valuation_tag_list, :incompatible, :visible_to_valuators, :selected, - :milestone_tag_list, tracker_ids: [], valuator_ids: [], valuator_group_ids: []) + :milestone_tag_list, tracker_ids: [], valuator_ids: [], valuator_group_ids: []] + params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment)) end def load_budget diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 1aea05085..d5728e254 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -6,6 +6,7 @@ module Budgets include FlagActions include RandomSeed include ImageAttributes + include Translatable PER_PAGE = 10 @@ -122,12 +123,12 @@ module Budgets end def investment_params - params.require(:budget_investment) - .permit(:title, :description, :heading_id, :tag_list, + attributes = [:heading_id, :tag_list, :organization_name, :location, :terms_of_service, :skip_map, image_attributes: image_attributes, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], - map_location_attributes: [:latitude, :longitude, :zoom]) + map_location_attributes: [:latitude, :longitude, :zoom]] + params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment)) end def load_ballot diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index 79a65cf15..da7bb117e 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -1,4 +1,5 @@ class Management::Budgets::InvestmentsController < Management::BaseController + include Translatable before_action :load_budget load_resource :budget @@ -53,8 +54,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController end def investment_params - params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, - :tag_list, :organization_name, :location, :skip_map) + attributes = [:external_url, :heading_id, :tag_list, :organization_name, :location, :skip_map] + params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment)) end def only_verified_users diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index 23e277dd1..8b94f5cac 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -2,24 +2,30 @@ <%= t("shared.back") %> <% end %> -<%= form_for @investment, - url: admin_budget_budget_investment_path(@budget, @investment) do |f| %> +<%= render "admin/shared/globalize_locales", resource: @investment %> + +<%= translatable_form_for @investment, + url: admin_budget_budget_investment_path(@budget, @investment) do |f| %> + + <%= render "shared/errors", resource: @investment %> <% Budget::Investment.filter_params(params).to_h.each do |filter_name, filter_value| %> <%= hidden_field_tag filter_name, filter_value %> <% end %>
-
- <%= f.text_field :title, - maxlength: Budget::Investment.title_max_length %> -
+ <%= f.translatable_fields do |translations_form| %> +
+ <%= translations_form.text_field :title, + maxlength: Budget::Investment.title_max_length %> +
-
- <%= f.cktext_area :description, - maxlength: Budget::Investment.description_max_length, - ckeditor: { language: I18n.locale } %> -
+
+ <%= translations_form.cktext_area :description, + maxlength: Budget::Investment.description_max_length, + ckeditor: { language: I18n.locale } %> +
+ <% end %>
<%= f.label :tag_list, t("admin.budget_investments.edit.user_tags") %> @@ -51,7 +57,6 @@
-
<%= f.label :valuation_tag_list, t("admin.budget_investments.edit.tags") %>
diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index dcc62d92d..c88caca33 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -1,4 +1,7 @@ -<%= form_for(@investment, url: form_url, method: :post, html: { multipart: true }) do |f| %> +<%= render "admin/shared/globalize_locales", resource: @investment %> + +<%= translatable_form_for(@investment, url: form_url, method: :post, html: { multipart: true }) do |f| %> + <%= render "shared/errors", resource: @investment %>
@@ -6,23 +9,25 @@ <%= f.select :heading_id, budget_heading_select_options(@budget), {include_blank: true, } %>
-
- <%= f.text_field :title, - maxlength: Budget::Investment.title_max_length, - data: { js_suggest_result: "js_suggest_result", - js_suggest: "#js-suggest", - js_url: suggest_budget_investments_path(@budget) } %> -
-
+ <%= f.translatable_fields do |translations_form| %> +
+ <%= translations_form.text_field :title, + maxlength: Budget::Investment.title_max_length, + data: { js_suggest_result: "js_suggest_result", + js_suggest: ".js-suggest", + js_url: suggest_budget_investments_path(@budget) }%> +
+
+ +
+ <%= translations_form.cktext_area :description, + maxlength: Budget::Investment.description_max_length, + ckeditor: { language: I18n.locale } %> +
+ <% end %> <%= f.invisible_captcha :subtitle %> -
- <%= f.cktext_area :description, - maxlength: Budget::Investment.description_max_length, - ckeditor: { language: I18n.locale } %> -
- <% if feature?(:allow_images) %>
<%= render "images/nested_image", imageable: @investment, f: f %> diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 8e9495564..6e5f78f68 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -150,6 +150,9 @@ en: organization_name: "If you are proposing in the name of a collective/organization, or on behalf of more people, write its name" image: "Proposal descriptive image" image_title: "Image title" + budget/investment/translation: + title: "Title" + description: "Description" geozone: name: Name external_code: "External code (optional)" diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 626796cc4..e8d8a4efb 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -152,6 +152,9 @@ es: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva del proyecto de gasto" image_title: "Título de la imagen" + budget/investment/translation: + title: "Título" + description: "Descripción" geozone: name: Nombre external_code: "Código externo (opcional)" diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 6b40587a2..8a45ac44f 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -11,6 +11,12 @@ describe "Admin budget investments" do :budget_investment, "admin_budget_budget_investment_path" + it_behaves_like "translatable", + :budget_investment, + "edit_admin_budget_budget_investment_path", + %w[title], + { "description" => :ckeditor } + before do @admin = create(:administrator) login_as(@admin.user) diff --git a/spec/shared/features/translatable.rb b/spec/shared/features/translatable.rb index e2aa5a8b8..9e13643dd 100644 --- a/spec/shared/features/translatable.rb +++ b/spec/shared/features/translatable.rb @@ -402,6 +402,8 @@ def update_button_text "Update milestone" when "AdminNotification" "Update notification" + when "Budget::Investment" + "Update" when "Poll" "Update poll" when "Budget"