Sha256: c34d4a5737e7d782cd5fc4f2c6d1d8e7168d0266457204c7139ebc0fde00b745

Contents?: true

Size: 1.27 KB

Versions: 15

Compression:

Stored size: 1.27 KB

Contents

- if params[:associations].nil?
  = render 'rails_admin/main/enum_check_boxes', field: field, form: form
- else
  :ruby
    related_id = params[:associations] && params[:associations][field.name.to_s]
    config = field.associated_model_config
    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)]
    else
      selected = form.object.send(field.name)
    end
    selected_ids = selected.map{|s| s.send(field.associated_primary_key)}

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

    xhr = !field.associated_collection_cache_all

    collection = if xhr
      selected.map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }
    else
      i = 0
      controller.list_entries(config, :index, field.associated_collection_scope, false).map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }.sort_by {|a| [selected_ids.index(a[1]) || selected_ids.size, i+=1] }
    end

  = form.collection_check_boxes(field.method_name, collection, :last, :first, {}, {}) { |i| i.label( class: 'checkbox' ) { i.check_box + i.text } }

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rocket_cms-0.37.1 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.37.0 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.36.0 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.35.0 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.34.0 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.33.1 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.33.0 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.32.0 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.31.1 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.31.0 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.30.0 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.29.0 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.28.0 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.27.8 app/views/rails_admin/main/_check_boxes.html.haml
rocket_cms-0.27.7 app/views/rails_admin/main/_check_boxes.html.haml