mirror of
https://github.com/redmine/redmine.git
synced 2026-07-07 13:02:10 +02:00
Adds file custom field format (#6719).
git-svn-id: http://svn.redmine.org/redmine/trunk@15917 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -34,6 +34,7 @@ module Redmine
|
||||
options.merge(:as => :container, :dependent => :destroy, :inverse_of => :container)
|
||||
send :include, Redmine::Acts::Attachable::InstanceMethods
|
||||
before_save :attach_saved_attachments
|
||||
after_rollback :detach_saved_attachments
|
||||
validate :warn_about_failed_attachments
|
||||
end
|
||||
end
|
||||
@@ -90,7 +91,7 @@ module Redmine
|
||||
if file = attachment['file']
|
||||
next unless file.size > 0
|
||||
a = Attachment.create(:file => file, :author => author)
|
||||
elsif token = attachment['token']
|
||||
elsif token = attachment['token'].presence
|
||||
a = Attachment.find_by_token(token)
|
||||
unless a
|
||||
@failed_attachment_count += 1
|
||||
@@ -117,6 +118,14 @@ module Redmine
|
||||
end
|
||||
end
|
||||
|
||||
def detach_saved_attachments
|
||||
saved_attachments.each do |attachment|
|
||||
# TODO: use #reload instead, after upgrading to Rails 5
|
||||
# (after_rollback is called when running transactional tests in Rails 4)
|
||||
attachment.container = nil
|
||||
end
|
||||
end
|
||||
|
||||
def warn_about_failed_attachments
|
||||
if @failed_attachment_count && @failed_attachment_count > 0
|
||||
errors.add :base, ::I18n.t('warning_attachments_not_saved', count: @failed_attachment_count)
|
||||
|
||||
@@ -68,16 +68,7 @@ module Redmine
|
||||
custom_field_values.each do |custom_field_value|
|
||||
key = custom_field_value.custom_field_id.to_s
|
||||
if values.has_key?(key)
|
||||
value = values[key]
|
||||
if value.is_a?(Array)
|
||||
value = value.reject(&:blank?).map(&:to_s).uniq
|
||||
if value.empty?
|
||||
value << ''
|
||||
end
|
||||
else
|
||||
value = value.to_s
|
||||
end
|
||||
custom_field_value.value = value
|
||||
custom_field_value.value = values[key]
|
||||
end
|
||||
end
|
||||
@custom_field_values_changed = true
|
||||
@@ -93,11 +84,11 @@ module Redmine
|
||||
if values.empty?
|
||||
values << custom_values.build(:customized => self, :custom_field => field)
|
||||
end
|
||||
x.value = values.map(&:value)
|
||||
x.instance_variable_set("@value", values.map(&:value))
|
||||
else
|
||||
cv = custom_values.detect { |v| v.custom_field == field }
|
||||
cv ||= custom_values.build(:customized => self, :custom_field => field)
|
||||
x.value = cv.value
|
||||
x.instance_variable_set("@value", cv.value)
|
||||
end
|
||||
x.value_was = x.value.dup if x.value
|
||||
x
|
||||
|
||||
Reference in New Issue
Block a user