Sha256: 2a97ea418ae27479c4cc2afa53f27628d3584acb11e31d28e32d4413b0c080a1

Contents?: true

Size: 1.57 KB

Versions: 11

Compression:

Stored size: 1.57 KB

Contents

:ruby
  type_collection = field.polymorphic_type_collection
  type_column = field.association.foreign_type.to_s
  selected_type = field.bindings[:object].send(type_column)
  selected = field.bindings[:object].send(field.association.name)
  collection = selected ? [[field.formatted_value, selected.id]] : [[]]
  column_type_dom_id = form.dom_id(field).sub(field.method_name.to_s, type_column)
  current_action = params[:action].in?(['create', 'new']) ? 'create' : 'update'

  default_options = { float_left: false }

  js_data = type_collection.inject({}) do |options, model|
    model_name = model.second.underscore.downcase
    source_abstract_model = RailsAdmin.config(form.object.class).abstract_model
    options.merge(model_name.gsub("_", "") => {
      xhr: true,
      remote_source: index_path(model_name, source_object_id: form.object.id, source_abstract_model: source_abstract_model.to_param, current_action: current_action, compact: true),
      float_left: false
    })
  end

.form-inline
  - js_data.each do |model, value|
    %div{id: "#{model}-js-options", data: { options: value.to_json } }
  = form.select type_column, type_collection, {include_blank: true, selected: selected_type}, class: "form-control", id: column_type_dom_id, data: { polymorphic: true, urls: field.polymorphic_type_urls.to_json }, style: "float: left; margin-right: 10px;"
  = form.select field.method_name, collection, {include_blank: true, selected: selected.try(:id)}, class: "form-control", data: { filteringselect: true, options: js_data[selected_type.try(:downcase)] || default_options }, placeholder: 'Search'

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rails_admin-2.3.1 app/views/rails_admin/main/_form_polymorphic_association.html.haml
rails_admin-2.3.0 app/views/rails_admin/main/_form_polymorphic_association.html.haml
rails_admin-2.2.1 app/views/rails_admin/main/_form_polymorphic_association.html.haml
rails_admin-2.2.0 app/views/rails_admin/main/_form_polymorphic_association.html.haml
rails_admin-2.1.1 app/views/rails_admin/main/_form_polymorphic_association.html.haml
rails_admin-2.1.0 app/views/rails_admin/main/_form_polymorphic_association.html.haml
rails_admin-2.0.2 app/views/rails_admin/main/_form_polymorphic_association.html.haml
rails_admin-2.0.1 app/views/rails_admin/main/_form_polymorphic_association.html.haml
rails_admin-2.0.0 app/views/rails_admin/main/_form_polymorphic_association.html.haml
rails_admin-2.0.0.rc app/views/rails_admin/main/_form_polymorphic_association.html.haml
rails_admin-2.0.0.beta app/views/rails_admin/main/_form_polymorphic_association.html.haml