Module: Admin::NodeHelper

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

Instance Method Summary collapse

Instance Method Details

#expandedObject



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

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

#expanded_rowsObject



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

def expanded_rows
  unless @expanded_rows
    @expanded_rows = if rows = cookies[:expanded_rows]
                       rows.split(',').map do |x|
                         begin
                                                                    Integer(x)
                         rescue StandardError
                           nil
                                                                  end
                       end .compact
                     else
                       []
    end

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

#expander(level) ⇒ Object



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

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

#homepageObject



26
27
28
# File 'app/helpers/admin/node_helper.rb', line 26

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

#iconObject



69
70
71
72
# File 'app/helpers/admin/node_helper.rb', line 69

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

#node_titleObject



74
75
76
# File 'app/helpers/admin/node_helper.rb', line 74

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

#page_typeObject



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

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



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

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, simple = false) ⇒ Object



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

def render_node(page, index, parent_index = nil, simple = false)
  @current_node = prepare_page(page)

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

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



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

def render_nodes(page, starting_index, parent_index = nil, simple = false)
  @rendered_html = ''
  render_node page, starting_index, parent_index, simple
  @rendered_html
end

#show_all?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/helpers/admin/node_helper.rb', line 30

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

#spinnerObject



87
88
89
90
91
92
# File 'app/helpers/admin/node_helper.rb', line 87

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