Class: Interview::Tree
- Defined in:
- lib/interview/controls/tree.rb
Instance Attribute Summary collapse
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#sortable ⇒ Object
Returns the value of attribute sortable.
Attributes inherited from Control
Instance Method Summary collapse
Methods inherited from Control
#ancestors, #build_child, #build_with_params, #find_attribute, #find_attribute!, #initialize, #set_attributes, #set_defaults
Constructor Details
This class inherits a constructor from Interview::Control
Instance Attribute Details
#icon ⇒ Object
Returns the value of attribute icon.
4 5 6 |
# File 'lib/interview/controls/tree.rb', line 4 def icon @icon end |
#sortable ⇒ Object
Returns the value of attribute sortable.
4 5 6 |
# File 'lib/interview/controls/tree.rb', line 4 def sortable @sortable end |
Instance Method Details
#build(b) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/interview/controls/tree.rb', line 6 def build(b) 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 b.section html_class: 'jstree', html_options: { data: data } end |