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 /vendor | |
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 'vendor')
-rw-r--r-- | vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb index 943cc441c..88fe88b59 100644 --- a/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb +++ b/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb @@ -70,6 +70,12 @@ module Redmine 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?).uniq + if value.empty? + value << '' + end + end custom_field_value.value = value end end @@ -81,9 +87,17 @@ module Redmine x = CustomFieldValue.new x.custom_field = field x.customized = self - cv = custom_values.detect { |v| v.custom_field == field } - cv ||= custom_values.build(:customized => self, :custom_field => field, :value => nil) - x.value = cv.value + if field.multiple? + values = custom_values.select { |v| v.custom_field == field } + if values.empty? + values << custom_values.build(:customized => self, :custom_field => field, :value => nil) + end + x.value = values.map(&:value) + else + cv = custom_values.detect { |v| v.custom_field == field } + cv ||= custom_values.build(:customized => self, :custom_field => field, :value => nil) + x.value = cv.value + end x end end @@ -115,10 +129,18 @@ module Redmine def save_custom_field_values target_custom_values = [] custom_field_values.each do |custom_field_value| - target = custom_values.detect {|cv| cv.custom_field == custom_field_value.custom_field} - target ||= custom_values.build(:customized => self, :custom_field => custom_field_value.custom_field) - target.value = custom_field_value.value - target_custom_values << target + if custom_field_value.value.is_a?(Array) + custom_field_value.value.each do |v| + target = custom_values.detect {|cv| cv.custom_field == custom_field_value.custom_field && cv.value == v} + target ||= custom_values.build(:customized => self, :custom_field => custom_field_value.custom_field, :value => v) + target_custom_values << target + end + else + target = custom_values.detect {|cv| cv.custom_field == custom_field_value.custom_field} + target ||= custom_values.build(:customized => self, :custom_field => custom_field_value.custom_field) + target.value = custom_field_value.value + target_custom_values << target + end end self.custom_values = target_custom_values custom_values.each(&:save) |