mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
extract method
This commit is contained in:
parent
7aacc1a919
commit
e12981c827
1 changed files with 61 additions and 57 deletions
|
|
@ -95,68 +95,72 @@ class TodosController < ApplicationController
|
||||||
if is_multiple
|
if is_multiple
|
||||||
create_multiple
|
create_multiple
|
||||||
else
|
else
|
||||||
p = Todos::TodoCreateParamsHelper.new(params, current_user)
|
create_single
|
||||||
p.parse_dates unless mobile?
|
end
|
||||||
tag_list = p.tag_list
|
end
|
||||||
|
|
||||||
@todo = current_user.todos.build
|
def create_single
|
||||||
@todo.assign_attributes(p.attributes)
|
p = Todos::TodoCreateParamsHelper.new(params, current_user)
|
||||||
p.add_errors(@todo)
|
p.parse_dates unless mobile?
|
||||||
|
tag_list = p.tag_list
|
||||||
|
|
||||||
if @todo.errors.empty?
|
@todo = current_user.todos.build
|
||||||
@todo.add_predecessor_list(p.predecessor_list)
|
@todo.assign_attributes(p.attributes)
|
||||||
@saved = @todo.save
|
p.add_errors(@todo)
|
||||||
@todo.tag_with(tag_list) if @saved && tag_list.present?
|
|
||||||
@todo.block! if @todo.uncompleted_predecessors?
|
if @todo.errors.empty?
|
||||||
else
|
@todo.add_predecessor_list(p.predecessor_list)
|
||||||
@saved = false
|
@saved = @todo.save
|
||||||
|
@todo.tag_with(tag_list) if @saved && tag_list.present?
|
||||||
|
@todo.block! if @todo.uncompleted_predecessors?
|
||||||
|
else
|
||||||
|
@saved = false
|
||||||
|
end
|
||||||
|
|
||||||
|
@todo_was_created_deferred = @todo.deferred?
|
||||||
|
@todo_was_created_blocked = @todo.pending?
|
||||||
|
@not_done_todos = [@todo] if p.new_project_created || p.new_context_created
|
||||||
|
@new_project_created = p.new_project_created
|
||||||
|
@new_context_created = p.new_context_created
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html do
|
||||||
|
redirect_to :action => "index"
|
||||||
end
|
end
|
||||||
|
format.m do
|
||||||
@todo_was_created_deferred = @todo.deferred?
|
@return_path=cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
|
||||||
@todo_was_created_blocked = @todo.pending?
|
if @saved
|
||||||
@not_done_todos = [@todo] if p.new_project_created || p.new_context_created
|
onsite_redirect_to @return_path
|
||||||
@new_project_created = p.new_project_created
|
else
|
||||||
@new_context_created = p.new_context_created
|
@projects = current_user.projects
|
||||||
|
@contexts = current_user.contexts
|
||||||
respond_to do |format|
|
render :action => "new"
|
||||||
format.html do
|
|
||||||
redirect_to :action => "index"
|
|
||||||
end
|
end
|
||||||
format.m do
|
end
|
||||||
@return_path=cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
|
format.js do
|
||||||
if @saved
|
if @saved
|
||||||
onsite_redirect_to @return_path
|
determine_down_count
|
||||||
else
|
@contexts = current_user.contexts
|
||||||
@projects = current_user.projects
|
@projects = current_user.projects
|
||||||
@contexts = current_user.contexts
|
@context = @todo.context
|
||||||
render :action => "new"
|
@project = @todo.project
|
||||||
end
|
@initial_context_name = params['default_context_name']
|
||||||
|
@initial_project_name = params['default_project_name']
|
||||||
|
@initial_tags = params['initial_tag_list']
|
||||||
|
@status_message = t('todos.added_new_next_action')
|
||||||
|
@status_message += ' ' + t('todos.to_tickler') if @todo.deferred?
|
||||||
|
@status_message += ' ' + t('todos.in_pending_state') if @todo.pending?
|
||||||
|
@status_message += ' ' + t('todos.in_hidden_state') if @todo.hidden?
|
||||||
|
@status_message = t('todos.added_new_project') + ' / ' + @status_message if @new_project_created
|
||||||
|
@status_message = t('todos.added_new_context') + ' / ' + @status_message if @new_context_created
|
||||||
end
|
end
|
||||||
format.js do
|
render :action => 'create'
|
||||||
if @saved
|
end
|
||||||
determine_down_count
|
format.xml do
|
||||||
@contexts = current_user.contexts
|
if @saved
|
||||||
@projects = current_user.projects
|
head :created, :location => todo_url(@todo)
|
||||||
@context = @todo.context
|
else
|
||||||
@project = @todo.project
|
render_failure @todo.errors.to_xml.html_safe, 409
|
||||||
@initial_context_name = params['default_context_name']
|
|
||||||
@initial_project_name = params['default_project_name']
|
|
||||||
@initial_tags = params['initial_tag_list']
|
|
||||||
@status_message = t('todos.added_new_next_action')
|
|
||||||
@status_message += ' ' + t('todos.to_tickler') if @todo.deferred?
|
|
||||||
@status_message += ' ' + t('todos.in_pending_state') if @todo.pending?
|
|
||||||
@status_message += ' ' + t('todos.in_hidden_state') if @todo.hidden?
|
|
||||||
@status_message = t('todos.added_new_project') + ' / ' + @status_message if @new_project_created
|
|
||||||
@status_message = t('todos.added_new_context') + ' / ' + @status_message if @new_context_created
|
|
||||||
end
|
|
||||||
render :action => 'create'
|
|
||||||
end
|
|
||||||
format.xml do
|
|
||||||
if @saved
|
|
||||||
head :created, :location => todo_url(@todo)
|
|
||||||
else
|
|
||||||
render_failure @todo.errors.to_xml.html_safe, 409
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue