Skip to content

Commit

Permalink
Always open tree view treeview helper option.
Browse files Browse the repository at this point in the history
  • Loading branch information
oruen committed Jun 27, 2011
1 parent 4bfc0c0 commit 1d84761
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/helpers/typus_treeview_helper.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
module TypusTreeviewHelper
def treeview
def treeview open = false
model = @object_name.classify.constantize
if model.respond_to?(:roots) && method = Typus.treeview[@object_name.to_sym]
res = ''
res << javascript_include_tag("jquery.treeview")
res << stylesheet_link_tag("jquery.treeview")
res << (content_tag :ul, :id => "treeview" do
model.roots.map do |root|
treeview_draw(root, method)
treeview_draw(root, method, open)
end.join.html_safe
end)
res << javascript_tag('$(document).ready(function(){$("#treeview").treeview({persist: "location"});});')
res.html_safe
end
end

def treeview_draw node, method
content_tag :li, :class => "closed" do
def treeview_draw node, method, open
content_tag :li, :class => open ? nil : "closed" do
res = ''
name = method.is_a?(Proc) ? method.call(node) : node.send(method)
res << content_tag(:span, link_to(name, { :action => "edit",
Expand All @@ -27,7 +27,7 @@ def treeview_draw node, method
if node.children.size > 0
res << (content_tag :ul do
node.children.map do |child|
treeview_draw(child, method)
treeview_draw(child, method, open)
end.join.html_safe
end)
end
Expand Down

0 comments on commit 1d84761

Please sign in to comment.