diff options
| author | Xinhui | 2017-10-06 12:03:24 +0200 | 
|---|---|---|
| committer | Xinhui | 2017-10-06 12:03:24 +0200 | 
| commit | dbbd6869db784136c0a9017b6754a44ccacc719b (patch) | |
| tree | 779e3c5fe4bed9cc89553c9320fb3bfb00685b9f | |
| parent | 5005fd84579355bfb490203926f68275c21a92af (diff) | |
| download | chouette-core-dbbd6869db784136c0a9017b6754a44ccacc719b.tar.bz2 | |
ComplianceControl#new target field
Refs #4687
| -rw-r--r-- | app/views/compliance_controls/_form.html.slim | 6 | ||||
| -rw-r--r-- | lib/model_attribute.rb | 14 | 
2 files changed, 18 insertions, 2 deletions
| diff --git a/app/views/compliance_controls/_form.html.slim b/app/views/compliance_controls/_form.html.slim index 1e56a63b9..088532447 100644 --- a/app/views/compliance_controls/_form.html.slim +++ b/app/views/compliance_controls/_form.html.slim @@ -7,9 +7,11 @@        = f.input :criticity        = f.association :compliance_control_block, collection: @compliance_control_set.compliance_control_blocks, label_method: :label_method        = f.input :comment -        - f.object.class.dynamic_attributes.each do |attribute| -        = f.input attribute.to_sym +        - if attribute == :target +          = f.input :target, as: :grouped_select, collection: ModelAttribute.grouped_options(@compliance_control.class.attribute_type), :group_method => :last +        - else +          = f.input attribute.to_sym        end    .separator diff --git a/lib/model_attribute.rb b/lib/model_attribute.rb index 4d246853a..33f6c80aa 100644 --- a/lib/model_attribute.rb +++ b/lib/model_attribute.rb @@ -5,6 +5,20 @@ class ModelAttribute      @__all__ ||= []    end +  def self.grouped_options(type) +    {}.tap do |el| +      group_by_class.each do |key, values| +        values.reject!{ |x| x.data_type != type } +        el[I18n.t("activerecord.models.#{key}.one")] = values.map do |i| +          [ +            I18n.t("activerecord.attributes.#{i.klass}.#{i.name}"), +            "#{i.klass}.#{i.name}" +          ] +        end +      end +    end +  end +    def self.define(klass, name, data_type)      all << new(klass, name, data_type)    end | 
