Class: Interview::Tree

Inherits:
Control show all
Defined in:
lib/interview/tree.rb

Instance Attribute Summary collapse

Attributes inherited from Control

#parent

Instance Method Summary collapse

Methods inherited from Control

#ancestors, build, definition, #find_attribute, #find_attribute!, inherited, #initialize, #set_attributes, #set_defaults

Constructor Details

This class inherits a constructor from Interview::Control

Instance Attribute Details

#iconObject

Returns the value of attribute icon.



4
5
6
# File 'lib/interview/tree.rb', line 4

def icon
  @icon
end

#sortableObject

Returns the value of attribute sortable.



4
5
6
# File 'lib/interview/tree.rb', line 4

def sortable
  @sortable
end

Instance Method Details

#renderObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/interview/tree.rb', line 6

def render
  defaults = {}
  defaults[:icon] = @icon if @icon and @icon != :polymorphic
  objects = find_attribute! :objects
  data_content = objects.map do |object|
    object_data = {
      id: object.id.to_s,
      parent: object.parent_id ? object.parent_id.to_s : '#',
      text: object.human_id,
      state: {
        opened: true
      },
      a_attr: {
        href: h.polymorphic_path(object)
      }
    }.merge defaults
    object_data[:icon] = object.icon if @icon == :polymorphic
    object_data
  end
  data = { content: CGI::escapeHTML(data_content.to_json) }
  data[:sortable] = true if @sortable
  
  return h.(:div, '', { class: 'jstree', data: data }, false)
         
end