Sha256: 7476ce2f79b7298962ed67a652b78a15099ac124954890994375ea45f2c2fa36

Contents?: true

Size: 1.68 KB

Versions: 6

Compression:

Stored size: 1.68 KB

Contents

module ActiveScaffold::Bridges
  class CountrySelect
    module FormColumnHelpers
      def active_scaffold_input_country(column, options, ui_options: column.options)
        select_options = {prompt: as_(:_select_), priority_countries: ui_options[:priority] || [:us]}
        select_options[:format] = ui_options[:format] if ui_options[:format]
        select_options.merge!(options)
        options.reverse_merge!(ui_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, ui_options: column.options)
        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, ui_options: column.options)
        active_scaffold_input_country(column, options.merge!(selected: options.delete(:value)), ui_options: ui_options)
      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

6 entries across 6 versions & 1 rubygems

Version Path
active_scaffold-4.0.2 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-4.0.1 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-4.0.0 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-4.0.0.rc3 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-4.0.0.rc2 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-4.0.0.rc1 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb