2007-03-30 04:36:52 +00:00
|
|
|
class Context < ActiveRecord::Base
|
|
|
|
|
|
2007-08-28 12:38:16 +00:00
|
|
|
has_many :todos, :dependent => :delete_all, :include => :project, :order => "todos.completed_at DESC"
|
2010-04-04 18:20:07 +02:00
|
|
|
has_many :recurring_todos, :dependent => :delete_all
|
2007-03-30 04:36:52 +00:00
|
|
|
belongs_to :user
|
2008-11-29 15:35:17 +01:00
|
|
|
|
|
|
|
|
named_scope :active, :conditions => { :hide => false }
|
|
|
|
|
named_scope :hidden, :conditions => { :hide => true }
|
|
|
|
|
|
2007-03-30 04:36:52 +00:00
|
|
|
acts_as_list :scope => :user
|
|
|
|
|
extend NamePartFinder
|
|
|
|
|
include Tracks::TodoList
|
|
|
|
|
|
|
|
|
|
attr_protected :user
|
|
|
|
|
|
|
|
|
|
validates_presence_of :name, :message => "context must have a name"
|
|
|
|
|
validates_length_of :name, :maximum => 255, :message => "context name must be less than 256 characters"
|
|
|
|
|
validates_uniqueness_of :name, :message => "already exists", :scope => "user_id"
|
|
|
|
|
validates_does_not_contain :name, :string => ',', :message => "cannot contain the comma (',') character"
|
|
|
|
|
|
|
|
|
|
def self.feed_options(user)
|
2011-05-01 12:48:32 +02:00
|
|
|
# TODO: move to view or helper
|
2007-03-30 04:36:52 +00:00
|
|
|
{
|
|
|
|
|
:title => 'Tracks Contexts',
|
|
|
|
|
:description => "Lists all the contexts for #{user.display_name}"
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.null_object
|
|
|
|
|
NullContext.new
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def hidden?
|
|
|
|
|
self.hide == true || self.hide == 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def title
|
|
|
|
|
name
|
|
|
|
|
end
|
2011-05-01 12:48:32 +02:00
|
|
|
|
2007-11-04 23:06:46 +00:00
|
|
|
def new_record_before_save?
|
|
|
|
|
@new_record_before_save
|
2007-03-30 04:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class NullContext
|
|
|
|
|
|
|
|
|
|
def nil?
|
|
|
|
|
true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def id
|
|
|
|
|
nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def name
|
|
|
|
|
''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|