Class: Decidim::Assemblies::Admin::AssemblyForm

Inherits:
Form
  • Object
show all
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

Instance Method Details

#areaObject



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_typeObject



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_selectObject



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_selectObject



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_childObject



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

#parentObject



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_selectObject



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

#scopeObject



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