summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-03-08 19:55:56 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-03-08 19:55:56 +0000
commitf338fe9075e16de82a3bcbc860675d3404e8a774 (patch)
treee3fa5e7fd638a65ac22e4767e59d6caa761ee1a4 /lib
parenta63908c5eda2747eb40c6880d7b04ee8b706d9fe (diff)
downloadredmine-f338fe9075e16de82a3bcbc860675d3404e8a774.tar.gz
redmine-f338fe9075e16de82a3bcbc860675d3404e8a774.zip
Allow to set multiple values in emails for list custom fields (#16549).
git-svn-id: http://svn.redmine.org/redmine/trunk@16380 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r--lib/redmine/field_format.rb48
1 files changed, 38 insertions, 10 deletions
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb
index cfdab0e21..c1ce0055c 100644
--- a/lib/redmine/field_format.rb
+++ b/lib/redmine/field_format.rb
@@ -167,12 +167,13 @@ module Redmine
def value_from_keyword(custom_field, keyword, object)
possible_values_options = possible_values_options(custom_field, object)
if possible_values_options.present?
- keyword = keyword.to_s
- if v = possible_values_options.detect {|text, id| keyword.casecmp(text) == 0}
- if v.is_a?(Array)
- v.last
- else
- v
+ parse_keyword(custom_field, keyword) do |k|
+ if v = possible_values_options.detect {|text, id| k.casecmp(text) == 0}
+ if v.is_a?(Array)
+ v.last
+ else
+ v
+ end
end
end
else
@@ -180,6 +181,31 @@ module Redmine
end
end
+ def parse_keyword(custom_field, keyword, &block)
+ separator = Regexp.escape ","
+ keyword = keyword.to_s
+
+ if custom_field.multiple?
+ values = []
+ while keyword.length > 0
+ k = keyword.dup
+ loop do
+ if value = yield(k.strip)
+ values << value
+ break
+ elsif k.slice!(/#{separator}([^#{separator}]*)\Z/).nil?
+ break
+ end
+ end
+ keyword.slice!(/\A#{Regexp.escape k}#{separator}?/)
+ end
+ values
+ else
+ yield keyword.strip
+ end
+ end
+ protected :parse_keyword
+
# Returns the validation errors for custom_field
# Should return an empty array if custom_field is valid
def validate_custom_field(custom_field)
@@ -766,8 +792,9 @@ module Redmine
end
def value_from_keyword(custom_field, keyword, object)
- value = custom_field.enumerations.where("LOWER(name) LIKE LOWER(?)", keyword).first
- value ? value.id : nil
+ parse_keyword(custom_field, keyword) do |k|
+ custom_field.enumerations.where("LOWER(name) LIKE LOWER(?)", k).first.try(:id)
+ end
end
end
@@ -800,8 +827,9 @@ module Redmine
def value_from_keyword(custom_field, keyword, object)
users = possible_values_records(custom_field, object).to_a
- user = Principal.detect_by_keyword(users, keyword)
- user ? user.id : nil
+ parse_keyword(custom_field, keyword) do |k|
+ Principal.detect_by_keyword(users, k).try(:id)
+ end
end
def before_custom_field_save(custom_field)