Sha256: ea7334388bfad971700cbc8e97ef58755458a4639aac010079c221f4bf6af606

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

:ruby
  config = field.associated_model_config
  related_id = params[:associations] && params[:associations][field.name.to_s]
  source_abstract_model = RailsAdmin.config(form.object.class).abstract_model
  
  if form.object.new_record? && related_id.present? && related_id != 'new'
    selected = config.abstract_model.get(related_id)
    selected_id = selected.id
    selected_name = selected.send(config.object_label_method)
  else
    selected_id = field.selected_id
    selected_name = field.formatted_value
  end

  current_action = params[:action].in?(['create', 'new']) ? 'create' : 'update'

  edit_url = authorized?(:edit, config.abstract_model) ? edit_path(:model_name => config.abstract_model.to_param, :modal => true, :id => '__ID__') : ''
  
  xhr = !field.associated_collection_cache_all

  collection = xhr ? [[selected_name, selected_id]] : controller.list_entries(config, :index, field.associated_collection_scope, false).map { |o| [o.send(config.object_label_method), o.id] }

= form.select field.method_name, collection, { :selected => selected_id, :include_blank => true }, field._html_attributes.reverse_merge({:placeholder => t('admin.index.search')})

= form.javascript_for(field) do
  :plain
    $("#{form.jquery_namespace(field)} select").filteringSelect({
      xhr: #{xhr},
      createQuery: function(query) {
        return { query: query }
      },
      remote_source: "#{index_path(config.abstract_model.to_param, :source_object_id => form.object.id, :source_abstract_model => source_abstract_model.to_param, :associated_collection => field.name, :current_action => current_action, :compact => true).html_safe}"
    });
    if($("#modal").length) { // hide link if we already are inside a dialog (endless issues on nested dialogs with JS)
      $("#{form.jquery_namespace(field)} .btn").hide();
    } else {
      $("#{form.jquery_namespace(field)}").remoteForm();
    }

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
piggybak-0.3.1 app/views/rails_admin/main/_no_edit_form_filtering_select.html.haml
piggybak-0.3.0 app/views/rails_admin/main/_no_edit_form_filtering_select.html.haml