comparison app/models/custom_field.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 8661b858af72
children cbb26bc654de
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
46 v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil) 46 v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil)
47 v.custom_field.is_required = false 47 v.custom_field.is_required = false
48 errors.add(:default_value, :invalid) unless v.valid? 48 errors.add(:default_value, :invalid) unless v.valid?
49 end 49 end
50 50
51 def possible_values_options(obj=nil)
52 case field_format
53 when 'user', 'version'
54 if obj.respond_to?(:project) && obj.project
55 case field_format
56 when 'user'
57 obj.project.users.sort.collect {|u| [u.to_s, u.id.to_s]}
58 when 'version'
59 obj.project.versions.sort.collect {|u| [u.to_s, u.id.to_s]}
60 end
61 elsif obj.is_a?(Array)
62 obj.collect {|o| possible_values_options(o)}.inject {|memo, v| memo & v}
63 else
64 []
65 end
66 else
67 read_attribute :possible_values
68 end
69 end
70
71 def possible_values(obj=nil)
72 case field_format
73 when 'user', 'version'
74 possible_values_options(obj).collect(&:last)
75 else
76 read_attribute :possible_values
77 end
78 end
79
51 # Makes possible_values accept a multiline string 80 # Makes possible_values accept a multiline string
52 def possible_values=(arg) 81 def possible_values=(arg)
53 if arg.is_a?(Array) 82 if arg.is_a?(Array)
54 write_attribute(:possible_values, arg.compact.collect(&:strip).select {|v| !v.blank?}) 83 write_attribute(:possible_values, arg.compact.collect(&:strip).select {|v| !v.blank?})
55 else 84 else
69 casted = (value == '1' ? true : false) 98 casted = (value == '1' ? true : false)
70 when 'int' 99 when 'int'
71 casted = value.to_i 100 casted = value.to_i
72 when 'float' 101 when 'float'
73 casted = value.to_f 102 casted = value.to_f
103 when 'user', 'version'
104 casted = (value.blank? ? nil : field_format.classify.constantize.find_by_id(value.to_i))
74 end 105 end
75 end 106 end
76 casted 107 casted
77 end 108 end
78 109