From d57b31337692b477150bac2eab7ad73ecf495a70 Mon Sep 17 00:00:00 2001 From: lukemelia Date: Tue, 21 Nov 2006 06:34:32 +0000 Subject: [PATCH] Enable converting active actions to deferred actions and vice versa by editing the show_from date. Fixes #396. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@359 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/models/todo.rb | 10 ++++++++-- tracks/app/views/todo/_edit_form.rhtml | 2 -- tracks/app/views/todo/create.rjs | 10 ++++++---- tracks/app/views/todo/update.rjs | 10 +++++----- 4 files changed, 19 insertions(+), 13 deletions(-) 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 @@