@@ -5,12 +5,12 | |||
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 |
# |
|
|
8 | # | |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 |
# |
|
|
13 | # | |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
@@ -42,12 +42,12 module Redmine | |||
|
42 | 42 | def self.included(base) |
|
43 | 43 | base.extend ClassMethods |
|
44 | 44 | end |
|
45 | ||
|
45 | ||
|
46 | 46 | def available_custom_fields |
|
47 | 47 | CustomField.find(:all, :conditions => "type = '#{self.class.name}CustomField'", |
|
48 | 48 | :order => 'position') |
|
49 | 49 | end |
|
50 | ||
|
50 | ||
|
51 | 51 | # Sets the values of the object's custom fields |
|
52 | 52 | # values is an array like [{'id' => 1, 'value' => 'foo'}, {'id' => 2, 'value' => 'bar'}] |
|
53 | 53 | def custom_fields=(values) |
@@ -65,7 +65,7 module Redmine | |||
|
65 | 65 | # values is a hash like {'1' => 'foo', 2 => 'bar'} |
|
66 | 66 | def custom_field_values=(values) |
|
67 | 67 | values = values.stringify_keys |
|
68 | ||
|
68 | ||
|
69 | 69 | custom_field_values.each do |custom_field_value| |
|
70 | 70 | key = custom_field_value.custom_field_id.to_s |
|
71 | 71 | if values.has_key?(key) |
@@ -81,7 +81,7 module Redmine | |||
|
81 | 81 | end |
|
82 | 82 | @custom_field_values_changed = true |
|
83 | 83 | end |
|
84 | ||
|
84 | ||
|
85 | 85 | def custom_field_values |
|
86 | 86 | @custom_field_values ||= available_custom_fields.collect do |field| |
|
87 | 87 | x = CustomFieldValue.new |
@@ -101,31 +101,31 module Redmine | |||
|
101 | 101 | x |
|
102 | 102 | end |
|
103 | 103 | end |
|
104 | ||
|
104 | ||
|
105 | 105 | def visible_custom_field_values |
|
106 | 106 | custom_field_values.select(&:visible?) |
|
107 | 107 | end |
|
108 | ||
|
108 | ||
|
109 | 109 | def custom_field_values_changed? |
|
110 | 110 | @custom_field_values_changed == true |
|
111 | 111 | end |
|
112 | ||
|
112 | ||
|
113 | 113 | def custom_value_for(c) |
|
114 | 114 | field_id = (c.is_a?(CustomField) ? c.id : c.to_i) |
|
115 | 115 | custom_values.detect {|v| v.custom_field_id == field_id } |
|
116 | 116 | end |
|
117 | ||
|
117 | ||
|
118 | 118 | def custom_field_value(c) |
|
119 | 119 | field_id = (c.is_a?(CustomField) ? c.id : c.to_i) |
|
120 | 120 | custom_field_values.detect {|v| v.custom_field_id == field_id }.try(:value) |
|
121 | 121 | end |
|
122 | ||
|
122 | ||
|
123 | 123 | def validate_custom_field_values |
|
124 | 124 | if new_record? || custom_field_values_changed? |
|
125 | 125 | custom_field_values.each(&:validate_value) |
|
126 | 126 | end |
|
127 | 127 | end |
|
128 | ||
|
128 | ||
|
129 | 129 | def save_custom_field_values |
|
130 | 130 | target_custom_values = [] |
|
131 | 131 | custom_field_values.each do |custom_field_value| |
@@ -147,12 +147,12 module Redmine | |||
|
147 | 147 | @custom_field_values_changed = false |
|
148 | 148 | true |
|
149 | 149 | end |
|
150 | ||
|
150 | ||
|
151 | 151 | def reset_custom_values! |
|
152 | 152 | @custom_field_values = nil |
|
153 | 153 | @custom_field_values_changed = true |
|
154 | 154 | end |
|
155 | ||
|
155 | ||
|
156 | 156 | module ClassMethods |
|
157 | 157 | end |
|
158 | 158 | end |
General Comments 0
You need to be logged in to leave comments.
Login now