Sha256: ab16e6a2f6cf370f6f2e30239ab5e55e76a030f67d84fde22240cc1f60e40154

Contents?: true

Size: 1.45 KB

Versions: 20

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    # Helper methods for the create initiative wizard.
    module SignatureTypeOptionsHelper
      def signature_type_options(initiative_form)
        return all_signature_type_options unless initiative_form.signature_type_updatable?

        type = ::Decidim::InitiativesType.find(initiative_form.type_id)
        allowed_signatures = type.allowed_signature_types_for_initiatives

        case allowed_signatures
        when %w(online)
          online_signature_type_options
        when %w(offline)
          offline_signature_type_options
        else
          all_signature_type_options
        end
      end

      private

      def online_signature_type_options
        [
          [
            I18n.t(
              "online",
              scope: "activemodel.attributes.initiative.signature_type_values"
            ), "online"
          ]
        ]
      end

      def offline_signature_type_options
        [
          [
            I18n.t(
              "offline",
              scope: "activemodel.attributes.initiative.signature_type_values"
            ), "offline"
          ]
        ]
      end

      def all_signature_type_options
        Initiative.signature_types.keys.map do |type|
          [
            I18n.t(
              type,
              scope: "activemodel.attributes.initiative.signature_type_values"
            ), type
          ]
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
decidim-initiatives-0.29.1 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.28.4 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.27.9 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.29.0 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.28.3 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.27.8 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.29.0.rc4 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.29.0.rc3 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.29.0.rc2 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.29.0.rc1 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.28.2 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.27.7 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.28.1 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.27.6 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.28.0 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.27.5 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.28.0.rc5 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.28.0.rc4 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.27.4 app/helpers/decidim/initiatives/signature_type_options_helper.rb
decidim-initiatives-0.27.3 app/helpers/decidim/initiatives/signature_type_options_helper.rb