Update information texts translatable fields
This part used the code we deleted in order to make it easier to refactor the rest of the translatable models. Now we add the code back.
This commit is contained in:
@@ -35,9 +35,11 @@ App.Globalize =
|
||||
|
||||
enable_locale: (locale) ->
|
||||
App.Globalize.destroy_locale_field(locale).val(false)
|
||||
App.Globalize.site_customization_enable_locale_field(locale).val(1)
|
||||
|
||||
disable_locale: (locale) ->
|
||||
App.Globalize.destroy_locale_field(locale).val(true)
|
||||
App.Globalize.site_customization_enable_locale_field(locale).val(0)
|
||||
|
||||
enabled_locales: ->
|
||||
$.map(
|
||||
@@ -48,6 +50,9 @@ App.Globalize =
|
||||
destroy_locale_field: (locale) ->
|
||||
$(".destroy_locale[data-locale=" + locale + "]")
|
||||
|
||||
site_customization_enable_locale_field: (locale) ->
|
||||
$("#enabled_translations_" + locale)
|
||||
|
||||
refresh_visible_translations: ->
|
||||
locale = $('.js-globalize-locale-link.is-active').data("locale")
|
||||
App.Globalize.display_translations(locale)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomization::BaseController
|
||||
include Translatable
|
||||
before_action :delete_translations, only: [:update]
|
||||
|
||||
def index
|
||||
fetch_existing_keys
|
||||
@@ -9,7 +9,7 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
|
||||
|
||||
def update
|
||||
content_params.each do |content|
|
||||
values = content[:values].slice(*translation_params(I18nContent))
|
||||
values = content[:values].slice(*translation_params)
|
||||
|
||||
unless values.empty?
|
||||
values.each do |key, value|
|
||||
@@ -73,4 +73,15 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
|
||||
end
|
||||
end
|
||||
|
||||
def translation_params
|
||||
I18nContent.translated_attribute_names.product(enabled_translations).map do |attr_name, loc|
|
||||
I18nContent.localized_attr_name_for(attr_name, loc)
|
||||
end
|
||||
end
|
||||
|
||||
def enabled_translations
|
||||
params.fetch(:enabled_translations, {})
|
||||
.select { |_, v| v == '1' }
|
||||
.keys
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,10 +9,4 @@ module Translatable
|
||||
resource_model.translated_attribute_names
|
||||
}
|
||||
end
|
||||
|
||||
def enabled_translations
|
||||
params.fetch(:enabled_translations, {})
|
||||
.select { |_, v| v == '1' }
|
||||
.keys
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,12 +19,4 @@ module SiteCustomizationHelper
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def merge_translatable_field_options(options, locale)
|
||||
options.merge(
|
||||
class: "#{options[:class]} js-globalize-attribute".strip,
|
||||
style: "#{options[:style]} #{site_customization_display_translation_style(locale)}".strip,
|
||||
data: (options[:data] || {}).merge(locale: locale)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ class I18nContent < ActiveRecord::Base
|
||||
validates :key, uniqueness: true
|
||||
|
||||
translates :value, touch: true
|
||||
globalize_accessors locales: [:en, :es, :fr, :nl]
|
||||
globalize_accessors
|
||||
|
||||
# flat_hash returns a flattened hash, a hash with a single level of
|
||||
# depth in which each key is composed from the keys of the original
|
||||
|
||||
@@ -2,5 +2,8 @@
|
||||
<%= hidden_field_tag "contents[content_#{content.key}][id]", content.key %>
|
||||
<%= text_area_tag "contents[content_#{content.key}]values[value_#{locale}]",
|
||||
translation_for_locale(content, locale) || t(content.key, locale: locale),
|
||||
merge_translatable_field_options({rows: 5}, locale) %>
|
||||
rows: 5,
|
||||
class: "js-globalize-attribute",
|
||||
style: site_customization_display_translation_style(locale),
|
||||
data: { locale: locale } %>
|
||||
<% end %>
|
||||
|
||||
@@ -268,7 +268,11 @@ end
|
||||
|
||||
def expect_page_to_have_translatable_field(field, locale, with:)
|
||||
if input_fields.include?(field)
|
||||
if translatable_class.name == "I18nContent" && with.blank?
|
||||
expect(page).to have_field field_for(field, locale)
|
||||
else
|
||||
expect(page).to have_field field_for(field, locale), with: with
|
||||
end
|
||||
else
|
||||
textarea_type = textarea_fields[field]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user