diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 1661f22f..ffce91b9 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -361,6 +361,49 @@ class TodosController < ApplicationController end end + def mobile_done + # copied from toggle_check, left out other formats as they shouldn't come here + # ultimately would like to just use toggle_check + @todo = current_user.todos.find(params['id']) + @source_view = params['_source_view'] || 'todo' + @original_item_due = @todo.due + @original_item_was_deferred = @todo.deferred? + @original_item_was_pending = @todo.pending? + @original_item_was_hidden = @todo.hidden? + @original_item_context_id = @todo.context_id + @original_item_project_id = @todo.project_id + @todo_was_completed_from_deferred_or_blocked_state = @original_item_was_deferred || @original_item_was_pending + @saved = @todo.toggle_completion! + + @todo_was_blocked_from_completed_state = @todo.pending? # since we toggled_completion the previous state was completed + + # check if this todo has a related recurring_todo. If so, create next todo + @new_recurring_todo = check_for_next_todo(@todo) if @saved + + @predecessors = @todo.uncompleted_predecessors + if @saved + if @todo.completed? + @pending_to_activate = @todo.activate_pending_todos + else + @active_to_block = @todo.block_successors + end + end + + if @saved + if cookies[:mobile_url] + old_path = cookies[:mobile_url] + cookies[:mobile_url] = {:value => nil, :secure => SITE_CONFIG['secure_cookies']} + notify(:notice, t("todos.action_marked_complete", :description => @todo.description, :completed => @todo.completed? ? 'complete' : 'incomplete')) + redirect_to old_path + else + notify(:notice, t("todos.action_marked_complete", :description => @todo.description, :completed => @todo.completed? ? 'complete' : 'incomplete')) + redirect_to todos_path(:format => 'm') + end + else + render :action => "edit", :format => :m + end + end + def toggle_star @todo = current_user.todos.find(params['id']) @todo.toggle_star! @@ -1176,6 +1219,10 @@ class TodosController < ApplicationController lambda do @page_title = t('todos.mobile_todos_page_title') @home = true + + max_completed = current_user.prefs.show_number_completed + @done = current_user.todos.completed.find(:all, :limit => max_completed, :include => Todo::DEFAULT_INCLUDES) unless max_completed == 0 + cookies[:mobile_url]= { :value => request.request_uri, :secure => SITE_CONFIG['secure_cookies']} determine_down_count diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 2f3ef48e..d6f3ed53 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -89,6 +89,12 @@ module TodosHelper :title => todo.pending? ? t('todos.blocked_by', :predecessors => todo.uncompleted_predecessors.map(&:description).join(', ')) : "", :readonly => todo.pending?) end + def remote_mobile_checkbox(todo=@todo) + form_tag mobile_done_todo_path(@todo, :format => 'm'), :method => :put, :class => "mobile-done", :name => "mobile_complete_#{@todo.id}" do + check_box_tag('_source_view', 'todo', @todo && @todo.completed?, "onClick" => "document.mobile_complete_#{@todo.id}.submit()") + end + end + def date_span(todo=@todo) if todo.completed? content_tag(:span, {:class => :grey}) { format_date( todo.completed_at ) } diff --git a/app/views/projects/project_mobile.rhtml b/app/views/projects/project_mobile.rhtml index d79cad08..414cb297 100644 --- a/app/views/projects/project_mobile.rhtml +++ b/app/views/projects/project_mobile.rhtml @@ -4,6 +4,7 @@ <% unless @project.description.blank? -%>
<%= sanitize(@project.description) %>
<% end -%> +