Sha256: 352a7170ed1a9c362c7f7cfe1d5a8bf4e1b5b0c9610eeda05b1a8fd9b5a6f403

Contents?: true

Size: 1.18 KB

Versions: 20

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    module Admin
      # A form object to be used when admin users want to import a collection of proposals
      # from another component into projects component.
      class ProjectImportProposalsForm < Decidim::Form
        mimic :proposals_import

        attribute :origin_component_id, Integer
        attribute :default_budget, Integer
        attribute :import_all_accepted_proposals, Boolean

        validates :origin_component_id, :origin_component, :current_component, presence: true
        validates :import_all_accepted_proposals, allow_nil: false, acceptance: true
        validates :default_budget, presence: true, numericality: { greater_than: 0 }

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

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

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
decidim-budgets-0.22.0 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.21.0 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.20.1 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.20.0 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.19.1 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.18.1 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.19.0 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.17.2 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.18.0 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.17.1 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.16.1 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.17.0 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.16.0 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.15.2 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.15.1 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.15.0 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.14.4 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.14.3 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.14.2 app/forms/decidim/budgets/admin/project_import_proposals_form.rb
decidim-budgets-0.14.1 app/forms/decidim/budgets/admin/project_import_proposals_form.rb