Module: Redmine::Acts::Customizable::InstanceMethods

Defined in:
vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary

Instance Method Summary

Class Method Details

+ (Object) included(base)



44
45
46
# File 'vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb', line 44

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

- (Object) available_custom_fields



48
49
50
51
# File 'vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb', line 48

def available_custom_fields
  CustomField.find(:all, :conditions => "type = '#{self.class.name}CustomField'",
                         :order => 'position')
end

- (Object) custom_field_values



61
62
63
# File 'vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb', line 61

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) }
end

- (Object) custom_field_values=(values)



53
54
55
56
57
58
59
# File 'vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb', line 53

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)
end

- (Boolean) custom_field_values_changed?

Returns:

  • (Boolean)


65
66
67
# File 'vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb', line 65

def custom_field_values_changed?
  @custom_field_values_changed == true
end

- (Object) custom_value_for(c)



69
70
71
72
# File 'vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb', line 69

def custom_value_for(c)
  field_id = (c.is_a?(CustomField) ? c.id : c.to_i)
  custom_values.detect {|v| v.custom_field_id == field_id }
end

- (Object) reset_custom_values!



80
81
82
83
84
85
# File 'vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb', line 80

def reset_custom_values!
  @custom_field_values = nil
  @custom_field_values_changed = true
  values = custom_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
  custom_values.each {|cv| cv.destroy unless custom_field_values.include?(cv)}
end

- (Object) save_custom_field_values



74
75
76
77
78
# File 'vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb', line 74

def save_custom_field_values
  custom_field_values.each(&:save)
  @custom_field_values_changed = false
  @custom_field_values = nil
end