Class: Decidim::Plans::Admin::PlanForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Plans::Admin::PlanForm
- Includes:
- ApplicationHelper, OptionallyTranslatableAttributes
- Defined in:
- app/forms/decidim/plans/admin/plan_form.rb
Overview
A form object to be used when admin users want to create a plan.
Instance Method Summary collapse
- #author ⇒ Object
-
#category ⇒ Object
Finds the Category from the category_id.
- #map_model(model) ⇒ Object
- #proposals ⇒ Object
-
#scope ⇒ Object
Finds the Scope from the given decidim_scope_id, uses participatory space scope if missing.
-
#scope_id ⇒ Object
Scope identifier.
Methods included from OptionallyTranslatableAttributes
Instance Method Details
#author ⇒ Object
67 68 69 |
# File 'app/forms/decidim/plans/admin/plan_form.rb', line 67 def current_organization end |
#category ⇒ Object
Finds the Category from the category_id.
Returns a Decidim::Category
49 50 51 |
# File 'app/forms/decidim/plans/admin/plan_form.rb', line 49 def category @category ||= categories.find_by(id: category_id) end |
#map_model(model) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/forms/decidim/plans/admin/plan_form.rb', line 30 def map_model(model) self.contents = model.sections.map do |section| ContentForm.from_model( Content .where(plan: model, section: section) .first_or_initialize(plan: model, section: section) ) end self.proposal_ids = model.linked_resources(:proposals, "included_proposals").pluck(:id) self.scope_id = model.decidim_scope_id if model.scope self.category_id = model.categorization.decidim_category_id if model.categorization end |
#proposals ⇒ Object
71 72 73 74 75 76 77 |
# File 'app/forms/decidim/plans/admin/plan_form.rb', line 71 def proposals @proposals ||= Decidim .find_resource_manifest(:proposals) .try(:resource_scope, current_component) &.where(id: proposal_ids) &.order(title: :asc) end |
#scope ⇒ Object
Finds the Scope from the given decidim_scope_id, uses participatory space scope if missing.
Returns a Decidim::Scope
56 57 58 |
# File 'app/forms/decidim/plans/admin/plan_form.rb', line 56 def scope @scope ||= @scope_id ? current_participatory_space.scopes.find_by(id: @scope_id) : current_participatory_space.scope end |
#scope_id ⇒ Object
Scope identifier
Returns the scope identifier related to the plan
63 64 65 |
# File 'app/forms/decidim/plans/admin/plan_form.rb', line 63 def scope_id @scope_id || scope&.id end |