Class: Decidim::Votings::Admin::PollingStationForm

Inherits:
Form show all
Includes:
TranslatableAttributes
Defined in:
decidim-elections/app/forms/decidim/votings/admin/polling_station_form.rb

Overview

This class holds a Form to create/update votings from Decidim's admin panel.

Constant Summary

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from AttributeObject::Form

#context

Instance Method Summary collapse

Methods included from TranslatableAttributes

#default_locale?

Methods inherited from AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#geocoded?Boolean

Returns:


23
24
25
# File 'decidim-elections/app/forms/decidim/votings/admin/polling_station_form.rb', line 23

def geocoded?
  latitude.present? && longitude.present?
end

#geocoding_enabled?Boolean

Returns:


15
16
17
# File 'decidim-elections/app/forms/decidim/votings/admin/polling_station_form.rb', line 15

def geocoding_enabled?
  Decidim::Map.available?(:geocoding)
end

#has_address?Boolean

Returns:


19
20
21
# File 'decidim-elections/app/forms/decidim/votings/admin/polling_station_form.rb', line 19

def has_address?
  geocoding_enabled? && address.present?
end

#map_model(model) ⇒ Object


10
11
12
13
# File 'decidim-elections/app/forms/decidim/votings/admin/polling_station_form.rb', line 10

def map_model(model)
  self.polling_station_president_id = model.polling_station_president&.id
  self.polling_station_manager_ids = model.polling_station_managers.pluck(:id)
end

#polling_station_managersObject


31
32
33
# File 'decidim-elections/app/forms/decidim/votings/admin/polling_station_form.rb', line 31

def polling_station_managers
  @polling_station_managers ||= PollingOfficer.where(id: polling_station_manager_ids)
end

#polling_station_presidentObject


27
28
29
# File 'decidim-elections/app/forms/decidim/votings/admin/polling_station_form.rb', line 27

def polling_station_president
  @polling_station_president ||= PollingOfficer.find_by(id: polling_station_president_id)
end

#votingObject Also known as: component


35
36
37
# File 'decidim-elections/app/forms/decidim/votings/admin/polling_station_form.rb', line 35

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