diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-04-01 13:44:58 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-04-01 13:44:58 +0000 |
commit | 1cd6a2aa84db83b127cc037021dc6351877790d0 (patch) | |
tree | ae3eaa0a3f6d15c62771db779f19f15fce4b1d87 /lib/redmine/custom_field_format.rb | |
parent | 122ba564b9c5c475c360e45af51fa92cfe969657 (diff) | |
download | redmine-1cd6a2aa84db83b127cc037021dc6351877790d0.tar.gz redmine-1cd6a2aa84db83b127cc037021dc6351877790d0.zip |
Adds User and Version custom field format that can be used to reference a project member or version in custom fields (#2096).
These new field formats are available for project, issue, version and time entry custom fields.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5272 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/custom_field_format.rb')
-rw-r--r-- | lib/redmine/custom_field_format.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/redmine/custom_field_format.rb b/lib/redmine/custom_field_format.rb index 2f12397d5..7c6364f7a 100644 --- a/lib/redmine/custom_field_format.rb +++ b/lib/redmine/custom_field_format.rb @@ -22,12 +22,14 @@ module Redmine cattr_accessor :available @@available = {} - attr_accessor :name, :order, :label + attr_accessor :name, :order, :label, :edit_as, :class_names def initialize(name, options={}) self.name = name self.label = options[:label] self.order = options[:order] + self.edit_as = options[:edit_as] || name + self.class_names = options[:only] end def format(value) @@ -47,12 +49,11 @@ module Redmine return value } end - - # Allow displaying the edit type of another field_format - # - # Example: display a custom field as a list - def edit_as - name + + ['user', 'version'].each do |name| + define_method("format_as_#{name}") {|value| + return value.blank? ? "" : name.classify.constantize.find_by_id(value.to_i).to_s + } end class << self @@ -79,8 +80,10 @@ module Redmine end # Return an array of custom field formats which can be used in select_tag - def as_select - @@available.values.sort {|a,b| + def as_select(class_name=nil) + fields = @@available.values + fields = fields.select {|field| field.class_names.nil? || field.class_names.include?(class_name)} + fields.sort {|a,b| a.order <=> b.order }.collect {|custom_field_format| [ l(custom_field_format.label), custom_field_format.name ] |