tracks/tracks/app/models/todo.rb
bsag f7b77f6fd9 Did some refactoring of the todo/list page, which should make it a little quicker to load.
Changed the toggle_check method to use the built-in toggle() method, and moved setting of completion date to the before_save method of todo.rb


git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@10 a4c988fc-2ded-0310-b66e-134b36920a42
2005-01-23 11:50:07 +00:00

29 lines
933 B
Ruby

class Todo < ActiveRecord::Base
belongs_to :context
belongs_to :project
# Description field can't be empty, and must be < 100 bytes
# Notes must be < 60,000 bytes (65,000 actually, but I'm being cautious)
validates_presence_of :description, :message => "no description provided"
validates_length_of :description, :maximum => 100, :message => "description is too long"
validates_length_of :notes, :maximum => 60000, :message => "notes are too long"
#validates_format_of :due, :with => /^[\d]{2,2}\/[\d]{2,2}\/[\d]{4,4}$/, :message => "date format incorrect"
def before_save
# Add a creation date (Ruby object format) to item before it's saved
# if there is no existing creation date (this prevents creation date
# being reset to completion date when item is completed)
#
if self.created == nil
self.created = Time.now()
end
if self.done == 1
self.completed = Time.now()
end
end
end