From 95e0fd35907a869399e126745b229464b634624f Mon Sep 17 00:00:00 2001 From: bsag Date: Tue, 11 Apr 2006 12:40:10 +0000 Subject: [PATCH] Added Luke's patch for moving an action between contexts when you edit the context. If you change the context of a next action by editing it, the action moves immediately between contexts when you hit update (by the magic of Ajax), rather than requiring you to refresh as happened previously. Fixes #245. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@219 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/todo_controller.rb | 19 ++++++++----------- tracks/app/helpers/todo_helper.rb | 4 +--- tracks/app/views/todo/update_action.rjs | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 tracks/app/views/todo/update_action.rjs diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 2cf870cc..783ab045 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -23,6 +23,7 @@ class TodoController < ApplicationController self.init @on_page = "home" @page_title = "TRACKS::List tasks" + @done = @done[0..(@user.preferences["no_completed"].to_i-1)] @contexts_to_show = @contexts.clone @@ -116,21 +117,17 @@ class TodoController < ApplicationController if @params["on_project_page"] == true @on_page = "project" end - item = check_user_return_item - item.attributes = @params["item"] + @item = check_user_return_item + @original_item_context_id = @item.context_id + @item.attributes = @params["item"] - if item.due? - item.due = Date.strptime(@params["item"]["due"], @user.preferences["date_format"]) + if @item.due? + @item.due = Date.strptime(@params["item"]["due"], @user.preferences["date_format"]) else - item.due = "" + @item.due = "" end - if item.save - render :partial => 'item', :object => item - else - flash["warning"] = "Couldn't update the action" - render_text "" - end + @saved = @item.save end # Delete a next action diff --git a/tracks/app/helpers/todo_helper.rb b/tracks/app/helpers/todo_helper.rb index e4e63a03..56d7a3c2 100644 --- a/tracks/app/helpers/todo_helper.rb +++ b/tracks/app/helpers/todo_helper.rb @@ -9,9 +9,7 @@ module TodoHelper def form_remote_tag_edit_todo( item ) form_remote_tag( :url => { :controller => 'todo', :action => 'update_action', :id => item.id }, - :html => { :id => "form-action-#{item.id}", :class => "inline-form" }, - :update => "item-#{item.id}-container", - :complete => visual_effect(:appear, "item-#{item.id}-container") + :html => { :id => "form-action-#{item.id}", :class => "inline-form" } ) end diff --git a/tracks/app/views/todo/update_action.rjs b/tracks/app/views/todo/update_action.rjs new file mode 100644 index 00000000..c16c3ae2 --- /dev/null +++ b/tracks/app/views/todo/update_action.rjs @@ -0,0 +1,14 @@ +if @saved + if @item.context_id == @original_item_context_id + page.replace_html "item-#{@item.id}-container", :partial => 'todo/item' + page.visual_effect :highlight, "item-#{@item.id}-container", :duration => 3 + else + page["item-#{@item.id}-container"].remove + page.insert_html :bottom, "c#{@item.context_id}items", :partial => 'todo/item' + page.visual_effect :highlight, "item-#{@item.id}-container", :duration => 3 + end +else + page.hide "info" + 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 +end \ No newline at end of file