Sha256: ebbb8599918a7e44e77aed0a588ba7ef9587a26fa7b61ddd5a798104f4731299

Contents?: true

Size: 814 Bytes

Versions: 13

Compression:

Stored size: 814 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A form object to create or update areas.
    class AreaForm < Form
      include TranslatableAttributes

      translatable_attribute :name, String
      attribute :organization, Decidim::Organization
      attribute :area_type_id, Integer

      mimic :area

      validates :name, translatable_presence: true
      validates :organization, presence: true

      validate :name_uniqueness

      def name_uniqueness
        return unless organization
        return unless organization.areas.where(name:, area_type:).where.not(id:).any?

        errors.add(:name, :taken)
      end

      alias organization current_organization

      def area_type
        Decidim::AreaType.find_by(id: area_type_id) if area_type_id
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/forms/decidim/admin/area_form.rb
decidim-admin-0.28.4 app/forms/decidim/admin/area_form.rb
decidim-admin-0.29.0 app/forms/decidim/admin/area_form.rb
decidim-admin-0.28.3 app/forms/decidim/admin/area_form.rb
decidim-admin-0.29.0.rc4 app/forms/decidim/admin/area_form.rb
decidim-admin-0.29.0.rc3 app/forms/decidim/admin/area_form.rb
decidim-admin-0.29.0.rc2 app/forms/decidim/admin/area_form.rb
decidim-admin-0.29.0.rc1 app/forms/decidim/admin/area_form.rb
decidim-admin-0.28.2 app/forms/decidim/admin/area_form.rb
decidim-admin-0.28.1 app/forms/decidim/admin/area_form.rb
decidim-admin-0.28.0 app/forms/decidim/admin/area_form.rb
decidim-admin-0.28.0.rc5 app/forms/decidim/admin/area_form.rb
decidim-admin-0.28.0.rc4 app/forms/decidim/admin/area_form.rb