Sha256: b9da804703d68a5d3c6f1f4a6f722b123a5a394be1253c0d5f682fb8875f02d1

Contents?: true

Size: 845 Bytes

Versions: 13

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A form object used to create categories from the admin dashboard.
    #
    class CategoryForm < Form
      include TranslatableAttributes

      translatable_attribute :name, String
      attribute :weight, Integer, default: 0
      attribute :parent_id, Integer

      mimic :category

      validates :name, translatable_presence: true
      validates :parent_id, inclusion: { in: :parent_categories_ids }, allow_blank: true

      delegate :current_participatory_space, to: :context, prefix: false

      def parent_categories
        @parent_categories ||= current_participatory_space.categories.first_class.where.not(id:)
      end

      private

      def parent_categories_ids
        @parent_categories_ids ||= parent_categories.pluck(: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/category_form.rb
decidim-admin-0.28.4 app/forms/decidim/admin/category_form.rb
decidim-admin-0.29.0 app/forms/decidim/admin/category_form.rb
decidim-admin-0.28.3 app/forms/decidim/admin/category_form.rb
decidim-admin-0.29.0.rc4 app/forms/decidim/admin/category_form.rb
decidim-admin-0.29.0.rc3 app/forms/decidim/admin/category_form.rb
decidim-admin-0.29.0.rc2 app/forms/decidim/admin/category_form.rb
decidim-admin-0.29.0.rc1 app/forms/decidim/admin/category_form.rb
decidim-admin-0.28.2 app/forms/decidim/admin/category_form.rb
decidim-admin-0.28.1 app/forms/decidim/admin/category_form.rb
decidim-admin-0.28.0 app/forms/decidim/admin/category_form.rb
decidim-admin-0.28.0.rc5 app/forms/decidim/admin/category_form.rb
decidim-admin-0.28.0.rc4 app/forms/decidim/admin/category_form.rb