Sha256: 996f1f0d0915fb7e6a85ee72fe7797d8c2300f0f2f034f0db4571b7146621ec1

Contents?: true

Size: 1 KB

Versions: 88

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Initiatives
    # Common logic for elements that need to be able to select initiative types.
    module TypeSelectorOptions
      extend ActiveSupport::Concern

      include Decidim::TranslationsHelper

      included do
        helper_method :available_initiative_types, :initiative_type_options,
                      :initiative_types_each

        private

        # Return all initiative types with scopes defined.
        def available_initiative_types
          Decidim::Initiatives::InitiativeTypes
            .for(current_organization)
            .joins(:scopes)
            .distinct
        end

        def initiative_type_options
          available_initiative_types.map do |type|
            [type.title[I18n.locale.to_s], type.id]
          end
        end

        def initiative_types_each
          available_initiative_types.each do |type|
            yield(type)
          end
        end
      end
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
decidim-initiatives-0.20.1 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.20.0 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.19.1 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.18.1 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.19.0 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.17.2 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.18.0 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.17.1 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.16.1 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.17.0 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.16.0 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.15.2 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.15.1 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.15.0 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.14.4 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.14.3 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.14.2 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.14.1 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.13.1 app/controllers/concerns/decidim/initiatives/type_selector_options.rb
decidim-initiatives-0.12.2 app/controllers/concerns/decidim/initiatives/type_selector_options.rb