2010-06-01 00:06:46 +00:00
|
|
|
class ContentInstance
|
|
|
|
|
2010-05-24 00:18:23 +00:00
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
2010-06-10 13:30:22 +00:00
|
|
|
## extensions ##
|
|
|
|
include CustomFields::ProxyClassEnabler
|
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
## fields (dynamic fields) ##
|
2010-05-26 00:41:10 +00:00
|
|
|
field :_position_in_list, :type => Integer, :default => 0
|
2010-05-25 00:32:12 +00:00
|
|
|
|
|
|
|
## validations ##
|
|
|
|
validate :require_highlighted_field
|
|
|
|
|
|
|
|
## associations ##
|
|
|
|
embedded_in :content_type, :inverse_of => :contents
|
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
## callbacks ##
|
|
|
|
before_create :add_to_list_bottom
|
|
|
|
|
2010-05-26 00:41:10 +00:00
|
|
|
## named scopes ##
|
|
|
|
named_scope :latest_updated, :order_by => [[:updated_at, :desc]], :limit => Locomotive.config.lastest_items_nb
|
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
## methods ##
|
|
|
|
|
2010-06-10 13:30:22 +00:00
|
|
|
def to_liquid
|
|
|
|
Locomotive::Liquid::Drops::Content.new(self)
|
|
|
|
end
|
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
protected
|
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
def add_to_list_bottom
|
|
|
|
Rails.logger.debug "add_to_list_bottom"
|
|
|
|
self._position_in_list = self.content_type.contents.size
|
|
|
|
end
|
|
|
|
|
2010-05-25 00:32:12 +00:00
|
|
|
def require_highlighted_field
|
|
|
|
_alias = self.content_type.highlighted_field._alias.to_sym
|
|
|
|
if self.send(_alias).blank?
|
|
|
|
self.errors.add(_alias, :blank)
|
|
|
|
end
|
|
|
|
end
|
2010-05-24 00:18:23 +00:00
|
|
|
|
|
|
|
end
|