Module: Admin::NodeHelper

Included in:
PagesHelper
Defined in:
app/helpers/admin/node_helper.rb

Instance Method Summary collapse

Instance Method Details

#children_classObject



60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/admin/node_helper.rb', line 60

def children_class
  unless @current_node.children.empty?
    if expanded
      " children_visible"
    else
      " children_hidden"
    end
  else
    " no_children"
  end
end

#expandedObject



52
53
54
# File 'app/helpers/admin/node_helper.rb', line 52

def expanded
  show_all? || expanded_rows.include?(@current_node.id)
end

#expanded_rowsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/admin/node_helper.rb', line 36

def expanded_rows
  unless @expanded_rows
    @expanded_rows = case
    when rows = cookies[:expanded_rows]
      rows.split(',').map { |x| Integer(x) rescue nil }.compact
    else
      []
    end

    if homepage and !@expanded_rows.include?(homepage.id)
      @expanded_rows << homepage.id
    end
  end
  @expanded_rows
end

#expander(level) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'app/helpers/admin/node_helper.rb', line 76

def expander(level)
  unless @current_node.children.empty? or level == 0
    image((expanded ? "collapse" : "expand"),
          :class => "expander", :alt => 'toggle children',
          :title => '')
  else
    ""
  end
end

#homepageObject



28
29
30
# File 'app/helpers/admin/node_helper.rb', line 28

def homepage
  @homepage ||= Page.find_by_parent_id(nil)
end

#iconObject



86
87
88
89
# File 'app/helpers/admin/node_helper.rb', line 86

def icon
  icon_name = @current_node.virtual? ? 'virtual_page' : 'page'
  image(icon_name, :class => "icon", :alt => '', :title => '')
end

#node_titleObject



91
92
93
# File 'app/helpers/admin/node_helper.rb', line 91

def node_title
  %{<span class="title">#{ h(@current_node.title) }</span>}.html_safe
end

#padding_left(level) ⇒ Object



56
57
58
# File 'app/helpers/admin/node_helper.rb', line 56

def padding_left(level)
  (level * 23) + 9
end

#page_typeObject



95
96
97
98
99
100
101
102
# File 'app/helpers/admin/node_helper.rb', line 95

def page_type
  display_name = @current_node.class.display_name
  if display_name == 'Page'
    ""
  else
    %{<span class="info">(#{ h(display_name) })</span>}.html_safe
  end
end

#prepare_page(page) ⇒ Object



19
20
21
22
23
24
25
26
# File 'app/helpers/admin/node_helper.rb', line 19

def prepare_page(page)
  page.extend MenuRenderer
  page.view = self
  if page.additional_menu_features?
    page.extend(*page.menu_renderer_modules)
  end
  page
end

#render_node(page, index, parent_index = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'app/helpers/admin/node_helper.rb', line 9

def render_node(page, index, parent_index = nil)

  @current_node = prepare_page(page)

  @rendered_html += (render :partial => 'admin/pages/node',
                            :locals =>  {level: index, index: index, parent_index: parent_index,
                                         page: page, simple: false, branch: (page.children.count > 0) })
  index
end

#render_nodes(page, starting_index, parent_index = nil) ⇒ Object



3
4
5
6
7
# File 'app/helpers/admin/node_helper.rb', line 3

def render_nodes(page, starting_index, parent_index = nil)
  @rendered_html = ""
  render_node page, starting_index, parent_index
  @rendered_html
end

#show_all?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/helpers/admin/node_helper.rb', line 32

def show_all?
  controller.action_name == 'remove'
end

#spinnerObject



104
105
106
107
108
109
# File 'app/helpers/admin/node_helper.rb', line 104

def spinner
  image('spinner.gif',
          :class => 'busy', :id => "busy_#{@current_node.id}",
          :alt => "",  :title => "",
          :style => 'display: none;')
end

#virtual_classObject



72
73
74
# File 'app/helpers/admin/node_helper.rb', line 72

def virtual_class
  @current_node.virtual? ? " virtual": ""
end