Sha256: 2170f51d6d292472b68c4b5e1f56ef42a7ab2553e90f8ca60a6ee2c21d7f3479

Contents?: true

Size: 1.68 KB

Versions: 10

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

10 entries across 10 versions & 1 rubygems

Version Path
active_scaffold-3.7.12 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.7.11.1 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.7.11 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.7.10 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.7.8 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.7.7 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.7.6 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.7.5 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.7.2 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb
active_scaffold-3.7.1 lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb