diff --git a/tracks/app/controllers/todos_controller.rb b/tracks/app/controllers/todos_controller.rb index 44715871..9915c5e3 100644 --- a/tracks/app/controllers/todos_controller.rb +++ b/tracks/app/controllers/todos_controller.rb @@ -120,7 +120,7 @@ class TodosController < ApplicationController respond_to do |format| format.js do if @saved - @remaining_undone_in_context = current_user.contexts.find(@todo.context_id).not_done_todo_count + determine_remaining_in_context_count(@todo.context_id) determine_down_count determine_completed_count end @@ -192,7 +192,7 @@ class TodosController < ApplicationController @saved = @todo.update_attributes params["todo"] @context_changed = @original_item_context_id != @todo.context_id @todo_was_activated_from_deferred_state = @original_item_was_deferred && @todo.active? - if @context_changed then @remaining_undone_in_context = current_user.contexts.find(@original_item_context_id).not_done_todo_count; end + determine_remaining_in_context_count(@original_item_context_id) if @context_changed @project_changed = @original_item_project_id != @todo.project_id if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = current_user.projects.find(@original_item_project_id).not_done_todo_count; end determine_down_count @@ -231,7 +231,7 @@ class TodosController < ApplicationController determine_down_count source_view do |from| from.todo do - @remaining_undone_in_context = current_user.contexts.find(@context_id).not_done_todo_count + determine_remaining_in_context_count(@context_id) end end end @@ -459,6 +459,14 @@ class TodosController < ApplicationController end end + def determine_remaining_in_context_count(context_id = @todo.context_id) + if source_view_is :deferred + @remaining_in_context = current_user.contexts.find(context_id).deferred_todo_count + else + @remaining_in_context = current_user.contexts.find(context_id).not_done_todo_count + end + end + def determine_completed_count source_view do |from| from.todo do diff --git a/tracks/app/helpers/todos_helper.rb b/tracks/app/helpers/todos_helper.rb index e56020aa..e3562bb6 100644 --- a/tracks/app/helpers/todos_helper.rb +++ b/tracks/app/helpers/todos_helper.rb @@ -181,7 +181,6 @@ module TodosHelper def empty_container_msg_div_id return "tickler-empty-nd" if source_view_is(:project) && @todo.deferred? return "p#{@todo.project_id}empty-nd" if source_view_is :project - return "tickler-empty-nd" if source_view_is :deferred return "c#{@todo.context_id}empty-nd" end diff --git a/tracks/app/views/shared/_add_new_item_form.rhtml b/tracks/app/views/shared/_add_new_item_form.rhtml index c8f71980..3e4fcb6c 100644 --- a/tracks/app/views/shared/_add_new_item_form.rhtml +++ b/tracks/app/views/shared/_add_new_item_form.rhtml @@ -69,7 +69,7 @@ function initializeNamesForAutoComplete(contextNamesForAutoComplete) { Event.observe($('todo_context_name'), "click", contextAutoCompleter.activate.bind(contextAutoCompleter)); } function updateContextNamesForAutoComplete(contextNamesForAutoComplete) { - if (contextAutoCompleter) // if we're already initialized + if (contextAutoCompleter) // i.e. if we're already initialized { contextAutoCompleter.options.array = contextNamesForAutoComplete } diff --git a/tracks/app/views/todos/destroy.rjs b/tracks/app/views/todos/destroy.rjs index fd0d1ad4..71d90d2b 100644 --- a/tracks/app/views/todos/destroy.rjs +++ b/tracks/app/views/todos/destroy.rjs @@ -1,7 +1,7 @@ if @saved page[@todo].remove page['badge_count'].replace_html @down_count - page.visual_effect :fade, item_container_id, :duration => 0.4 if source_view_is(:todo) && @remaining_undone_in_context == 0 + page.visual_effect :fade, item_container_id, :duration => 0.4 if source_view_is(:todo) && @remaining_in_context == 0 page[empty_container_msg_div_id].show if !empty_container_msg_div_id.nil? && @down_count == 0 else page.notify :error, "There was an error deleting the item #{@todo.description}", 8.0 diff --git a/tracks/app/views/todos/toggle_check.rjs b/tracks/app/views/todos/toggle_check.rjs index de6ab123..3b3632aa 100644 --- a/tracks/app/views/todos/toggle_check.rjs +++ b/tracks/app/views/todos/toggle_check.rjs @@ -9,7 +9,7 @@ if @saved page.show 'tickler-empty-nd' if source_view_is(:project) && @deferred_count == 0 page.hide 'empty-d' # If we've checked something as done, completed items can't be empty end - if @remaining_undone_in_context == 0 && source_view_is(:todo) + if @remaining_in_context == 0 && source_view_is(:todo) page.visual_effect :fade, item_container_id, :duration => 0.4 end else diff --git a/tracks/app/views/todos/update.rjs b/tracks/app/views/todos/update.rjs index 9f8e5460..444599dd 100644 --- a/tracks/app/views/todos/update.rjs +++ b/tracks/app/views/todos/update.rjs @@ -9,7 +9,7 @@ if @saved if source_view_is_one_of [:todo, :context] if @context_changed || @todo.deferred? page[@todo].remove - if (@remaining_undone_in_context == 0) + if (@remaining_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" } @@ -21,7 +21,7 @@ if @saved page[empty_container_msg_div_id].hide unless empty_container_msg_div_id.nil? page.insert_html :bottom, "c#{@todo.context_id}items", :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } end - page.replace_html("badge_count", @remaining_undone_in_context) if source_view_is :context + page.replace_html("badge_count", @remaining_in_context) if source_view_is :context page.replace_html("badge_count", @down_count) if source_view_is :todo page.delay(0.5) do page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items" @@ -56,14 +56,28 @@ if @saved page.visual_effect :highlight, dom_id(@todo), :duration => 3 end elsif source_view_is :deferred - if @todo.deferred? - page.replace dom_id(@todo), :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } - page.visual_effect :highlight, dom_id(@todo), :duration => 3 - else + if !@todo.deferred? page[@todo].remove page.show(empty_container_msg_div_id) if (@down_count == 0) page.replace_html "badge_count", @down_count - end + elsif @context_changed + page[@todo].remove + page.call "console.log", "'@remaining_in_context = #{@remaining_in_context}'" + page.visual_effect(:fade, "c#{@original_item_context_id}", :duration => 0.4) if (@remaining_in_context == 0) + 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? + page.insert_html :bottom, "c#{@todo.context_id}items", :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } + page.replace_html("badge_count", @down_count) + page.delay(0.5) do + page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items" + page.call "todoItems.ensureContainerHeight", "c#{@todo.context_id}items" + page.visual_effect :highlight, dom_id(@todo), :duration => 3 + end + else + page.replace dom_id(@todo), :partial => 'todos/todo', :locals => { :parent_container_type => parent_container_type } + page.visual_effect :highlight, dom_id(@todo), :duration => 3 + end else logger.error "unexpected source_view '#{params[:_source_view]}'" end diff --git a/tracks/lib/source_view.rb b/tracks/lib/source_view.rb index a6dbee09..12261796 100644 --- a/tracks/lib/source_view.rb +++ b/tracks/lib/source_view.rb @@ -25,6 +25,10 @@ module Tracks base.send(:helper, Tracks::SourceViewSwitching::Helper) base.send(:helper_method, :source_view) end + + def source_view_is( s ) + s == (params[:_source_view] || @source_view).to_sym + end def source_view responder = Tracks::SourceViewSwitching::Responder.new(params[:_source_view] || @source_view) diff --git a/tracks/test/selenium/tickler/change_deferred_todo_context.rsel b/tracks/test/selenium/tickler/change_deferred_todo_context.rsel new file mode 100644 index 00000000..31bfa5e4 --- /dev/null +++ b/tracks/test/selenium/tickler/change_deferred_todo_context.rsel @@ -0,0 +1,12 @@ +setup :fixtures => :all +login :as => 'admin' +open "/tickler" +click "edit_icon_todo_15" +wait_for_visible "context_name_todo_15" +type "context_name_todo_15", "lab" +click "submit_todo_15" +wait_for_element_not_present "css=#c6 #todo_15" +wait_for_visible "c5" +wait_for_visible "css=#c5 #todo_15" +assert_not_visible "c5empty-nd" +wait_for_not_visible "c6" diff --git a/tracks/test/selenium/tickler/create_deferred_todo_with_existing_context.rsel b/tracks/test/selenium/tickler/create_deferred_todo_with_existing_context.rsel new file mode 100644 index 00000000..f7578816 --- /dev/null +++ b/tracks/test/selenium/tickler/create_deferred_todo_with_existing_context.rsel @@ -0,0 +1,10 @@ +setup :fixtures => :all +login :as => 'admin' +open "/tickler" +store_eval "this.browserbot.getCurrentWindow().$$('.context').length", 'initial_context_count' +type "todo_description", "a new action" +type "todo_context_name", "errands" +type "todo_show_from", "1/1/2030" +click "css=#todo-form-new-action .submit_box button" +store_eval "${initial_context_count} + 1", 'expected_context_count' +wait_for_eval "this.browserbot.getCurrentWindow().$$('.context').length", "${expected_context_count}" diff --git a/tracks/test/selenium/tickler/create_deferred_todo_with_new_context.rsel b/tracks/test/selenium/tickler/create_deferred_todo_with_new_context.rsel new file mode 100644 index 00000000..2355c541 --- /dev/null +++ b/tracks/test/selenium/tickler/create_deferred_todo_with_new_context.rsel @@ -0,0 +1,10 @@ +setup :fixtures => :all +login :as => 'admin' +open "/tickler" +store_eval "this.browserbot.getCurrentWindow().$$('.context').length", 'initial_context_count' +type "todo_description", "a new action" +type "todo_context_name", "Brand new context" +type "todo_show_from", "1/1/2030" +click "css=#todo-form-new-action .submit_box button" +store_eval "${initial_context_count} + 1", 'expected_context_count' +wait_for_eval "this.browserbot.getCurrentWindow().$$('.context').length", "${expected_context_count}"