2014-05-01 08:44:01 +00:00
|
|
|
module OrbitModel
|
|
|
|
module Status
|
|
|
|
|
|
|
|
def self.included(base)
|
2014-05-05 11:40:31 +00:00
|
|
|
base.extend ClassMethods
|
2014-05-01 08:44:01 +00:00
|
|
|
base.field :is_top, :type => Boolean, :default => false
|
|
|
|
base.field :is_hot, :type => Boolean, :default => false
|
|
|
|
base.field :is_hidden, :type => Boolean, :default => false
|
|
|
|
|
|
|
|
def is_top?
|
|
|
|
self.is_top
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_hot?
|
|
|
|
self.is_hot
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_hidden?
|
|
|
|
self.is_hidden
|
|
|
|
end
|
|
|
|
|
|
|
|
def status_for_table
|
|
|
|
status = ""
|
|
|
|
status << "<span class='label label-success'>#{I18n.t(:top)}</span> " if self.is_top
|
|
|
|
status << "<span class='label label-important'>#{I18n.t(:hot)}</span> " if self.is_hot
|
|
|
|
status << "<span class='label'>#{I18n.t(:hidden)}</span>"if self.is_hidden
|
|
|
|
status.html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-05 11:40:31 +00:00
|
|
|
module ClassMethods
|
|
|
|
def with_status(status)
|
|
|
|
status = [status].flatten
|
|
|
|
self.any_of(status.map{|s| {s.to_sym=>true}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-01 08:44:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|