From 91f272a672760603163f8841750f3ca0f0a54be1 Mon Sep 17 00:00:00 2001 From: lukemelia Date: Tue, 18 Jul 2006 05:09:54 +0000 Subject: [PATCH] Make contexts appear and disappear on the home page as items are added/deleted/marked complete. Fixes #313. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@285 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/todo_controller.rb | 3 +++ tracks/app/views/context/_context.rhtml | 2 +- tracks/app/views/context/add_item.rjs | 2 +- tracks/app/views/context/destroy_action.rjs | 2 +- tracks/app/views/context/toggle_check.rjs | 6 +++--- tracks/app/views/project/_project.rhtml | 2 +- tracks/app/views/project/add_item.rjs | 2 +- tracks/app/views/project/destroy_action.rjs | 2 +- tracks/app/views/project/toggle_check.rjs | 6 +++--- tracks/app/views/todo/_tickler_items.rhtml | 2 +- tracks/app/views/todo/add_deferred_item.rjs | 1 + tracks/app/views/todo/add_item.rjs | 2 ++ tracks/app/views/todo/destroy_action.rjs | 3 +++ tracks/app/views/todo/toggle_check.rjs | 5 ++++- 14 files changed, 26 insertions(+), 14 deletions(-) diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 9201eb42..65c45267 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -94,6 +94,7 @@ class TodoController < ApplicationController @item.completed = Time.now() # For some reason, the before_save in todo.rb stopped working @saved = @item.save @on_page = "home" + @remaining_undone_in_context = Todo.count(:conditions => ['user_id = ? and context_id = ? and type = ? and done = ?', @user.id, @item.context_id, "Immediate", false]) if @saved @down_count = @todos.collect { |x| ( !x.done? and !x.context.hide? ) ? x:nil }.compact.size.to_s end @@ -181,9 +182,11 @@ class TodoController < ApplicationController def destroy_action self.init @item = check_user_return_item + context_id = @item.context_id @saved = @item.destroy @on_page = "home" + @remaining_undone_in_context = Todo.count(:conditions => ['user_id = ? and context_id = ? and type = ? and done = ?', @user.id, context_id, "Immediate", false]) if @saved self.init @down_count = @todos.reject { |x| x.done? or x.context.hide? }.size.to_s diff --git a/tracks/app/views/context/_context.rhtml b/tracks/app/views/context/_context.rhtml index a87a52ec..18bcc5f0 100644 --- a/tracks/app/views/context/_context.rhtml +++ b/tracks/app/views/context/_context.rhtml @@ -7,7 +7,7 @@ <%= link_to( sanitize("#{context.name}"), { :controller => "context", :action => "show", :name => urlize(context.name) }, { :title => "Go to the #{context.name} context page" } ) %>
-
+

Currently there are no uncompleted actions in this context

<%= render :partial => "todo/item", :collection => @not_done %> diff --git a/tracks/app/views/context/add_item.rjs b/tracks/app/views/context/add_item.rjs index cb648b08..baee2e33 100644 --- a/tracks/app/views/context/add_item.rjs +++ b/tracks/app/views/context/add_item.rjs @@ -7,7 +7,7 @@ if @saved page.send :record, "Form.reset('todo-form-new-action-lightbox');Form.focusFirstElement('todo-form-new-action-lightbox')" page.insert_html :bottom, "c#{@item.context_id}", :partial => 'todo/item' page.visual_effect :highlight, "item-#{@item.id}-container", :duration => 3 - page.hide "empty-nd" # If we are adding an new action, the uncompleted actions must be > 0 + page["c#{@item.context_id}empty-nd"].hide # If we are adding an new action, the uncompleted actions must be > 0 else page.hide "status" page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@item.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @item.errors.each_full { |msg| content_tag("li", msg) }), "id" => "ErrorExplanation", "class" => "ErrorExplanation") diff --git a/tracks/app/views/context/destroy_action.rjs b/tracks/app/views/context/destroy_action.rjs index 28335b4e..4940a403 100644 --- a/tracks/app/views/context/destroy_action.rjs +++ b/tracks/app/views/context/destroy_action.rjs @@ -2,7 +2,7 @@ if @saved page.visual_effect :fade, "item-#{@item.id}-container", :duration => 0.4 page.replace_html "badge_count", @down_count if @down_count == "0" - page.show 'empty-nd' + page["c#{@item.context_id}empty-nd").show end else page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@item.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @item.errors.each_full { |msg| content_tag("li", msg) }), "id" => "ErrorExplanation", "class" => "ErrorExplanation") diff --git a/tracks/app/views/context/toggle_check.rjs b/tracks/app/views/context/toggle_check.rjs index dc18d508..8c1e71b8 100644 --- a/tracks/app/views/context/toggle_check.rjs +++ b/tracks/app/views/context/toggle_check.rjs @@ -6,18 +6,18 @@ if @saved page.insert_html :top, "completed", :partial => 'todo/item' page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} if @down_count == '0' - page.show "empty-nd" + page["c#{@item.context_id}empty-nd"].show end page.hide "empty-d" # If we've checked something as done, completed items can't be empty end else - page.call "ensureVisibleWithEffectAppear", "c#{@item.context_id}" + page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}" page.insert_html :bottom, "c#{@item.context_id}", :partial => 'todo/item' page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} if @done_count == '0' page.show "empty-d" end - page.hide "empty-nd" # If we've checked something as undone, uncompleted items can't be empty + page["c#{@item.context_id}empty-nd"].hide # If we've checked something as undone, uncompleted items can't be empty end page.hide "status" page.replace_html "badge_count", @down_count diff --git a/tracks/app/views/project/_project.rhtml b/tracks/app/views/project/_project.rhtml index 40549cd6..b962c32d 100644 --- a/tracks/app/views/project/_project.rhtml +++ b/tracks/app/views/project/_project.rhtml @@ -15,7 +15,7 @@

