2011-12-01 23:04:45 +00:00
|
|
|
module Locomotive
|
|
|
|
class LocaleInput < Formtastic::Inputs::TextInput
|
|
|
|
|
2011-12-02 00:43:49 +00:00
|
|
|
include Formtastic::Inputs::Base::Choices
|
|
|
|
|
2011-12-01 23:04:45 +00:00
|
|
|
def to_html
|
|
|
|
input_wrapping do
|
|
|
|
label_html <<
|
|
|
|
self.available_locales_to_html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def available_locales_to_html
|
|
|
|
template.content_tag(:div,
|
|
|
|
Locomotive.config.locales.map do |locale|
|
|
|
|
template.content_tag(:div, locale_to_html(locale).html_safe, :class => 'entry')
|
|
|
|
end.join.html_safe, :class => 'list')
|
|
|
|
end
|
|
|
|
|
|
|
|
def locale_to_html(locale)
|
|
|
|
text = I18n.t("locomotive.my_account.edit.#{locale}")
|
|
|
|
|
2011-12-02 00:43:49 +00:00
|
|
|
builder.radio_button(:locale, locale, :id => choice_input_dom_id(locale)) +
|
2011-12-01 23:04:45 +00:00
|
|
|
template.content_tag(:label,
|
|
|
|
template.image_tag("locomotive/icons/flags/#{locale}.png", :alt => text) +
|
2011-12-02 00:43:49 +00:00
|
|
|
text, :for => choice_input_dom_id(locale))
|
|
|
|
end
|
|
|
|
|
|
|
|
def choice_input_dom_id(choice)
|
|
|
|
[
|
|
|
|
builder.custom_namespace,
|
|
|
|
sanitized_object_name,
|
|
|
|
association_primary_key || method,
|
|
|
|
choice_html_safe_value(choice)
|
|
|
|
].compact.reject { |i| i.blank? }.join("_")
|
2011-12-01 23:04:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|