|
|
|
@ -172,6 +172,76 @@ module Redmine
|
|
|
|
|
{:files => saved_attachments, :unsaved => unsaved_attachments}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 扩展方法,因为类型太多,为了不影响其它的
|
|
|
|
|
# 最终需要形成一个方法
|
|
|
|
|
def save_attachments_containers(attachments, author, is_public)
|
|
|
|
|
# 清除临时文件
|
|
|
|
|
if attachments
|
|
|
|
|
tempAttach = attachments[:dummy]
|
|
|
|
|
if tempAttach && tempAttach[:file]
|
|
|
|
|
attachments.delete(:dummy)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if attachments.is_a?(Hash)
|
|
|
|
|
attachments = attachments.stringify_keys
|
|
|
|
|
attachments = attachments.to_a.sort {|a, b|
|
|
|
|
|
if a.first.to_i > 0 && b.first.to_i > 0
|
|
|
|
|
a.first.to_i <=> b.first.to_i
|
|
|
|
|
elsif a.first.to_i > 0
|
|
|
|
|
1
|
|
|
|
|
elsif b.first.to_i > 0
|
|
|
|
|
-1
|
|
|
|
|
else
|
|
|
|
|
a.first <=> b.first
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
attachments = attachments.map(&:last)
|
|
|
|
|
end
|
|
|
|
|
if attachments.is_a?(Array)
|
|
|
|
|
attachments.each do |attachment|
|
|
|
|
|
if attachment.is_a?(Hash)
|
|
|
|
|
a = nil
|
|
|
|
|
file = attachment['file']
|
|
|
|
|
token = attachment['token']
|
|
|
|
|
t = file && file.size > 0
|
|
|
|
|
if file && file.size > 0
|
|
|
|
|
a = Attachment.create(:file => file, :author => author)
|
|
|
|
|
elsif token
|
|
|
|
|
# 通过token值找到对应的attachment
|
|
|
|
|
a = Attachment.find_by_token_only(token)
|
|
|
|
|
if a
|
|
|
|
|
a.filename = attachment['filename'] unless attachment['filename'].blank?
|
|
|
|
|
a.content_type = attachment['content_type']
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if a && !attachment['is_public_checkbox']
|
|
|
|
|
# 考虑到更新操作,所以全部设置为公开,私有项目、课程是不能访问的
|
|
|
|
|
if is_public
|
|
|
|
|
a.is_public = true
|
|
|
|
|
else
|
|
|
|
|
a.is_public = false
|
|
|
|
|
end
|
|
|
|
|
elsif a && attachment['is_public_checkbox']
|
|
|
|
|
a.is_public = true
|
|
|
|
|
end
|
|
|
|
|
set_attachment_public(a) if a
|
|
|
|
|
next unless a
|
|
|
|
|
a.description = attachment['description'].to_s.strip
|
|
|
|
|
a.attachtype = @curattachment_type
|
|
|
|
|
if a.new_record?
|
|
|
|
|
unsaved_attachments << a
|
|
|
|
|
else
|
|
|
|
|
saved_attachments << a
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
{:files => saved_attachments, :unsaved => unsaved_attachments}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def attach_saved_attachments
|
|
|
|
|
saved_attachments.each do |attachment|
|
|
|
|
|
self.attachments << attachment
|
|
|
|
|