diff vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb @ 524:1248a47e81b3 feature_36

Merge from branch "luisf"
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 25 Jul 2011 14:39:38 +0100
parents cbce1fd3b1b7
children cbb26bc654de
line wrap: on
line diff
--- a/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb	Fri Jul 15 17:21:05 2011 +0100
+++ b/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb	Mon Jul 25 14:39:38 2011 +0100
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006-2008  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
@@ -50,16 +50,32 @@
                                  :order => 'position')
         end
         
+        # Sets the values of the object's custom fields
+        # values is an array like [{'id' => 1, 'value' => 'foo'}, {'id' => 2, 'value' => 'bar'}]
+        def custom_fields=(values)
+          values_to_hash = values.inject({}) do |hash, v|
+            v = v.stringify_keys
+            if v['id'] && v.has_key?('value')
+              hash[v['id']] = v['value']
+            end
+            hash
+          end
+          self.custom_field_values = values_to_hash
+        end
+
+        # Sets the values of the object's custom fields
+        # values is a hash like {'1' => 'foo', 2 => 'bar'}
         def custom_field_values=(values)
           @custom_field_values_changed = true
           values = values.stringify_keys
           custom_field_values.each do |custom_value|
             custom_value.value = values[custom_value.custom_field_id.to_s] if values.has_key?(custom_value.custom_field_id.to_s)
           end if values.is_a?(Hash)
+          self.custom_values = custom_field_values
         end
         
         def custom_field_values
-          @custom_field_values ||= available_custom_fields.collect { |x| custom_values.detect { |v| v.custom_field == x } || custom_values.build(:custom_field => x, :value => nil) }
+          @custom_field_values ||= available_custom_fields.collect { |x| custom_values.detect { |v| v.custom_field == x } || custom_values.build(:customized => self, :custom_field => x, :value => nil) }
         end
         
         def visible_custom_field_values