Sha256: 0311c7bdae1b7c3048110835ae83c556dea57a03f89184d16b0ea8a50ea2916b

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 KB

Contents

module Enjoy::Catalog
  module Models
    module Mongoid
      module ItemCategory
        extend ActiveSupport::Concern
        include Enjoy::MongoidPaperclip

        include Enjoy::HtmlField

        included do
          if defined?(RailsAdminComments)
            include RailsAdminComments::Commentable
          end

          field :name, type: String, localize: Enjoy.configuration.localize, default: ""

          enjoy_cms_mongoid_attached_file(:image,
                    styles: lambda { |attachment| attachment.instance.image_styles },
                    content_type: { content_type: ["image/jpg", "image/jpeg", "image/png"] }
          )

          acts_as_nested_set
          scope :sorted, -> { order_by([:lft, :asc]) }

          enjoy_cms_html_field :excerpt,   type: String, localize: Enjoy.configuration.localize, default: ""
          enjoy_cms_html_field :content,   type: String, localize: Enjoy.configuration.localize, default: ""

          embeds_many :item_category_images, cascade_callbacks: true, class_name: "Enjoy::Catalog::ItemCategoryImage"
          alias :images :item_category_images
          accepts_nested_attributes_for :item_category_images, allow_destroy: true
        end

        def items
          item_class.in(item_category_ids: self.id)
        end

        def all_items
          item_class.any_in(item_category_ids: self.self_and_descendants.map(&:id))
        end

        def image_styles
          Enjoy::Catalog.configuration.item_category_image_styles
        end

        def image_jcrop_options
          {}
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
enjoy_cms_catalog-0.3.7 lib/enjoy/catalog/models/mongoid/item_category.rb
enjoy_cms_catalog-0.3.6 lib/enjoy/catalog/models/mongoid/item_category.rb
enjoy_cms_catalog-0.3.5 lib/enjoy/catalog/models/mongoid/item_category.rb
enjoy_cms_catalog-0.3.4 lib/enjoy/catalog/models/mongoid/item_category.rb
enjoy_cms_catalog-0.3.3 lib/enjoy/catalog/models/mongoid/item_category.rb