diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-10-25 08:32:47 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-10-25 08:32:47 +0000 |
commit | 2f51dc11cfdf9cdbd2c67ec12cf93f4b112646bc (patch) | |
tree | 0216d3fe5705f74909c477e9fcca56438e0fed5f /lib/redmine | |
parent | 934a7615c427caf120b5386e62aa159b8d79949f (diff) | |
download | redmine-2f51dc11cfdf9cdbd2c67ec12cf93f4b112646bc.tar.gz redmine-2f51dc11cfdf9cdbd2c67ec12cf93f4b112646bc.zip |
Adds Enumeration custom field format (#21060).
Similar to List format but stores possible values as records.
git-svn-id: http://svn.redmine.org/redmine/trunk@14745 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine')
-rw-r--r-- | lib/redmine/field_format.rb | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index 3d97f601b..841d6a08d 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -539,7 +539,7 @@ module Redmine add 'list' self.searchable_supported = true self.form_partial = 'custom_fields/formats/list' - + def possible_custom_value_options(custom_value) options = possible_values_options(custom_value.custom_field) missing = [custom_value.value].flatten.reject(&:blank?) - options @@ -636,7 +636,6 @@ module Redmine missing = [custom_value.value_was].flatten.reject(&:blank?) - options.map(&:last) if missing.any? options += target_class.where(:id => missing.map(&:to_i)).map {|o| [o.to_s, o.id.to_s]} - options.sort_by!(&:first) end options end @@ -674,6 +673,32 @@ module Redmine protected :value_join_alias end + class EnumerationFormat < RecordList + add 'enumeration' + self.form_partial = 'custom_fields/formats/enumeration' + + def label + "label_field_format_enumeration" + end + + def target_class + @target_class ||= CustomFieldEnumeration + end + + def possible_values_options(custom_field, object=nil) + possible_values_records(custom_field, object).map {|u| [u.name, u.id.to_s]} + end + + def possible_values_records(custom_field, object=nil) + custom_field.enumerations.active + end + + def value_from_keyword(custom_field, keyword, object) + value = custom_field.enumerations.where("LOWER(name) LIKE LOWER(?)", keyword) + value ? value.id : nil + end + end + class UserFormat < RecordList add 'user' self.form_partial = 'custom_fields/formats/user' |