Sha256: 57c7fd5d7c6820862cbbe06df56c5cb25d0e3e14ea3584b09dd24e9961a2fee8

Contents?: true

Size: 947 Bytes

Versions: 1

Compression:

Stored size: 947 Bytes

Contents

module Admin::Resources::FiltersHelper

  def build_filters(resource = @resource, params = params())
    if (typus_filters = resource.typus_filters).any?
      locals = {}

      locals[:filters] = typus_filters.map do |key, value|
                           { :key => set_filter(key, value),
                             :value => send("#{value}_filter", key) }
                         end

      rejections = %w(controller action locale utf8 sort_order order_by) + locals[:filters].map { |f| f[:key] }
      locals[:hidden_filters] = params.dup.delete_if { |k, v| rejections.include?(k) }

      render "helpers/admin/resources/filters", locals
    end
  end

  def set_filter(key, value)
    return key unless value == :belongs_to

    att_assoc = @resource.reflect_on_association(key.to_sym)
    class_name = att_assoc.options[:class_name] || key.capitalize.camelize
    resource = class_name.constantize
    att_assoc.foreign_key
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
brainsome_typus-4.0.0.beta10 app/helpers/admin/resources/filters_helper.rb