Refine todo update.rjs to work better when called from a project page. Fixes #354.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@309 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2006-08-11 05:36:48 +00:00
parent 03f4de5703
commit 31214f1812
2 changed files with 27 additions and 11 deletions

View file

@ -1,19 +1,27 @@
page.hide "info"
if @saved
item_container_id = "item-#{@item.id}-container"
if @item.context_id == @original_item_context_id
page.replace item_container_id, :partial => 'todo/item', :locals => { :parent_container_type => "context" }
if source_view_is_one_of [:todo, :context]
if @item.context_id == @original_item_context_id
page.replace item_container_id, :partial => 'todo/item', :locals => { :parent_container_type => "context" }
page.visual_effect :highlight, item_container_id, :duration => 3
else
page[item_container_id].remove
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 => "context" }
page.delay(0.5) do
page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items"
page.call "todoItems.ensureContainerHeight", "c#{@item.context_id}items"
page.visual_effect :highlight, item_container_id, :duration => 3
end
end
elsif source_view_is :project
page.replace item_container_id, :partial => 'todo/item', :locals => { :parent_container_type => "project" }
page.visual_effect :highlight, item_container_id, :duration => 3
else
page[item_container_id].remove
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 => "context" }
page.delay(0.5) do
page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items"
page.call "todoItems.ensureContainerHeight", "c#{@item.context_id}items"
page.visual_effect :highlight, item_container_id, :duration => 3
end
logger.error "unexpected source_view '#{params[:_source_view]}'"
end
else
page.replace_html "info", content_tag("div", content_tag("div", "#{pluralize(@item.errors.count, "error")} prohibited this record from being saved", "id" => "warning", "class" => "warning") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @item.errors.each_full { |msg| content_tag("li", msg) }))
page.visual_effect :appear, 'info', :duration => 0.5

View file

@ -30,7 +30,7 @@ module Tracks
responder = Tracks::SourceViewSwitching::Responder.new(params[:_source_view])
block_given? ? yield(responder) : responder
end
end
module Helper
@ -38,6 +38,14 @@ module Tracks
def source_view_tag(name)
hidden_field_tag :_source_view, name.underscore.gsub(/\s+/,'_')
end
def source_view_is( s )
s == params[:_source_view].to_sym
end
def source_view_is_one_of( s=[] )
s.include?(params[:_source_view].to_sym)
end
end