Mercurial > hg > soundsoftware-site
diff app/models/custom_field.rb @ 514:7eba09d624db live
Merge
author | Chris Cannam |
---|---|
date | Thu, 14 Jul 2011 10:50:53 +0100 |
parents | cbce1fd3b1b7 |
children | cbb26bc654de |
line wrap: on
line diff
--- a/app/models/custom_field.rb Thu Jul 14 10:46:20 2011 +0100 +++ b/app/models/custom_field.rb Thu Jul 14 10:50:53 2011 +0100 @@ -1,5 +1,5 @@ -# redMine - project management software -# Copyright (C) 2006 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2011 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -23,7 +23,6 @@ validates_presence_of :name, :field_format validates_uniqueness_of :name, :scope => :type validates_length_of :name, :maximum => 30 - validates_format_of :name, :with => /^[\w\s\.\'\-]*$/i validates_inclusion_of :field_format, :in => Redmine::CustomFieldFormat.available_formats def initialize(attributes = nil) @@ -49,6 +48,35 @@ errors.add(:default_value, :invalid) unless v.valid? end + def possible_values_options(obj=nil) + case field_format + when 'user', 'version' + if obj.respond_to?(:project) && obj.project + case field_format + when 'user' + obj.project.users.sort.collect {|u| [u.to_s, u.id.to_s]} + when 'version' + obj.project.versions.sort.collect {|u| [u.to_s, u.id.to_s]} + end + elsif obj.is_a?(Array) + obj.collect {|o| possible_values_options(o)}.inject {|memo, v| memo & v} + else + [] + end + else + read_attribute :possible_values + end + end + + def possible_values(obj=nil) + case field_format + when 'user', 'version' + possible_values_options(obj).collect(&:last) + else + read_attribute :possible_values + end + end + # Makes possible_values accept a multiline string def possible_values=(arg) if arg.is_a?(Array) @@ -72,6 +100,8 @@ casted = value.to_i when 'float' casted = value.to_f + when 'user', 'version' + casted = (value.blank? ? nil : field_format.classify.constantize.find_by_id(value.to_i)) end end casted