Class: Decidim::Budgets::Admin::ProjectForm

Inherits:
Form
  • Object
show all
Includes:
AttachmentAttributes, ApplicationHelper, TranslatableAttributes, TranslationsHelper
Defined in:
app/forms/decidim/budgets/admin/project_form.rb

Overview

This class holds a Form to create/update projects from Decidim’s admin panel.

Instance Method Summary collapse

Instance Method Details

#budgetObject

Finds the Budget from the decidim_budgets_budget_id.

Returns a Decidim::Budgets:Budget



71
72
73
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 71

def budget
  @budget ||= context[:budget]
end

#categoryObject

Finds the Category from the decidim_category_id.

Returns a Decidim::Category



78
79
80
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 78

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

#decidim_scope_idObject

Scope identifier

Returns the scope identifier related to the project



92
93
94
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 92

def decidim_scope_id
  super || scope&.id
end

#geocoded?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 64

def geocoded?
  latitude.present? && longitude.present?
end

#geocoding_enabled?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 56

def geocoding_enabled?
  Decidim::Map.available?(:geocoding) && current_component.settings.geocoding_enabled?
end

#has_address?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 60

def has_address?
  geocoding_enabled? && address.present?
end

#map_model(model) ⇒ Object



41
42
43
44
45
46
47
48
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 41

def map_model(model)
  self.proposal_ids = model.linked_resources(:proposals, "included_proposals").pluck(:id)
  self.selected = model.selected?

  return unless model.categorization

  self.decidim_category_id = model.categorization.decidim_category_id
end

#proposalsObject



50
51
52
53
54
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 50

def proposals
  @proposals ||= Decidim.find_resource_manifest(:proposals).try(:resource_scope, current_component)
                 &.where(id: proposal_ids)
                 &.order(title: :asc)
end

#scopeObject

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

Returns a Decidim::Scope



85
86
87
# File 'app/forms/decidim/budgets/admin/project_form.rb', line 85

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