% config = field.associated_model_config source_abstract_model = RailsAdmin.config(form.object.class).abstract_model selected = form.object.send(field.name) 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 js_data = { xhr: xhr, :'edit-url' => (field.inline_edit && authorized?(:edit, config.abstract_model) ? edit_path(model_name: config.abstract_model.to_param, id: '__ID__') : ''), remote_source: index_path(config.abstract_model, source_object_id: form.object.id, source_abstract_model: source_abstract_model.to_param, associated_collection: field.name, current_action: current_action, compact: true), sortable: !!field.orderable, removable: !!field.removable, cacheAll: !!field.associated_collection_cache_all, regional: { add: t('admin.misc.add_new'), chooseAll: t('admin.misc.chose_all'), clearAll: t('admin.misc.clear_all'), down: t('admin.misc.down'), remove: t('admin.misc.remove'), search: t('admin.misc.search'), up: t('admin.misc.up') } } %>