Sha256: eeca14e7a454e2ff0835897b1a06002933403be2b013bbd299c43cd1ea2e879a

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Admin
      # This class holds a Form to close a meeting from Decidim's admin panel.
      class CloseMeetingForm < Decidim::Form
        include TranslatableAttributes

        translatable_attribute :closing_report, String
        attribute :attendees_count, Integer, default: 0
        attribute :contributions_count, Integer, default: 0
        attribute :attending_organizations, String
        attribute :proposal_ids, Array[Integer]
        attribute :proposals
        attribute :closed_at, Decidim::Attributes::TimeWithZone, default: ->(_form, _attribute) { Time.current }

        validates :closing_report, translatable_presence: true
        validates :attendees_count, presence: true, numericality: { greater_than_or_equal_to: 0 }
        validates :contributions_count, numericality: true, allow_blank: true
        validates :attending_organizations, presence: true

        # Private: Gets the proposals from the meeting and injects them to the form.
        #
        # Returns nothing.
        def map_model(model)
          self.proposal_ids = model.linked_resources(:proposals, "proposals_from_meeting").pluck(:id)
        end

        def proposals
          @proposals ||= Decidim.find_resource_manifest(:proposals)
                                .try(:resource_scope, current_component)
                                &.where(id: proposal_ids)
                                &.order(title: :asc)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-meetings-0.23.6 app/forms/decidim/meetings/admin/close_meeting_form.rb
decidim-meetings-0.23.5 app/forms/decidim/meetings/admin/close_meeting_form.rb
decidim-meetings-0.23.4 app/forms/decidim/meetings/admin/close_meeting_form.rb
decidim-meetings-0.23.3 app/forms/decidim/meetings/admin/close_meeting_form.rb
decidim-meetings-0.23.2 app/forms/decidim/meetings/admin/close_meeting_form.rb
decidim-meetings-0.23.1 app/forms/decidim/meetings/admin/close_meeting_form.rb
decidim-meetings-0.23.1.rc1 app/forms/decidim/meetings/admin/close_meeting_form.rb
decidim-meetings-0.23.0 app/forms/decidim/meetings/admin/close_meeting_form.rb
decidim-meetings-0.22.0 app/forms/decidim/meetings/admin/close_meeting_form.rb