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