mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-28 21:08:48 +01:00
folding mobile_done method into original toggle_check method
the mobile_done method was created to test out a checkbox submit the mobile interface. In the interests of DRY, this brings the new mobile code into the original method,
This commit is contained in:
parent
27fb483485
commit
250e1d8fcc
2 changed files with 12 additions and 51 deletions
|
|
@ -348,62 +348,23 @@ class TodosController < ApplicationController
|
|||
end
|
||||
end
|
||||
format.m {
|
||||
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
|
||||
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
|
||||
notify(:notice, t("todos.action_marked_complete", :description => @todo.description, :completed => @todo.completed? ? 'complete' : 'incomplete'))
|
||||
redirect_to todos_path(:format => 'm')
|
||||
render :action => "edit", :format => :m
|
||||
end
|
||||
}
|
||||
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!
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ module TodosHelper
|
|||
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
|
||||
form_tag toggle_check_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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue