Sha256: 94f04339f6a273e441bee80b69d6d9914593404f99e178ef707967d0c0d19cd3
Contents?: true
Size: 1.71 KB
Versions: 25
Compression:
Stored size: 1.71 KB
Contents
# frozen_string_literal: true module Decidim module Proposals module Admin # A form object to be used when admin users want to import a collection of proposals # from another component. class ProposalsImportForm < Decidim::Form mimic :proposals_import attribute :origin_component_id, Integer attribute :import_proposals, Boolean attribute :keep_authors, Boolean attribute :states, Array validates :origin_component_id, :origin_component, :states, :current_component, presence: true validates :import_proposals, allow_nil: false, acceptance: true validate :valid_states VALID_STATES = %w(accepted not_answered evaluating rejected withdrawn).freeze def states_collection VALID_STATES.map do |state| OpenStruct.new( name: I18n.t(state, scope: "decidim.proposals.answers"), value: state ) end end def states super.reject(&:blank?) end def origin_component @origin_component ||= origin_components.find_by(id: origin_component_id) end def origin_components @origin_components ||= current_participatory_space.components.where.not(id: current_component.id).where(manifest_name: :proposals) end def origin_components_collection origin_components.map do |component| [component.name[I18n.locale.to_s], component.id] end end private def valid_states return if states.all? do |state| VALID_STATES.include?(state) end errors.add(:states, :invalid) end end end end end
Version data entries
25 entries across 25 versions & 1 rubygems