diff --git a/app/helpers/globalize_helper.rb b/app/helpers/globalize_helper.rb index 15ad85da5..d82fe2e43 100644 --- a/app/helpers/globalize_helper.rb +++ b/app/helpers/globalize_helper.rb @@ -11,15 +11,19 @@ module GlobalizeHelper end def display_translation?(locale) - same_locale?(I18n.locale, locale) ? "" : "display: none;" + locale == I18n.locale + end + + def display_translation_style(locale) + "display: none;" unless display_translation?(locale) end def translation_enabled_tag(locale, enabled) hidden_field_tag("enabled_translations[#{locale}]", (enabled ? 1 : 0)) end - def css_to_display_translation?(resource, locale) - enable_locale?(resource, locale) ? "" : "display: none;" + def enable_translation_style(resource, locale) + "display: none;" unless enable_locale?(resource, locale) end def enable_locale?(resource, locale) @@ -28,12 +32,8 @@ module GlobalizeHelper resource.translations.reject(&:_destroy).map(&:locale).include?(locale) || locale == I18n.locale end - def highlight_current?(locale) - same_locale?(I18n.locale, locale) ? 'is-active' : '' - end - - def show_delete?(locale) - display_translation?(locale) + def highlight_class(locale) + "is-active" if display_translation?(locale) end def globalize(locale, &block) diff --git a/app/helpers/site_customization_helper.rb b/app/helpers/site_customization_helper.rb index 1b4968b6c..8b6fccb31 100644 --- a/app/helpers/site_customization_helper.rb +++ b/app/helpers/site_customization_helper.rb @@ -3,7 +3,15 @@ module SiteCustomizationHelper I18nContentTranslation.existing_languages.include?(locale) || locale == I18n.locale end - def site_customization_display_translation?(locale) + def site_customization_display_translation_style(locale) site_customization_enable_translation?(locale) ? "" : "display: none;" 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 diff --git a/app/helpers/translatable_form_helper.rb b/app/helpers/translatable_form_helper.rb index 8d14a1d74..136c518ce 100644 --- a/app/helpers/translatable_form_helper.rb +++ b/app/helpers/translatable_form_helper.rb @@ -5,14 +5,6 @@ module TranslatableFormHelper end end - def merge_translatable_field_options(options, locale) - options.merge( - class: "#{options[:class]} js-globalize-attribute".strip, - style: "#{options[:style]} #{display_translation?(locale)}".strip, - data: options.fetch(:data, {}).merge(locale: locale), - ) - end - class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder def translatable_fields(&block) @object.globalize_locales.map do |locale| @@ -62,7 +54,7 @@ module TranslatableFormHelper content_tag :div, label_help_text_and_field, class: "js-globalize-attribute", - style: @template.display_translation?(locale), + style: display_style, data: { locale: locale } else label_help_text_and_field @@ -75,30 +67,34 @@ module TranslatableFormHelper end def label(attribute, text = nil, options = {}) - label_options = options.merge( - class: "#{options[:class]} js-globalize-attribute".strip, - style: "#{options[:style]} #{@template.display_translation?(locale)}".strip, - data: (options[:data] || {}) .merge(locale: locale) - ) - + label_options = translations_options(options) hint = label_options.delete(:hint) + super(attribute, text, label_options) + help_text(hint) end + def display_style + @template.display_translation_style(locale) + end + private def help_text(text) if text content_tag :span, text, class: "help-text js-globalize-attribute", data: { locale: locale }, - style: @template.display_translation?(locale) + style: display_style else "" end end def translations_options(options) - @template.merge_translatable_field_options(options, locale) + options.merge( + class: "#{options[:class]} js-globalize-attribute".strip, + style: "#{options[:style]} #{display_style}".strip, + data: (options[:data] || {}).merge(locale: locale) + ) end end end diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index 729ed071c..417a303fe 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -35,7 +35,7 @@ <%= content_tag :div, class: "markdown-editor clear js-globalize-attribute", data: { locale: translations_form.locale }, - style: display_translation?(translations_form.locale) do %> + style: translations_form.display_style do %>