Class: Decidim::Elections::Admin::ElectionForm

Inherits:
Form
  • Object
show all
Includes:
AttachmentAttributes, HasUploadValidations, TranslatableAttributes
Defined in:
app/forms/decidim/elections/admin/election_form.rb

Overview

Form to create or update an election.

Instance Method Summary collapse

Instance Method Details

#electionObject



50
51
52
# File 'app/forms/decidim/elections/admin/election_form.rb', line 50

def election
  @election ||= context[:election]
end

#map_model(election) ⇒ Object



34
35
36
37
38
# File 'app/forms/decidim/elections/admin/election_form.rb', line 34

def map_model(election)
  self.manual_start = election.start_at.blank?
  self.attachments = election.attachments.ids
  self.add_attachments = election.attachments.map { |att| { id: att.id, title: att.title } }
end

#per_question_not_started?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/forms/decidim/elections/admin/election_form.rb', line 46

def per_question_not_started?
  results_availability == "per_question" && start_at.blank?
end

#results_availability_labelsObject



40
41
42
43
44
# File 'app/forms/decidim/elections/admin/election_form.rb', line 40

def results_availability_labels
  Decidim::Elections::Election::RESULTS_AVAILABILITY_OPTIONS.map do |type|
    [type, I18n.t("decidim.elections.admin.elections.form.results_availability.#{type}")]
  end
end

#scheduled_election?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'app/forms/decidim/elections/admin/election_form.rb', line 54

def scheduled_election?
  election&.scheduled?
end