def move_to_period(with_layout = false)
params[:id] = $1 if params[:id] =~ /^task_(\d*)$/
task = Task.find(params[:id])
if request.post?
period = params[:period_id] && Period.find(params[:period_id])
if period && period.active_or_future?
next_task = task.higher_item ? task.higher_item : task.lower_item ? task.lower_item : task
task.move_to_period period
if with_layout
back_or_redirect_to :controller => 'periods', :action => :show, :id => next_task.period, :task_id => next_task.id
else
back_or_redirect_to :controller => 'periods', :action => :show_no_layout, :id => next_task.period, :task_id => next_task.id
end
else
detour_to :controller => 'periods', :action => :new, :period => {:party_id => task.period.party_id}, :layout => with_layout && determine_layout
end
else
redirect_to :controller => 'periods', :action => :show, :id => task.period, :task_id => task.id, :layout => with_layout && determine_layout
end
end