Class: Decidim::Proposals::Admin::ProposalsImportForm

Inherits:
Form show all
Defined in:
decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb

Overview

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

Constant Summary collapse

VALID_STATES =
%w(accepted not_answered evaluating rejected withdrawn).freeze

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 inherited from AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, #map_model, 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

#origin_componentObject


41
42
43
# File 'decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb', line 41

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

#origin_componentsObject


45
46
47
# File 'decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb', line 45

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

#origin_components_collectionObject


49
50
51
52
53
# File 'decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb', line 49

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

#scopesObject


37
38
39
# File 'decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb', line 37

def scopes
  Decidim::Scope.where(organization: current_organization, id: scope_ids)
end

#statesObject


33
34
35
# File 'decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb', line 33

def states
  super.reject(&:blank?)
end

#states_collectionObject


24
25
26
27
28
29
30
31
# File 'decidim-proposals/app/forms/decidim/proposals/admin/proposals_import_form.rb', line 24

def states_collection
  VALID_STATES.map do |state|
    OpenStruct.new(
      name: I18n.t(state, scope: "decidim.proposals.answers"),
      value: state
    )
  end
end