Sha256: f48c4c3cf22eba96f940d1c6e30b9e8344fa495a52a909c6a541dbd8c72b8173

Contents?: true

Size: 848 Bytes

Versions: 12

Compression:

Stored size: 848 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: id)
      end

      private

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-admin-0.27.9 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.8 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.7 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.6 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.5 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.4 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.3 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.2 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.1 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.0 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.0.rc2 app/forms/decidim/admin/category_form.rb
decidim-admin-0.27.0.rc1 app/forms/decidim/admin/category_form.rb