Sha256: dc77b6d4e6423142f0d8c89e7bf044dce94efb2110eabfe6391c6dfa3a3e4b31

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

class Lolita::FieldDataController < ApplicationController
  include Lolita::Controllers::UserHelpers

  before_filter :authenticate_lolita_user!
  before_filter :find_field, :except => [:autocomplete_field]

  def array_polymorphic
    klass = params[:class].camelize.constantize
    data_collection = @field.polymorphic_association_values(:klass => klass)
    @id = params[:id].to_s.to_i
    @collection = [[]]+data_collection
    render_component(*@field.build(:state => :options_for_select, :collection => @collection, :id => @id))
  end

  def find_field
    @field = params[:field_class].camelize.constantize.lolita.tabs.fields.detect{|field|
      field.name.to_s == params[:name].to_s
    }
  end

	def autocomplete_field
    klass = params[:field_class].camelize.constantize
    field = klass.lolita.tabs.fields.detect{|field| field.name.to_s == params[:field_name]}
    data = if field
      (field.search || field.create_search(true)).run(params[:term],request).map do |record|
        {
          :id => record.id,
          :value => record.send(field.current_text_method(field.association.klass)),
          :name => "#{params[:field_class].downcase}[#{params[:field_name].singularize}_ids][]",
          :delete_link => I18n.t("lolita.shared.delete").to_s.downcase
        }
      end
    end
    render :json => data || {}
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lolita-3.2.0.rc.7 app/controllers/lolita/field_data_controller.rb