Sha256: db682d8ce1303d1a5e8477f4ed07f5534affe92b7bbbb6fc22f5e94e537c760c

Contents?: true

Size: 1.55 KB

Versions: 13

Compression:

Stored size: 1.55 KB

Contents

module ActiveScaffold::Bridges
  class CountrySelect
    module FormColumnHelpers
      def active_scaffold_input_country(column, options)
        select_options = {:prompt => as_(:_select_), :priority_countries => column.options[:priority] || [:us], :format => column.options[:format]}
        select_options.merge!(options)
        options.reverse_merge!(column.options).except!(:prompt, :priority, :format)
        active_scaffold_select_name_with_multiple options
        country_select(:record, column.name, select_options, options.except(:object))
      end
    end

    module ListColumnHelpers
      def active_scaffold_column_country(record, column)
        country_code = record.send(column.name)
        return if country_code.blank?
        country = ISO3166::Country[country_code]
        return country_code unless country
        country.translations[I18n.locale.to_s] || country.name
      end
    end

    module SearchColumnHelpers
      def active_scaffold_search_country(column, options)
        active_scaffold_input_country(column, options.merge!(:selected => options.delete(:value)))
      end
    end
  end
end

# To use old way, saving country name instead of CountrySelect default of country code
CountrySelect::FORMATS[:old] = ->(country) { [country.translations[I18n.locale.to_s] || country.name, country.name] }

ActionView::Base.class_eval do
  include ActiveScaffold::Bridges::CountrySelect::FormColumnHelpers
  include ActiveScaffold::Bridges::CountrySelect::ListColumnHelpers
  include ActiveScaffold::Bridges::CountrySelect::SearchColumnHelpers
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
active_scaffold-3.6.3 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.6.2 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.6.1 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.6.0 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.6.0.rc2 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.6.0.rc1 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.5.5 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.6.0.pre lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.5.4 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.5.3 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.5.2 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.5.1 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.5.0 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb