summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-04-01 13:44:58 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-04-01 13:44:58 +0000
commit1cd6a2aa84db83b127cc037021dc6351877790d0 (patch)
treeae3eaa0a3f6d15c62771db779f19f15fce4b1d87 /lib
parent122ba564b9c5c475c360e45af51fa92cfe969657 (diff)
downloadredmine-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')
-rw-r--r--lib/redmine.rb2
-rw-r--r--lib/redmine/custom_field_format.rb21
2 files changed, 14 insertions, 9 deletions
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 87efc72ea..631f10946 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -41,6 +41,8 @@ Redmine::CustomFieldFormat.map do |fields|
fields.register Redmine::CustomFieldFormat.new('list', :label => :label_list, :order => 5)
fields.register Redmine::CustomFieldFormat.new('date', :label => :label_date, :order => 6)
fields.register Redmine::CustomFieldFormat.new('bool', :label => :label_boolean, :order => 7)
+ fields.register Redmine::CustomFieldFormat.new('user', :label => :label_user, :only => %w(Issue TimeEntry Version Project), :edit_as => 'list', :order => 8)
+ fields.register Redmine::CustomFieldFormat.new('version', :label => :label_version, :only => %w(Issue TimeEntry Version Project), :edit_as => 'list', :order => 9)
end
# Permissions
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 ]