Sha256: d3e97ed07faa02552e0d319a5cabf5a154e39389ece1533f3e335c460a08ffff

Contents?: true

Size: 912 Bytes

Versions: 37

Compression:

Stored size: 912 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
      translatable_attribute :description, String
      attribute :parent_id, Integer

      mimic :category

      validates :name, :description, 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: id)
      end

      private

      def parent_categories_ids
        @parent_categories_ids ||= parent_categories.pluck(:id)
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.9 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.8 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.7 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.5 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.4 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.3 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.2 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.1 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.0 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.0.rc2 app/forms/decidim/admin/category_form.rb
decidim-admin-0.26.0.rc1 app/forms/decidim/admin/category_form.rb
decidim-admin-0.25.2 app/forms/decidim/admin/category_form.rb
decidim-admin-0.25.1 app/forms/decidim/admin/category_form.rb
decidim-admin-0.25.0 app/forms/decidim/admin/category_form.rb
decidim-admin-0.25.0.rc4 app/forms/decidim/admin/category_form.rb
decidim-admin-0.25.0.rc3 app/forms/decidim/admin/category_form.rb
decidim-admin-0.25.0.rc2 app/forms/decidim/admin/category_form.rb
decidim-admin-0.25.0.rc1 app/forms/decidim/admin/category_form.rb
decidim-admin-0.24.3 app/forms/decidim/admin/category_form.rb