Sha256: 2b7bae98bddac6bc78e3b099c18f8e3600f07542f97522fa8923401fb6094cab

Contents?: true

Size: 1.33 KB

Versions: 27

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      # A form object to be used when admin users want to answer a proposal.
      class ProposalAnswerForm < Decidim::Form
        include TranslatableAttributes
        mimic :proposal_answer

        translatable_attribute :answer, String
        translatable_attribute :cost_report, String
        translatable_attribute :execution_period, String
        attribute :cost, Float
        attribute :internal_state, String

        validates :internal_state, presence: true, inclusion: { in: %w(not_answered accepted rejected evaluating) }
        validates :answer, translatable_presence: true, if: ->(form) { form.state == "rejected" }

        with_options if: :costs_required? do
          validates :cost, numericality: true, presence: true
          validates :cost_report, translatable_presence: true
          validates :execution_period, translatable_presence: true
        end

        alias state internal_state

        def costs_required?
          costs_enabled? && state == "accepted"
        end

        def publish_answer?
          current_component.current_settings.publish_answers_immediately?
        end

        private

        def costs_enabled?
          current_component.current_settings.answers_with_costs?
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
decidim-proposals-0.28.4 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.27.9 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.28.3 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.27.8 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.28.2 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.27.7 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.28.1 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.27.6 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.26.10 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.26.9 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.28.0 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.27.5 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.28.0.rc5 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.28.0.rc4 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.26.8 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.27.4 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.27.3 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.26.7 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.26.5 app/forms/decidim/proposals/admin/proposal_answer_form.rb
decidim-proposals-0.27.2 app/forms/decidim/proposals/admin/proposal_answer_form.rb