Class: Decidim::Assemblies::Admin::AssemblyForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Assemblies::Admin::AssemblyForm
- Includes:
- HasUploadValidations, TranslatableAttributes
- Defined in:
- app/forms/decidim/assemblies/admin/assembly_form.rb
Overview
A form object used to create assemblies from the admin dashboard.
Constant Summary collapse
- CREATED_BY =
%w(city_council public others).freeze
Instance Method Summary collapse
- #area ⇒ Object
- #assembly_type ⇒ Object
- #assembly_types_for_select ⇒ Object
- #created_by_for_select ⇒ Object
- #ensure_parent_cannot_be_child ⇒ Object
- #map_model(model) ⇒ Object
- #parent ⇒ Object
- #processes_for_select ⇒ Object
- #scope ⇒ Object
Instance Method Details
#area ⇒ Object
102 103 104 |
# File 'app/forms/decidim/assemblies/admin/assembly_form.rb', line 102 def area @area ||= current_organization.areas.find_by(id: area_id) end |
#assembly_type ⇒ Object
130 131 132 |
# File 'app/forms/decidim/assemblies/admin/assembly_form.rb', line 130 def assembly_type AssembliesType.find_by(id: decidim_assemblies_type_id) end |
#assembly_types_for_select ⇒ Object
106 107 108 109 |
# File 'app/forms/decidim/assemblies/admin/assembly_form.rb', line 106 def assembly_types_for_select @assembly_types_for_select ||= organization_assembly_types &.map { |type| [translated_attribute(type.title), type.id] } end |
#created_by_for_select ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'app/forms/decidim/assemblies/admin/assembly_form.rb', line 111 def created_by_for_select CREATED_BY.map do |creator| [ I18n.t("created_by.#{creator}", scope: "decidim.assemblies"), creator ] end end |
#ensure_parent_cannot_be_child ⇒ Object
87 88 89 90 91 92 |
# File 'app/forms/decidim/assemblies/admin/assembly_form.rb', line 87 def ensure_parent_cannot_be_child return if id.blank? available_assemblies = Decidim::Assemblies::ParentAssembliesForSelect.for(current_organization, Assembly.find(id)) errors.add(:parent, :invalid) unless available_assemblies.include? parent end |
#map_model(model) ⇒ Object
94 95 96 |
# File 'app/forms/decidim/assemblies/admin/assembly_form.rb', line 94 def map_model(model) self.scope_id = model.decidim_scope_id end |
#parent ⇒ Object
120 121 122 |
# File 'app/forms/decidim/assemblies/admin/assembly_form.rb', line 120 def parent @parent ||= organization_assemblies.find_by(id: parent_id) end |
#processes_for_select ⇒ Object
124 125 126 127 128 |
# File 'app/forms/decidim/assemblies/admin/assembly_form.rb', line 124 def processes_for_select @processes_for_select ||= organization_participatory_processes &.map { |pp| [translated_attribute(pp.title), pp.id] } &.sort_by { |arr| arr[0] } end |
#scope ⇒ Object
98 99 100 |
# File 'app/forms/decidim/assemblies/admin/assembly_form.rb', line 98 def scope @scope ||= current_organization.scopes.find_by(id: scope_id) end |