Cleanup in TimelogController#destroy.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9095 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
dc50edae5e
commit
6b47cad8ce
@ -507,8 +507,12 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Renders API response on validation failure
|
# Renders API response on validation failure
|
||||||
def render_validation_errors(object)
|
def render_validation_errors(objects)
|
||||||
@error_messages = object.errors.full_messages
|
if objects.is_a?(Array)
|
||||||
|
@error_messages = objects.map {|object| object.errors.full_messages}.flatten
|
||||||
|
else
|
||||||
|
@error_messages = objects.errors.full_messages
|
||||||
|
end
|
||||||
render :template => 'common/error_messages.api', :status => :unprocessable_entity, :layout => false
|
render :template => 'common/error_messages.api', :status => :unprocessable_entity, :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -199,30 +199,30 @@ class TimelogController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
destroyed = TimeEntry.transaction do
|
||||||
@time_entries.each do |t|
|
@time_entries.each do |t|
|
||||||
begin
|
|
||||||
unless t.destroy && t.destroyed?
|
unless t.destroy && t.destroyed?
|
||||||
respond_to do |format|
|
raise ActiveRecord::Rollback
|
||||||
format.html {
|
|
||||||
flash[:error] = l(:notice_unable_delete_time_entry)
|
|
||||||
redirect_to :back
|
|
||||||
}
|
|
||||||
format.api { render_validation_errors(t) }
|
|
||||||
end
|
end
|
||||||
return
|
|
||||||
end
|
|
||||||
rescue ::ActionController::RedirectBackError
|
|
||||||
redirect_to :action => 'index', :project_id => @projects.first
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
|
if destroyed
|
||||||
flash[:notice] = l(:notice_successful_delete)
|
flash[:notice] = l(:notice_successful_delete)
|
||||||
|
else
|
||||||
|
flash[:error] = l(:notice_unable_delete_time_entry)
|
||||||
|
end
|
||||||
redirect_back_or_default(:action => 'index', :project_id => @projects.first)
|
redirect_back_or_default(:action => 'index', :project_id => @projects.first)
|
||||||
}
|
}
|
||||||
format.api { head :ok }
|
format.api {
|
||||||
|
if destroyed
|
||||||
|
head :ok
|
||||||
|
else
|
||||||
|
render_validation_errors(@time_entries)
|
||||||
|
end
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user