Module: Cdx::Admin::FormHelper

Included in:
BaseHelper
Defined in:
app/helpers/cdx/admin/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#available_locales_options_tagsObject



23
24
25
# File 'app/helpers/cdx/admin/form_helper.rb', line 23

def available_locales_options_tags
  current_settings.available_locales.map { |l| ["#{EmojiFlag.new(l)} (#{l})", l] }
end

#locales_options_tagsObject



19
20
21
# File 'app/helpers/cdx/admin/form_helper.rb', line 19

def locales_options_tags
  Cdx.available_locales.map { |l| ["#{EmojiFlag.new(l)} (#{l})", l] }
end

#select_localeObject



27
28
29
# File 'app/helpers/cdx/admin/form_helper.rb', line 27

def select_locale
  concat select_tag('translation', options_for_select(available_locales_options_tags, current_settings.default_locale), include_blank: false, class: 'select-translation select2-simple')
end

#translated_field(form_object, field, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/cdx/admin/form_helper.rb', line 4

def translated_field(form_object, field, options = {})
  concat form_object.input field, options
  current_settings.available_locales.each do |locale|
    unless locale.to_sym == current_settings.default_locale.to_sym
      options[:label] = form_object.object.class.human_attribute_name(field) + ' ' + EmojiFlag.new(locale)
      options[:input_html]                                   ||= {}
      options[:input_html][:data]                            ||= {}
      options[:input_html][:data][:'translation-for-locale'] = locale
      options[:wrapper_html] ||= {}
      options[:wrapper_html][:class] = 'hidden-translation'
      concat form_object.input "#{field}_#{locale}", options
    end
  end
end