Orbit/app/helpers/admin/item_helper.rb

45 lines
1.5 KiB
Ruby

module Admin::ItemHelper
def render_node_and_children(node)
ret = ''
if node
case node._type
when 'Page'
dest = admin_page_path(node)
when 'Link'
dest = admin_link_path(node)
no_nested = 'no-nest'
end
ret << "<li id='#{node.id}' class='#{no_nested}'>"
ret << "<div class='with_action'>"
ret << (link_to node.i18n_variable[I18n.locale], dest)
ret << "<div class='quick-edit hide'>"
ret << (link_to t('admin.edit'), eval("edit_admin_#{node._type.downcase}_path(node)")) if node._type.eql?('Page')
ret << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id), :class => 'new_page') if node._type.eql?('Page')
ret << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id), :class => 'new_link') if node._type.eql?('Page')
ret << (link_to t(:delete), eval("delete_admin_#{node._type.downcase}_path(node, :authenticity_token => form_authenticity_token)"), :confirm => t('sure?'), :class => 'delete')
ret << "</div>"
ret << "</div>"
ret << render_children(node)
ret << "</li>"
end
ret.html_safe
end
def render_children(parent)
children = parent.children
if !parent.children.entries.blank?
ret = ''
ret << "<ol class='#{'sortable' if parent.parent.nil?}'>"
children.each do |child|
ret << render_node_and_children(child)
end
ret << '</ol>'
ret
else
''
end
end
end