Sha256: 8aa4a4391e260b53a9aa820a622d42f89c8dde4f7387c270d3402e1031c00c98

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

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

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

  def array_polymorphic
    klass = params[:class].camelize.constantize
    authorization_proxy.authorize!(:read,klass)
    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 autocomplete_field
    klass = params[:field_class].camelize.constantize
    authorization_proxy.authorize!(:read,klass)
    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].underscore}[#{params[:field_name].singularize}_ids][]",
          :delete_link => I18n.t("lolita.shared.delete").to_s.downcase
        }
      end
    end
    render :json => data || {}
	end

  private

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

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
lolita-3.3.7 app/controllers/lolita/field_data_controller.rb~
lolita-3.3.6 app/controllers/lolita/field_data_controller.rb
lolita-3.3.5 app/controllers/lolita/field_data_controller.rb
lolita-3.3.4 app/controllers/lolita/field_data_controller.rb
lolita-3.3.3 app/controllers/lolita/field_data_controller.rb
lolita-3.3.2 app/controllers/lolita/field_data_controller.rb
lolita-3.3.1 app/controllers/lolita/field_data_controller.rb
lolita-3.3.0 app/controllers/lolita/field_data_controller.rb
lolita-3.2.1 app/controllers/lolita/field_data_controller.rb
lolita-3.2.0.rc.17 app/controllers/lolita/field_data_controller.rb
lolita-3.2.0.rc.16 app/controllers/lolita/field_data_controller.rb
lolita-3.2.0.rc.14 app/controllers/lolita/field_data_controller.rb
lolita-3.2.0.rc.13 app/controllers/lolita/field_data_controller.rb
lolita-3.2.0.rc.12 app/controllers/lolita/field_data_controller.rb
lolita-3.2.0.rc.11 app/controllers/lolita/field_data_controller.rb
lolita-3.2.0.rc.10 app/controllers/lolita/field_data_controller.rb
lolita-3.2.0.rc.9 app/controllers/lolita/field_data_controller.rb