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
|
|
|
|
|
2014-05-14 11:47:25 +00:00
|
|
|
def statuses
|
|
|
|
statuses = []
|
|
|
|
statuses << I18n.t(:top) if is_top?
|
|
|
|
statuses << I18n.t(:hot) if is_hot?
|
|
|
|
statuses << I18n.t(:hidden) if is_hidden?
|
|
|
|
statuses
|
|
|
|
end
|
|
|
|
|
2014-06-18 09:57:36 +00:00
|
|
|
def statuses_with_classname
|
|
|
|
statuses = []
|
|
|
|
statuses << {"name" => I18n.t(:top), "classname" => "top"} if is_top?
|
|
|
|
statuses << {"name" => I18n.t(:hot), "classname" => "hot"} if is_hot?
|
|
|
|
statuses << {"name" => I18n.t(:hidden), "classname" => "hidden"} if is_hidden?
|
|
|
|
statuses
|
|
|
|
end
|
|
|
|
|
2014-05-01 08:44:01 +00:00
|
|
|
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
|