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 @@
|
|
- <% if @item.current_state == :deferred -%>
|
|
- <% end -%>
<% if controller.controller_name == "project" || @item.deferred? -%>
<% end -%>
diff --git a/tracks/app/views/todo/create.rjs b/tracks/app/views/todo/create.rjs
index 5251d4f3..c7c7d65f 100644
--- a/tracks/app/views/todo/create.rjs
+++ b/tracks/app/views/todo/create.rjs
@@ -6,12 +6,14 @@ if @saved
page.notify :notice, status_message, 5.0
page['badge_count'].replace_html @down_count
page.send :record, "Form.reset('todo-form-new-action');Form.focusFirstElement('todo-form-new-action')"
- page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}" if source_view_is(:todo)
page << "contextAutoCompleter.options.array = #{context_names_for_autocomplete}" if @new_context_created
page << "projectAutoCompleter.options.array = #{project_names_for_autocomplete}" if @new_project_created
- page.insert_html :bottom, item_container_id, :partial => 'todo/item', :locals => { :parent_container_type => parent_container_type, :source_view => @source_view }
- page.visual_effect :highlight, "item-#{@item.id}-container", :duration => 3
- page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil?
+ unless (source_view_is(:deferred) && !@item.deferred?) || (source_view_is(:project) && @item.project.hidden? && @item.project_hidden?) || (!source_view_is(:deferred) && @item.active)
+ page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}" if source_view_is(:todo)
+ page.insert_html :bottom, item_container_id, :partial => 'todo/item', :locals => { :parent_container_type => parent_container_type, :source_view => @source_view }
+ page.visual_effect :highlight, "item-#{@item.id}-container", :duration => 3
+ page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil?
+ end
else
page.show 'status'
page.replace_html 'status', "#{error_messages_for('item')}"
diff --git a/tracks/app/views/todo/update.rjs b/tracks/app/views/todo/update.rjs
index ed94f054..dfac070a 100644
--- a/tracks/app/views/todo/update.rjs
+++ b/tracks/app/views/todo/update.rjs
@@ -8,15 +8,15 @@ if @saved
page << "contextAutoCompleter.options.array = #{context_names_for_autocomplete}; contextAutoCompleter.changed = true" if @new_context_created
page << "projectAutoCompleter.options.array = #{project_names_for_autocomplete}; projectAutoCompleter.changed = true" if @new_project_created
if source_view_is_one_of [:todo, :context]
- if @context_changed
+ if @context_changed || @item.deferred?
page[item_container_id].remove
- if (@remaining_undone_in_original_context == 0)
+ if (@remaining_undone_in_context == 0)
source_view do |from|
from.todo { page.visual_effect :fade, "c#{@original_item_context_id}", :duration => 0.4 }
from.context { page.show "c#{@original_item_context_id}empty-nd" }
end
end
- if source_view_is :todo
+ if source_view_is(:todo) && @item.active?
page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}"
page.call "todoItems.expandNextActionListingByContext", "c#{@item.context_id}items", true
page.insert_html :bottom, "c#{@item.context_id}items", :partial => 'todo/item', :locals => { :parent_container_type => parent_container_type }
@@ -24,7 +24,7 @@ if @saved
page.replace_html("badge_count", @remaining_undone_in_context) if source_view_is :context
page.delay(0.5) do
page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items"
- if source_view_is :todo
+ if source_view_is(:todo) && @item.active?
page.call "todoItems.ensureContainerHeight", "c#{@item.context_id}items"
page.visual_effect :highlight, item_container_id, :duration => 3
end
@@ -34,7 +34,7 @@ if @saved
page.visual_effect :highlight, item_container_id, :duration => 3
end
elsif source_view_is :project
- if @project_changed
+ if @project_changed || @item.deferred?
page[item_container_id].remove
page.show("p#{@original_item_project_id}empty-nd") if (@remaining_undone_in_project == 0)
page.replace_html "badge_count", @remaining_undone_in_project