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