elasticsearch_plugin_helper.rb
960 Bytes
module ElasticsearchPluginHelper
def render_categories(collection, selected_collections)
content_tag :ul, class: "category-ident" do
if collection.respond_to? :each
collection.collect do |item|
concat ("<li>".html_safe)
concat (check_box_tag(item.name, item.id, selected_collections.include?(item.id.to_s)) )
concat (label_tag item.name)
concat (render_categories(item.children, selected_collections)) if item.children_count > 0
concat ("</li>".html_safe)
end
else
check_box_tag collection.name, collection.id, selected_collections.include?(collection.id)
label_tag collection.name
end
end
end
def categories_data(collection)
result = []
collection.each do | item |
result.push({ text: item.name, id: item.id })
result.last[:children] = categories_data(item.children) if item.children_count > 0
end
result
end
end