diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb index 2f9fd629..aa0c79f4 100644 --- a/tracks/app/models/todo.rb +++ b/tracks/app/models/todo.rb @@ -7,7 +7,7 @@ class Todo < ActiveRecord::Base acts_as_state_machine :initial => :active, :column => 'state' - state :active, :enter => Proc.new { |t| t.show_from = nil } + state :active, :enter => Proc.new { |t| t[:show_from] = nil } state :project_hidden state :completed, :enter => Proc.new { |t| t.completed_at = Time.now() }, :exit => Proc.new { |t| t.completed_at = nil } state :deferred @@ -29,7 +29,7 @@ class Todo < ActiveRecord::Base end event :unhide do - transitions :to => :deferred, :from => [:project_hidden], :guard => Proc.new{|t| t.show_from != nil} + transitions :to => :deferred, :from => [:project_hidden], :guard => Proc.new{|t| !t.show_from.blank? } transitions :to => :active, :from => [:project_hidden] end @@ -58,6 +58,12 @@ class Todo < ActiveRecord::Base end end + def show_from=(date) + activate! if deferred? && date.blank? + defer! if active? && !date.blank? && date > Date.today() + self[:show_from] = date + end + alias_method :original_project, :project def project diff --git a/tracks/app/views/todo/_edit_form.rhtml b/tracks/app/views/todo/_edit_form.rhtml index 6d2eb967..e0646201 100644 --- a/tracks/app/views/todo/_edit_form.rhtml +++ b/tracks/app/views/todo/_edit_form.rhtml @@ -38,12 +38,10 @@