Class: Decidim::Debates::Admin::DebateForm

Inherits:
Form show all
Includes:
TranslatableAttributes
Defined in:
decidim-debates/app/forms/decidim/debates/admin/debate_form.rb

Overview

This class holds a Form to create/update debates 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

#categoryObject


39
40
41
42
43
# File 'decidim-debates/app/forms/decidim/debates/admin/debate_form.rb', line 39

def category
  return unless current_component

  @category ||= current_component.categories.find_by(id: decidim_category_id)
end

#map_model(model) ⇒ Object


31
32
33
34
35
36
37
# File 'decidim-debates/app/forms/decidim/debates/admin/debate_form.rb', line 31

def map_model(model)
  self.decidim_category_id = model.categorization.decidim_category_id if model.categorization
  presenter = DebatePresenter.new(model)

  self.title = presenter.title(all_locales: title.is_a?(Hash))
  self.description = presenter.description(all_locales: description.is_a?(Hash))
end

#scopeObject

Finds the Scope from the given decidim_scope_id, uses the compoenent scope if missing.

Returns a Decidim::Scope


48
49
50
# File 'decidim-debates/app/forms/decidim/debates/admin/debate_form.rb', line 48

def scope
  @scope ||= @attributes["scope_id"].value ? current_component.scopes.find_by(id: @attributes["scope_id"].value) : current_component.scope
end

#scope_idObject

Scope identifier

Returns the scope identifier related to the meeting


55
56
57
# File 'decidim-debates/app/forms/decidim/debates/admin/debate_form.rb', line 55

def scope_id
  super || scope&.id
end