Sha256: d328ba1040a44d9145bd557c3073162dda7f39bdb5418a2f1bcc857a3d24dfd9

Contents?: true

Size: 1.5 KB

Versions: 12

Compression:

Stored size: 1.5 KB

Contents

require 'rails_admin/config/fields/association'

module RailsAdmin
  module Config
    module Fields
      module Types
        class BelongsToAssociation < RailsAdmin::Config::Fields::Association
          RailsAdmin::Config::Fields::Types::register(self)

          register_instance_option :formatted_value do
            (o = value) && o.send(associated_model_config.object_label_method)
          end

          register_instance_option :sortable do
            @sortable ||= associated_model_config.abstract_model.properties.map{ |p| p[:name] }.include?(associated_model_config.object_label_method) ? associated_model_config.object_label_method : {self.abstract_model.table_name => self.method_name}
          end

          register_instance_option :searchable do
            @searchable ||= associated_model_config.abstract_model.properties.map{ |p| p[:name] }.include?(associated_model_config.object_label_method) ? [associated_model_config.object_label_method, {self.abstract_model.model => self.method_name}] : {self.abstract_model.model => self.method_name}
          end

          register_instance_option :partial do
            nested_form ? :form_nested_one : :form_filtering_select
          end

          def selected_id
            bindings[:object].send(foreign_key)
          end

          def method_name
            nested_form ? "#{self.name}_attributes" : association[:foreign_key]
          end
          
          def multiple?
            false
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
rails_admin-0.1.2 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.1.1 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.1.0 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.0.5 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.0.4 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.0.3 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.0.2 lib/rails_admin/config/fields/types/belongs_to_association.rb
upstream-rails_admin-1.0.2 lib/rails_admin/config/fields/types/belongs_to_association.rb
rails_admin-0.0.1 lib/rails_admin/config/fields/types/belongs_to_association.rb
obitum-rails_admin-0.0.5 lib/rails_admin/config/fields/types/belongs_to_association.rb
drewda_rails_admin-0.0.1 lib/rails_admin/config/fields/types/belongs_to_association.rb
obitum-rails_admin-0.0.4 lib/rails_admin/config/fields/types/belongs_to_association.rb