Project has been marked as completed

<% end -%>
-
+

Currently there are no uncompleted actions in this project

<%= render :partial => "todo/item", :collection => @not_done %> diff --git a/tracks/app/views/project/add_item.rjs b/tracks/app/views/project/add_item.rjs index fdb06db4..aebc3549 100644 --- a/tracks/app/views/project/add_item.rjs +++ b/tracks/app/views/project/add_item.rjs @@ -7,7 +7,7 @@ if @saved page.send :record, "Form.reset('todo-form-new-action-lightbox');Form.focusFirstElement('todo-form-new-action-lightbox')" page.insert_html :bottom, "p#{@item.project_id}", :partial => 'todo/item' page.visual_effect :highlight, "item-#{@item.id}-container", :duration => 3 - page.hide "empty-nd" # If we are adding an new action, the uncompleted actions must be > 0 + page.hide "p#{@item.project_id}empty-nd" # If we are adding an new action, the uncompleted actions must be > 0 else page.hide "status" page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@item.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @item.errors.each_full { |msg| content_tag("li", msg) }), "id" => "ErrorExplanation", "class" => "ErrorExplanation") diff --git a/tracks/app/views/project/destroy_action.rjs b/tracks/app/views/project/destroy_action.rjs index 28335b4e..e25073c1 100644 --- a/tracks/app/views/project/destroy_action.rjs +++ b/tracks/app/views/project/destroy_action.rjs @@ -2,7 +2,7 @@ if @saved page.visual_effect :fade, "item-#{@item.id}-container", :duration => 0.4 page.replace_html "badge_count", @down_count if @down_count == "0" - page.show 'empty-nd' + page["p#{@item.project_id}empty-nd"].show end else page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@item.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @item.errors.each_full { |msg| content_tag("li", msg) }), "id" => "ErrorExplanation", "class" => "ErrorExplanation") diff --git a/tracks/app/views/project/toggle_check.rjs b/tracks/app/views/project/toggle_check.rjs index 15bfa97f..64e51e6e 100644 --- a/tracks/app/views/project/toggle_check.rjs +++ b/tracks/app/views/project/toggle_check.rjs @@ -6,18 +6,18 @@ if @saved page.insert_html :top, "completed", :partial => 'todo/item' page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} if @down_count == '0' - page.show "empty-nd" + page["p#{@item.project_id}empty-nd"].show end page.hide "empty-d" # If we've checked something as done, completed items can't be empty end else - page.call "ensureVisibleWithEffectAppear", "p#{@item.project_id}" + page.call "todoItems.ensureVisibleWithEffectAppear", "p#{@item.project_id}" page.insert_html :bottom, "p#{@item.project_id}", :partial => 'todo/item' page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} if @done_count == '0' page.show "empty-d" end - page.hide "empty-nd" # If we've checked something as undone, uncompleted items can't be empty + page["p#{@item.project_id}empty-nd"].hide # If we've checked something as undone, uncompleted items can't be empty end page.hide "status" page.replace_html "badge_count", @down_count diff --git a/tracks/app/views/todo/_tickler_items.rhtml b/tracks/app/views/todo/_tickler_items.rhtml index 55626861..cb65f9a7 100644 --- a/tracks/app/views/todo/_tickler_items.rhtml +++ b/tracks/app/views/todo/_tickler_items.rhtml @@ -2,7 +2,7 @@

