Sha256: d4a210c61f903cdab6434c767b33d7a9ac617814655746c226c0d122797c454d
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
class Category < ActiveRecord::Base translates :name, :description, :url acts_as_tree :order => "position" has_and_belongs_to_many_attachments acts_as_list :scope => [:type] validates_each :parent_id do |record, attr, value| record.errors.add(attr, 'Can\'t be his self parent') if record.id == value end def level return self.ancestors.length end def kind read_attribute(:type) end def kind=(kind) write_attribute(:type, kind) end def total_elements_count ([elements.count('id')] + children.all(:select => 'id,type').map(&:total_elements_count)).sum end def category_picture unless self.attachments.empty? self.attachments.first.public_filename(:categories_icon) else 'folder' end end def to_jstree hash = {} hash[:attr] = { :id => "#{self.class.to_s.underscore}_#{id}", :type => 'folder' } hash[:data] = { :title => name, :icon => category_picture, :attr => { :title => total_elements_count } } unless children.empty? hash[:children] = children.all(:order => 'position ASC').collect(&:to_jstree) end hash end def descendants (children + children.map(&:descendants)).flatten end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
forgeos_core-1.9.4 | app/models/category.rb |
forgeos_core-1.9.3 | app/models/category.rb |