diff --git a/tracks/app/controllers/context_controller.rb b/tracks/app/controllers/context_controller.rb index 1f862256..e1b653b8 100644 --- a/tracks/app/controllers/context_controller.rb +++ b/tracks/app/controllers/context_controller.rb @@ -59,7 +59,9 @@ class ContextController < ApplicationController @saved = @item.save @on_page = "context" - @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.context_id IN (?)", @user.id, @item.context_id]).size.to_s + if @saved + @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.context_id IN (?)", @user.id, @item.context_id]).size.to_s + end return if request.xhr? @@ -88,7 +90,9 @@ class ContextController < ApplicationController @item = check_user_return_item @saved = @item.destroy - @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.context_id IN (?)", @user.id, @item.context_id]).size.to_s + if @saved + @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.context_id IN (?)", @user.id, @item.context_id]).size.to_s + end return if request.xhr? @@ -108,6 +112,29 @@ class ContextController < ApplicationController render :controller => 'todo', :action => 'list' end end + + # Toggles the 'done' status of the action + # + def toggle_check + self.init + + @item = check_user_return_item + @item.toggle!('done') + @item.completed = Time.now() # For some reason, the before_save in todo.rb stopped working + @saved = @item.save + if @saved + @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.context_id IN (?)", @user.id, @item.context_id]).size.to_s + @done_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 1 and todos.context_id IN (?)", @user.id, @item.context_id]).size.to_s + end + return if request.xhr? + + if @saved + flash['notice'] = "The action '#{@item.description}' was marked as #{@item.done? ? 'complete' : 'incomplete' }" + else + flash['notice'] = "The action '#{@item.description}' was NOT marked as #{@item.done? ? 'complete' : 'incomplete' } due to an error on the server." + end + redirect_to :action => "list" + end # Edit the details of the context # diff --git a/tracks/app/controllers/project_controller.rb b/tracks/app/controllers/project_controller.rb index 80a031c5..0d0bd3dc 100644 --- a/tracks/app/controllers/project_controller.rb +++ b/tracks/app/controllers/project_controller.rb @@ -78,7 +78,9 @@ class ProjectController < ApplicationController @saved = @item.save @on_page = "project" - @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.project_id IN (?)", @user.id, @item.project_id]).size.to_s + if @saved + @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.project_id IN (?)", @user.id, @item.project_id]).size.to_s + end return if request.xhr? @@ -107,7 +109,10 @@ class ProjectController < ApplicationController @item = check_user_return_item @saved = @item.destroy - @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.project_id IN (?)", @user.id, @item.project_id]).size.to_s + @on_page = "project" + if @saved + @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.project_id IN (?)", @user.id, @item.project_id]).size.to_s + end return if request.xhr? @@ -128,6 +133,30 @@ class ProjectController < ApplicationController end end + # Toggles the 'done' status of the action + # + def toggle_check + self.init + + @item = check_user_return_item + @item.toggle!('done') + @item.completed = Time.now() # For some reason, the before_save in todo.rb stopped working + @saved = @item.save + @on_page = "project" + if @saved + @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0 and todos.project_id IN (?)", @user.id, @item.project_id]).size.to_s + @done_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 1 and todos.project_id IN (?)", @user.id, @item.project_id]).size.to_s + end + return if request.xhr? + + if @saved + flash['notice'] = "The action '#{@item.description}' was marked as #{@item.done? ? 'complete' : 'incomplete' }" + else + flash['notice'] = "The action '#{@item.description}' was NOT marked as #{@item.done? ? 'complete' : 'incomplete' } due to an error on the server." + end + redirect_to :action => "list" + end + # Edit the details of the project # def update diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 67b943ef..be54a23a 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -26,10 +26,10 @@ class TodoController < ApplicationController @done = @done[0..(NO_OF_ACTIONS-1)] @contexts_to_show = @contexts.clone - @contexts_to_show = @contexts_to_show.collect {|x| (!x.hidden? and !x.find_not_done_todos.empty?) ? x:nil }.compact + @contexts_to_show = @contexts_to_show.collect {|x| (!x.hide? and !x.find_not_done_todos.empty?) ? x:nil }.compact # Set count badge to number of not-done, not hidden context items - @count = @todos.collect { |x| ( !x.done? and !x.context.hidden? ) ? x:nil }.compact.size + @count = @todos.collect { |x| ( !x.done? and !x.context.hide? ) ? x:nil }.compact.size end def update_element @@ -51,8 +51,9 @@ class TodoController < ApplicationController @saved = @item.save @on_page = "home" - @up_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0", @user.id]).size.to_s - + if @saved + @up_count = @todos.collect { |x| ( !x.done? and !x.context.hide? ) ? x:nil }.compact.size.to_s + end return if request.xhr? # fallback for standard requests @@ -75,8 +76,8 @@ class TodoController < ApplicationController def edit_action self.init - item = check_user_return_item + render :partial => 'action_edit_form', :object => item end @@ -85,17 +86,22 @@ class TodoController < ApplicationController def toggle_check self.init - item = check_user_return_item - item.toggle!('done') - item.completed = Time.now() # For some reason, the before_save in todo.rb stopped working - if item.save - if request.xhr? - render :partial => 'item', :object => item - else - flash['notice'] = "The item '#{item.description}' was marked as #{item.done? ? 'complete' : 'incomplete' }" - redirect_to :action => "list" - end + @item = check_user_return_item + @item.toggle!('done') + @item.completed = Time.now() # For some reason, the before_save in todo.rb stopped working + @saved = @item.save + @on_page = "home" + if @saved + @down_count = @todos.collect { |x| ( !x.done? and !x.context.hide? ) ? x:nil }.compact.size.to_s end + return if request.xhr? + + if @saved + flash['notice'] = "The action '#{@item.description}' was marked as #{@item.done? ? 'complete' : 'incomplete' }" + else + flash['notice'] = "The action '#{@item.description}' was NOT marked as #{@item.done? ? 'complete' : 'incomplete' } due to an error on the server." + end + redirect_to :action => "list" end # Edit the details of an action @@ -129,7 +135,10 @@ class TodoController < ApplicationController @item = check_user_return_item @saved = @item.destroy - @down_count = Todo.find(:all, :conditions => ["todos.user_id = ? and todos.done = 0", @user.id]).size.to_s + @on_page = "home" + if @saved + @down_count = @todos.collect { |x| ( !x.done? and !x.context.hide? ) ? x:nil }.compact.size.to_s + end return if request.xhr? diff --git a/tracks/app/helpers/todo_helper.rb b/tracks/app/helpers/todo_helper.rb index f616e213..7eb1914c 100644 --- a/tracks/app/helpers/todo_helper.rb +++ b/tracks/app/helpers/todo_helper.rb @@ -6,30 +6,6 @@ module TodoHelper count = Todo.find_all("done=0 AND context_id=#{context.id}").length end - def form_remote_tag_toggle_todo( item ) - target_div = item.done? ? "c#{item.context_id}" : "completed" - target_position = item.done? ? "bottom" : "top" - form_id = "checkbox-#{item.id}-form" - item_container_id = "item-#{item.id}-container" - - loading_javascript = "Form.disable('#{form_id}');" - - success_javascript = " $('#{item_container_id}').setAttribute('id','#{item_container_id}-fading');" - success_javascript << visual_effect( :fade, "#{item_container_id}-fading", - { - :duration => 0.4, - :afterFinish => "function(effect) { Element.remove('#{item_container_id}-fading'); }" - }) - - form_remote_tag( :url => url_for( :controller => "todo", :action => "toggle_check", :id => item.id ), - :html => { :id=> "#{form_id}", :class => "inline-form item-checkmark-form" }, - :update => target_div, - :position => target_position, - :loading => loading_javascript, - :success => success_javascript, - :complete => visual_effect( :highlight, item_container_id)) - end - 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" }, diff --git a/tracks/app/views/context/_context_listing.rhtml b/tracks/app/views/context/_context_listing.rhtml index 727797e7..98484c90 100644 --- a/tracks/app/views/context/_context_listing.rhtml +++ b/tracks/app/views/context/_context_listing.rhtml @@ -11,7 +11,7 @@
-<% if context.hide == 1 %> +<% if context.hide? %> HIDDEN <% else %> VISIBLE diff --git a/tracks/app/views/context/toggle_check.rjs b/tracks/app/views/context/toggle_check.rjs new file mode 100644 index 00000000..d4a9b169 --- /dev/null +++ b/tracks/app/views/context/toggle_check.rjs @@ -0,0 +1,23 @@ +if @saved + page.call "fadeAndRemoveItem", "item-#{@item.id}-container" + if @item.done? + 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" + end + page.hide "empty-d" # If we've checked something as done, completed items can't be empty + else + page.call "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 + end + page.hide "status" + page.replace_html "badge_count", @down_count +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") +end \ No newline at end of file diff --git a/tracks/app/views/project/toggle_check.rjs b/tracks/app/views/project/toggle_check.rjs new file mode 100644 index 00000000..e0c4d037 --- /dev/null +++ b/tracks/app/views/project/toggle_check.rjs @@ -0,0 +1,23 @@ +if @saved + page.call "fadeAndRemoveItem", "item-#{@item.id}-container" + if @item.done? + 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" + end + page.hide "empty-d" # If we've checked something as done, completed items can't be empty + else + page.call "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 + end + page.hide "status" + page.replace_html "badge_count", @down_count +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") +end \ No newline at end of file diff --git a/tracks/app/views/shared/sidebar.rhtml b/tracks/app/views/shared/sidebar.rhtml index 0d10af5f..4164b3a0 100644 --- a/tracks/app/views/shared/sidebar.rhtml +++ b/tracks/app/views/shared/sidebar.rhtml @@ -16,7 +16,7 @@

Active Contexts: