Refactor: Decouple failed attachments and the flash messages
Attachment#attach_files will no longer need to return a flash message, instead it will put unsaved attachments into object#unsaved_attachments where the calling object can access them. A utility method #render_attachment_warning_if_needed is included for setting the standard flash warning. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3528 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -139,11 +139,9 @@ class Attachment < ActiveRecord::Base
|
||||
# Returns a Hash of the results:
|
||||
# :files => array of the attached files
|
||||
# :unsaved => array of the files that could not be attached
|
||||
# :flash => warning message
|
||||
def self.attach_files(obj, attachments)
|
||||
attached = []
|
||||
unsaved = []
|
||||
flash = nil
|
||||
if attachments && attachments.is_a?(Hash)
|
||||
attachments.each_value do |attachment|
|
||||
file = attachment['file']
|
||||
@@ -152,13 +150,10 @@ class Attachment < ActiveRecord::Base
|
||||
:file => file,
|
||||
:description => attachment['description'].to_s.strip,
|
||||
:author => User.current)
|
||||
a.new_record? ? (unsaved << a) : (attached << a)
|
||||
end
|
||||
if unsaved.any?
|
||||
flash = l(:warning_attachments_not_saved, unsaved.size)
|
||||
a.new_record? ? (obj.unsaved_attachments << a) : (attached << a)
|
||||
end
|
||||
end
|
||||
{:files => attached, :flash => flash, :unsaved => unsaved}
|
||||
{:files => attached, :unsaved => obj.unsaved_attachments}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user