Merge pull request #308 from barriault/master
Remove direction select control from sort_select form builder
This commit is contained in:
commit
af8895cab6
|
@ -36,6 +36,11 @@ module Ransack
|
|||
end
|
||||
|
||||
def sort_select(options = {}, html_options = {})
|
||||
sort_attribute_select(options, html_options) +
|
||||
sort_direction_select(options, html_options)
|
||||
end
|
||||
|
||||
def sort_attribute_select(options = {}, html_options = {})
|
||||
raise ArgumentError, "sort_select must be called inside a search FormBuilder!" unless object.respond_to?(:context)
|
||||
options[:include_blank] = true unless options.has_key?(:include_blank)
|
||||
bases = [''] + association_array(options[:associations])
|
||||
|
@ -43,16 +48,27 @@ module Ransack
|
|||
@template.grouped_collection_select(
|
||||
@object_name, :name, sortable_attribute_collection_for_bases(bases), :last, :first, :first, :last,
|
||||
objectify_options(options), @default_options.merge(html_options)
|
||||
) + @template.collection_select(
|
||||
@object_name, :dir, [['asc', object.translate('asc')], ['desc', object.translate('desc')]], :first, :last,
|
||||
objectify_options(options), @default_options.merge(html_options)
|
||||
)
|
||||
else
|
||||
collection = sortable_attribute_collection_for_base(bases.first)
|
||||
@template.collection_select(
|
||||
@object_name, :name, collection, :first, :last,
|
||||
objectify_options(options), @default_options.merge(html_options)
|
||||
) + @template.collection_select(
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def sort_direction_select(options = {}, html_options = {})
|
||||
raise ArgumentError, "sort_direction must be called inside a search FormBuilder!" unless object.respond_to?(:context)
|
||||
bases = [''] + association_array(options[:associations])
|
||||
if bases.size > 1
|
||||
@template.collection_select(
|
||||
@object_name, :dir, [['asc', object.translate('asc')], ['desc', object.translate('desc')]], :first, :last,
|
||||
objectify_options(options), @default_options.merge(html_options)
|
||||
)
|
||||
else
|
||||
collection = sortable_attribute_collection_for_base(bases.first)
|
||||
@template.collection_select(
|
||||
@object_name, :dir, [['asc', object.translate('asc')], ['desc', object.translate('desc')]], :first, :last,
|
||||
objectify_options(options), @default_options.merge(html_options)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue