diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-12-10 20:09:41 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-12-10 20:09:41 +0000 |
commit | ef25210aca9278e51f81bd15e85a3143c667ff17 (patch) | |
tree | 312d20360571770a231f4fd307c12d0c535d60f2 /app/controllers/attachments_controller.rb | |
parent | 2304f5d42c2bb1829b1cf9055c2848db116742d3 (diff) | |
download | redmine-ef25210aca9278e51f81bd15e85a3143c667ff17.tar.gz redmine-ef25210aca9278e51f81bd15e85a3143c667ff17.zip |
Merged ajax_upload branch (#3957).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10977 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/attachments_controller.rb')
-rw-r--r-- | app/controllers/attachments_controller.rb | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 13871c323..53e0fd6d4 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -85,15 +85,17 @@ class AttachmentsController < ApplicationController @attachment = Attachment.new(:file => request.raw_post) @attachment.author = User.current @attachment.filename = params[:filename].presence || Redmine::Utils.random_hex(16) + saved = @attachment.save - if @attachment.save - respond_to do |format| - format.api { render :action => 'upload', :status => :created } - end - else - respond_to do |format| - format.api { render_validation_errors(@attachment) } - end + respond_to do |format| + format.js + format.api { + if saved + render :action => 'upload', :status => :created + else + render_validation_errors(@attachment) + end + } end end @@ -101,9 +103,17 @@ class AttachmentsController < ApplicationController if @attachment.container.respond_to?(:init_journal) @attachment.container.init_journal(User.current) end - # Make sure association callbacks are called - @attachment.container.attachments.delete(@attachment) - redirect_to_referer_or project_path(@project) + if @attachment.container + # Make sure association callbacks are called + @attachment.container.attachments.delete(@attachment) + else + @attachment.destroy + end + + respond_to do |format| + format.html { redirect_to_referer_or project_path(@project) } + format.js + end end private |