app/helpers/tree_structure_helper.rb
def format_tree(node_key, node_value)
    tree = {
      id: node_key.id,
      name: node_key.name,
      parent_id: node_key.parent_id,
      position: node_key.position,
      enabled: node_key.enabled,
      content_type: node_key.content_type,
      show_on_menu: node_key.show_on_menu,
      disableable: node_key.disableable?,
      deletable: node_key.deletable?,
      deleteUrl:
        if node_key.deletable?
          management_site_site_page_path(@site.slug, node_key.id)
        else
          nil
        end,
      editUrl: edit_management_site_site_page_page_step_path(@site.slug, node_key.id, 'position')
    }
    unless node_value.blank?
      children = []
      node_value.each do |key, value|
        children << format_tree(key,value)
      end
      tree.merge!({children: children})
    end
    return tree
  end
# Formats the tree to send it to Backbone through gon
Formats the tree to send it to Backbone through gon
Formats the tree to send it to Backbone through gon
def format_tree(node_key, node_value)
    tree = {
      id: node_key.id,
      name: node_key.name,
      parent_id: node_key.parent_id,
      position: node_key.position,
      enabled: node_key.enabled,
      content_type: node_key.content_type,
      show_on_menu: node_key.show_on_menu,
      disableable: node_key.disableable?,
      deletable: node_key.deletable?,
      deleteUrl:
        if node_key.deletable?
          management_site_site_page_path(@site.slug, node_key.id)
        else
          nil
        end,
      editUrl: edit_management_site_site_page_page_step_path(@site.slug, node_key.id, 'position')
    }
    unless node_value.blank?
      children = []
      node_value.each do |key, value|
        children << format_tree(key,value)
      end
      tree.merge!({children: children})
    end
    return tree
  end
def format_tree ( node_key , node_value ) tree = { id : node_key . id , name : node_key . name , parent_id : node_key . parent_id , position : node_key . position , enabled : node_key . enabled , content_type : node_key . content_type , show_on_menu : node_key . show_on_menu , disableable : node_key . disableable? , deletable : node_key . deletable? , deleteUrl : if node_key . deletable? management_site_site_page_path ( @site . slug , node_key . id ) else nil end , editUrl : edit_management_site_site_page_page_step_path ( @site . slug , node_key . id , 'position' ) } unless node_value . blank? children = [ ] node_value . each do | key , value | children << format_tree ( key , value ) end tree . merge! ( { children : children } ) end return tree end
Formats the tree to send it to Backbone through gon
Formats the tree to send it to Backbone through gon
node_key
node_value