Sha256: 4d19bbd96cf471150d6ace362ccf8182c97e2a8638c3888f10620a46534c6500

Contents?: true

Size: 843 Bytes

Versions: 22

Compression:

Stored size: 843 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
      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_process, to: :context, prefix: false

      def parent_categories
        @parent_categories ||= current_process.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

22 entries across 22 versions & 2 rubygems

Version Path
decidim-admin-0.5.1 app/forms/decidim/admin/category_form.rb
decidim-0.5.1 decidim-admin/app/forms/decidim/admin/category_form.rb
decidim-admin-0.5.0 app/forms/decidim/admin/category_form.rb
decidim-0.5.0 decidim-admin/app/forms/decidim/admin/category_form.rb
decidim-admin-0.4.4 app/forms/decidim/admin/category_form.rb
decidim-0.4.4 decidim-admin/app/forms/decidim/admin/category_form.rb
decidim-admin-0.4.3 app/forms/decidim/admin/category_form.rb
decidim-admin-0.4.2 app/forms/decidim/admin/category_form.rb
decidim-admin-0.4.1 app/forms/decidim/admin/category_form.rb
decidim-0.4.3 decidim-admin/app/forms/decidim/admin/category_form.rb
decidim-0.4.2 decidim-admin/app/forms/decidim/admin/category_form.rb
decidim-0.4.1 decidim-admin/app/forms/decidim/admin/category_form.rb
decidim-admin-0.4.0 app/forms/decidim/admin/category_form.rb
decidim-0.4.0 decidim-admin/app/forms/decidim/admin/category_form.rb
decidim-admin-0.3.2 app/forms/decidim/admin/category_form.rb
decidim-0.3.2 decidim-admin/app/forms/decidim/admin/category_form.rb
decidim-admin-0.3.1 app/forms/decidim/admin/category_form.rb
decidim-0.3.1 decidim-admin/app/forms/decidim/admin/category_form.rb
decidim-admin-0.3.0 app/forms/decidim/admin/category_form.rb
decidim-0.3.0 decidim-admin/app/forms/decidim/admin/category_form.rb