diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-01-29 20:51:48 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-01-29 20:51:48 +0000 |
commit | cd6db6a3cbe43880eca4eec8c967fb78d95a2926 (patch) | |
tree | 42219d3f9b276f197f5045cec25639bb4e2be5fd /app/models/issue.rb | |
parent | 0c5af16e14570a384e154430cd1e9fa123cdf579 (diff) | |
download | redmine-cd6db6a3cbe43880eca4eec8c967fb78d95a2926.tar.gz redmine-cd6db6a3cbe43880eca4eec8c967fb78d95a2926.zip |
Adds support for multiselect custom fields (#1189).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8721 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r-- | app/models/issue.rb | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index d20cff35d..f6c458990 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -429,7 +429,7 @@ class Issue < ActiveRecord::Base else @attributes_before_change = attributes.dup @custom_values_before_change = {} - self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value } + self.custom_field_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value } end # Make sure updated_on is updated when adding a note. updated_on_will_change! @@ -1006,14 +1006,35 @@ class Issue < ActiveRecord::Base end if @custom_values_before_change # custom fields changes - custom_values.each {|c| + custom_field_values.each {|c| before = @custom_values_before_change[c.custom_field_id] after = c.value next if before == after || (before.blank? && after.blank?) - @current_journal.details << JournalDetail.new(:property => 'cf', - :prop_key => c.custom_field_id, - :old_value => before, - :value => after) + + if before.is_a?(Array) || after.is_a?(Array) + before = [before] unless before.is_a?(Array) + after = [after] unless after.is_a?(Array) + + # values removed + (before - after).reject(&:blank?).each do |value| + @current_journal.details << JournalDetail.new(:property => 'cf', + :prop_key => c.custom_field_id, + :old_value => value, + :value => nil) + end + # values added + (after - before).reject(&:blank?).each do |value| + @current_journal.details << JournalDetail.new(:property => 'cf', + :prop_key => c.custom_field_id, + :old_value => nil, + :value => value) + end + else + @current_journal.details << JournalDetail.new(:property => 'cf', + :prop_key => c.custom_field_id, + :old_value => before, + :value => after) + end } end @current_journal.save |