Sha256: a6671b5dbbb5dc20406f1f22fb4f86489bd21d1b7b71a950b98baa1cc2e350ac

Contents?: true

Size: 1.46 KB

Versions: 26

Compression:

Stored size: 1.46 KB

Contents

module Locomotive
  class LocalesInput < ::Formtastic::Inputs::CheckBoxesInput

    def to_html
      input_wrapping do
        label_html <<
        choices_group_wrapping do
          collection.map { |choice|
            choice_wrapping(choice_wrapping_html_options(choice)) do
              choice_html(choice)
            end
          }.join("\n").html_safe
        end
      end
    end

    def choices_group_wrapping(&block)
      template.content_tag(:div,
        template.capture(&block) +
        template.content_tag(:div, '', class: 'clear'),
        choices_group_wrapping_html_options
      )
    end

    def choice_wrapping(html_options, &block)
      template.content_tag(:div,
        template.capture(&block),
        html_options
      )
    end

    def choice_html(choice)
      check_box_without_hidden_input(choice) <<
      template.content_tag(:label,
        choice_label(choice),
        label_html_options.merge(for: choice_input_dom_id(choice), class: nil)
      )
    end

    def choice_label(choice)
      text = I18n.t("locomotive.locales.#{choice}")
      template.image_tag("locomotive/icons/flags/#{choice}.png", alt: text, size: '24x24') << text
    end

    def choices_group_wrapping_html_options
      { class: 'list' }
    end

    def choice_wrapping_html_options(choice)
      super.tap do |options|
        options[:class] = "entry #{checked?(choice) ? 'selected' : ''}"
      end
    end

    def hidden_fields?
      false
    end

  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
locomotive_cms-2.2.0 app/inputs/locomotive/locales_input.rb
locomotive_cms-2.1.4 app/inputs/locomotive/locales_input.rb
locomotive_cms-2.1.3 app/inputs/locomotive/locales_input.rb
locomotive_cms-2.1.2 app/inputs/locomotive/locales_input.rb
locomotive_cms-2.1.1 app/inputs/locomotive/locales_input.rb
locomotive_cms-2.1.0 app/inputs/locomotive/locales_input.rb