Class: Decidim::Plans::PlanForm
- Inherits:
-
Form
- Object
- Form
- Decidim::Plans::PlanForm
- Includes:
- OptionallyTranslatableAttributes
- Defined in:
- app/forms/decidim/plans/plan_form.rb
Overview
A form object to be used when public users want to create a Plan.
Instance Method Summary collapse
-
#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.
- #user_group ⇒ Object
Methods included from OptionallyTranslatableAttributes
Instance Method Details
#category ⇒ Object
Finds the Category from the category_id.
Returns a Decidim::Category
33 34 35 |
# File 'app/forms/decidim/plans/plan_form.rb', line 33 def category @category ||= categories.find_by(id: category_id) end |
#map_model(model) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/forms/decidim/plans/plan_form.rb', line 51 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.user_group_id = model.user_groups.first&.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
70 71 72 73 74 75 76 |
# File 'app/forms/decidim/plans/plan_form.rb', line 70 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
40 41 42 |
# File 'app/forms/decidim/plans/plan_form.rb', line 40 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
47 48 49 |
# File 'app/forms/decidim/plans/plan_form.rb', line 47 def scope_id @scope_id || scope&.id end |
#user_group ⇒ Object
66 67 68 |
# File 'app/forms/decidim/plans/plan_form.rb', line 66 def user_group @user_group ||= Decidim::UserGroup.find user_group_id if user_group_id.present? end |