From 718685b4b5574fce7b99a48832e71f21b37527a6 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Tue, 7 Apr 2009 17:14:51 +0200 Subject: [PATCH] fix #867. deferring in tag view is now working --- app/controllers/todos_controller.rb | 11 ++++++++++- app/helpers/todos_helper.rb | 7 +++++-- app/views/todos/update.js.rjs | 23 ++++++++++++++++++++--- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 36155659..ad7a3dd4 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -264,6 +264,8 @@ class TodosController < ApplicationController @remaining_undone_in_project = current_user.projects.find(@original_item_project_id).not_done_todo_count end determine_down_count + determine_deferred_tag_count(params['_tag_name']) if @source_view == 'tag' + respond_to do |format| format.js format.xml { render :xml => @todo.to_xml( :except => :user_id ) } @@ -436,7 +438,7 @@ class TodosController < ApplicationController @original_item_context_id = @todo.context_id @todo.show_from = (@todo.show_from || @todo.user.date) + numdays.days @saved = @todo.save - + determine_down_count determine_remaining_in_context_count(@todo.context_id) respond_to do |format| @@ -694,6 +696,13 @@ class TodosController < ApplicationController end end + def determine_deferred_tag_count(tag) + tag_collection = Tag.find_by_name(tag).todos + @deferred_tag_count = tag_collection.count(:all, + :conditions => ['todos.user_id = ? and state = ?', current_user.id, 'deferred'], + :order => 'show_from ASC, todos.created_at DESC') + end + def render_todos_html lambda do @page_title = "TRACKS::List tasks" diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index c534eb68..36eb2ec7 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -239,7 +239,7 @@ module TodosHelper end def empty_container_msg_div_id - return "tickler-empty-nd" if source_view_is(:project) && @todo.deferred? + return "tickler-empty-nd" if source_view_is_one_of(:project, :tag) && @todo.deferred? return "p#{@todo.project_id}empty-nd" if source_view_is :project return "c#{@todo.context_id}empty-nd" end @@ -276,7 +276,10 @@ module TodosHelper end def defer_link(days) - link_to_remote image_tag("defer_#{days}.png", :alt => "Defer #{pluralize(days, 'day')}"), :url => {:controller => 'todos', :action => 'defer', :id => @todo.id, :days => days, :_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")} + url = {:controller => 'todos', :action => 'defer', :id => @todo.id, :days => days, + :_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")} + url[:_tag_name] = @tag_name if @source_view == 'tag' + link_to_remote image_tag("defer_#{days}.png", :alt => "Defer #{pluralize(days, 'day')}"), :url => url end end diff --git a/app/views/todos/update.js.rjs b/app/views/todos/update.js.rjs index 9c7d7275..4754a1ab 100644 --- a/app/views/todos/update.js.rjs +++ b/app/views/todos/update.js.rjs @@ -33,7 +33,7 @@ if @saved end end end - + if source_view_is_one_of(:todo, :tag) && @todo.active? page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@todo.context_id}" page.call "todoItems.expandNextActionListingByContext", "c#{@todo.context_id}items", true @@ -41,6 +41,12 @@ if @saved # show all todos in context page.insert_html :bottom, "c#{@todo.context_id}items", :partial => 'todos/todo', :locals => { :todo => @todo, :parent_container_type => parent_container_type } end + + if source_view_is(:tag) && @todo.deferred? + # show todo in deferred container + page.insert_html :bottom, "tickleritems", :partial => 'todos/todo', :locals => { :todo => @todo, :parent_container_type => parent_container_type } + page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil? + end # update badge count page.replace_html("badge_count", @remaining_in_context) if source_view_is :context @@ -55,9 +61,20 @@ if @saved end end else - page.replace dom_id(@todo), :partial => 'todos/todo', :locals => { :todo => @todo, :parent_container_type => parent_container_type } + if @original_item_was_deferred && source_view_is(:tag) + # we go from the deferred container to a context container in tag view + page[@todo].remove + page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@todo.context_id}" + page.call "todoItems.expandNextActionListingByContext", "c#{@todo.context_id}items", true + page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil? + # show all todos in context + page.insert_html :bottom, "c#{@todo.context_id}items", :partial => 'todos/todo', :locals => { :todo => @todo, :parent_container_type => parent_container_type } + page['tickler-empty-nd'].show if @deferred_tag_count == 0 + else + page.replace dom_id(@todo), :partial => 'todos/todo', :locals => { :todo => @todo, :parent_container_type => parent_container_type } + end page.visual_effect :highlight, dom_id(@todo), :duration => 3 - end + end elsif source_view_is :project if @project_changed page[@todo].remove