Sha256: 9a023d5d0cc49b5e2f303e0d2c47794e0c400d77ebd3e71c09c206c3f2b9e483

Contents?: true

Size: 1.12 KB

Versions: 21

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

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

        mimic :meeting

        attribute :registrations_enabled, Boolean
        attribute :available_slots, Integer
        translatable_attribute :registration_terms, String

        validates :registration_terms, translatable_presence: true, if: ->(form) { form.registrations_enabled? }
        validates :available_slots, numericality: { greater_than_or_equal_to: 0 }, if: ->(form) { form.registrations_enabled? }
        validate :available_slots_greater_than_or_equal_to_registrations_count, if: ->(form) { form.registrations_enabled? && form.available_slots.positive? }

        private

        def available_slots_greater_than_or_equal_to_registrations_count
          errors.add(:available_slots, :invalid) if available_slots < meeting.registrations.count
        end

        def meeting
          @meeting ||= context[:meeting]
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
decidim-meetings-0.7.2 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.7.1 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.7.0 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.6.8 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-0.6.8 decidim-meetings/app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.6.7 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-0.6.7 decidim-meetings/app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.6.6 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-0.6.6 decidim-meetings/app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.6.5 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-0.6.5 decidim-meetings/app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.6.4 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-0.6.4 decidim-meetings/app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.6.3 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-0.6.3 decidim-meetings/app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.6.2 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-0.6.2 decidim-meetings/app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.6.1 app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-0.6.1 decidim-meetings/app/forms/decidim/meetings/admin/meeting_registrations_form.rb
decidim-meetings-0.6.0 app/forms/decidim/meetings/admin/meeting_registrations_form.rb