Class: Decidim::Budgets::Admin::ProjectImportProposalsForm

Inherits:
Form
  • Object
show all
Defined in:
app/forms/decidim/budgets/admin/project_import_proposals_form.rb

Overview

A form object to be used when admin users want to import a collection of proposals from another component into projects component.

Instance Method Summary collapse

Instance Method Details

#available_states(component_id = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'app/forms/decidim/budgets/admin/project_import_proposals_form.rb', line 36

def available_states(component_id = nil)
  scope = Decidim::Proposals::ProposalState
  scope = scope.where(component: Decidim::Component.find(component_id)) if component_id.present?

  states = scope.pluck(:token).uniq.map do |token|
    OpenStruct.new(token: token, title: token.humanize)
  end

  states + [OpenStruct.new(token: "not_answered", title: I18n.t("decidim.proposals.answers.not_answered"))]
end

#budgetObject



32
33
34
# File 'app/forms/decidim/budgets/admin/project_import_proposals_form.rb', line 32

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

#origin_componentObject



18
19
20
# File 'app/forms/decidim/budgets/admin/project_import_proposals_form.rb', line 18

def origin_component
  @origin_component ||= origin_components.find_by(id: origin_component_id)
end

#origin_componentsObject



22
23
24
# File 'app/forms/decidim/budgets/admin/project_import_proposals_form.rb', line 22

def origin_components
  @origin_components ||= current_participatory_space.components.where(manifest_name: :proposals)
end

#origin_components_collectionObject



26
27
28
29
30
# File 'app/forms/decidim/budgets/admin/project_import_proposals_form.rb', line 26

def origin_components_collection
  origin_components.map do |component|
    [component.name[I18n.locale.to_s], component.id]
  end
end