Sha256: 52dd1eec90bf3c2a70557913fbb321b1f753f52002895c65711e6a07a536d749

Contents?: true

Size: 1.4 KB

Versions: 25

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    module Admin
      # This class holds a form to start and end the voting period.
      class VotePeriodForm < ActionForm
        validate do
          validations.each do |message, t_args, valid|
            errors.add(message, I18n.t("steps.#{current_step}.errors.#{message}", **t_args, scope: "decidim.elections.admin")) unless valid
          end
        end

        def validations
          @validations ||= if current_step == "key_ceremony_ended"
                             [
                               [:time_before,
                                { start_time: I18n.l(election.start_time, format: :long),
                                  hours: Decidim::Elections.start_vote_maximum_hours_before_start },
                                election.maximum_hours_before_start?]
                             ].freeze
                           else
                             [
                               [:time_after, { end_time: I18n.l(election.end_time, format: :long) }, election.finished?]
                             ].freeze
                           end
        end

        def messages
          @messages ||= validations.map do |message, t_args, _valid|
            [message, I18n.t("steps.#{current_step}.requirements.#{message}", **t_args, scope: "decidim.elections.admin")]
          end.to_h
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-elections-0.26.10 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.9 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.8 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.7 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.5 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.4 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.3 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.2 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.1 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.0 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.0.rc2 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.26.0.rc1 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.25.2 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.25.1 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.25.0 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.25.0.rc4 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.25.0.rc3 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.25.0.rc2 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.25.0.rc1 app/forms/decidim/elections/admin/vote_period_form.rb
decidim-elections-0.24.3 app/forms/decidim/elections/admin/vote_period_form.rb