Deferred actions

-
+

Currently there are no deferred actions

diff --git a/tracks/app/views/todo/add_deferred_item.rjs b/tracks/app/views/todo/add_deferred_item.rjs index ed03563d..ce393e74 100644 --- a/tracks/app/views/todo/add_deferred_item.rjs +++ b/tracks/app/views/todo/add_deferred_item.rjs @@ -6,6 +6,7 @@ if @saved page.send :record, "Form.reset('todo-form-new-action');Form.focusFirstElement('todo-form-new-action')" page.insert_html :bottom, "tickler", :partial => 'todo/tickle', :object => @item page.visual_effect :highlight, "item-#{@item.id}-container", :duration => 3 + page["tickler-empty-nd"].hide else page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@item.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @item.errors.each_full { |msg| content_tag("li", msg) }), "id" => "ErrorExplanation", "class" => "ErrorExplanation") page.visual_effect :appear, 'status', :duration => 0.5 diff --git a/tracks/app/views/todo/add_item.rjs b/tracks/app/views/todo/add_item.rjs index 765285cc..c14683bf 100644 --- a/tracks/app/views/todo/add_item.rjs +++ b/tracks/app/views/todo/add_item.rjs @@ -5,8 +5,10 @@ if @saved page['badge_count'].replace_html @up_count page.send :record, "Form.reset('todo-form-new-action');Form.focusFirstElement('todo-form-new-action')" page.send :record, "Form.reset('todo-form-new-action-lightbox');Form.focusFirstElement('todo-form-new-action-lightbox')" + page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}" page.insert_html :bottom, "c#{@item.context_id}items", :partial => 'todo/item' page.visual_effect :highlight, "item-#{@item.id}-container", :duration => 3 + page["c#{@item.context_id}empty-nd"].hide else page.hide "status" page.replace_html "status", content_tag("div", content_tag("h2", "#{pluralize(@item.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @item.errors.each_full { |msg| content_tag("li", msg) }), "id" => "ErrorExplanation", "class" => "ErrorExplanation") diff --git a/tracks/app/views/todo/destroy_action.rjs b/tracks/app/views/todo/destroy_action.rjs index f7b6ca64..0359e012 100644 --- a/tracks/app/views/todo/destroy_action.rjs +++ b/tracks/app/views/todo/destroy_action.rjs @@ -1,6 +1,9 @@ if @saved page["item-#{@item.id}-container"].remove page['badge_count'].replace_html @down_count + if @remaining_undone_in_context == 0 + page.visual_effect :fade, "c#{@item.context_id}", :duration => 0.4 + end else page["status"].replace_html content_tag("div", content_tag("h2", "#{pluralize(@item.errors.count, "error")} prohibited this record from being saved") + content_tag("p", "There were problems with the following fields:") + content_tag("ul", @item.errors.each_full { |msg| content_tag("li", msg) }), "id" => "ErrorExplanation", "class" => "ErrorExplanation") end \ No newline at end of file diff --git a/tracks/app/views/todo/toggle_check.rjs b/tracks/app/views/todo/toggle_check.rjs index 5735bfc3..07b78359 100644 --- a/tracks/app/views/todo/toggle_check.rjs +++ b/tracks/app/views/todo/toggle_check.rjs @@ -9,8 +9,11 @@ if @saved page.insert_html :top, "completed", :partial => 'todo/item' page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} end + if @remaining_undone_in_context == 0 + page.visual_effect :fade, "c#{@item.context_id}", :duration => 0.4 + end else - page.call "ensureVisibleWithEffectAppear", "c#{@item.context_id}" + page.call "todoItems.ensureVisibleWithEffectAppear", "c#{@item.context_id}" page.insert_html :bottom, "c#{@item.context_id}", :partial => 'todo/item' page.visual_effect :highlight, "item-#{@item.id}", {'startcolor' => "'#99ff99'"} end