Class: Lapillus::ListView

Inherits:
Container show all
Defined in:
lib/lapillus/containers.rb

Instance Attribute Summary

Attributes inherited from Component

#behaviours, #identifier, #model, #property, #visible

Instance Method Summary collapse

Methods inherited from Container

#add, add_component, #component, fileuploadfield, image, #initialize, label, listview, panel, password_textfield, #post, textarea, textfield

Methods inherited from Component

#add_behaviour, #behaviour, #has_behaviour?, #has_model?, #has_parent?, #initialize, #parent, #path, #response_page=, #session, #value, #webpage

Methods inherited from RenderableComponent

#initialize, #on_render, #render_behaviours, #render_component, #render_container, #render_to_element, #visible?

Constructor Details

This class inherits a constructor from Lapillus::Container

Instance Method Details

#[](index) ⇒ Object

NOTE: in theory a user could also give a path as a String instead of an index



84
85
86
87
# File 'lib/lapillus/containers.rb', line 84

def [](index)
  index = index.to_i if index.kind_of?(String)
  return components[index]
end

#build_refresh_etcObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/lapillus/containers.rb', line 60

def build_refresh_etc
  raise "value is nil, it could be that the model/property is not set correctly!" if value.nil?
  block = parent.class.block(identifier)
  raise "listview without a block! #{self.path}" if block.nil?
  value.each_with_index { |item, index| 
    new_component = ListItem.new("item#{index}".intern, :model => item) 
    new_component.parent = self #NOTE: I could do this in the constructor!
    new_component.instance_exec(item, &block)
    @components << new_component
  }
end

#componentsObject



74
75
76
77
78
79
# File 'lib/lapillus/containers.rb', line 74

def components 
  if @components.empty?
    build_refresh_etc
  end
  @components
end

#refreshObject

TODO write test



71
72
73
# File 'lib/lapillus/containers.rb', line 71

def refresh #TODO write test
  @components = []
end

#render_children(visitor, listview_element) ⇒ Object



89
90
91
92
93
94
# File 'lib/lapillus/containers.rb', line 89

def render_children(visitor, listview_element)
  components.each {|container|
    visitor.current_container = container
    container.render_children(visitor, listview_element)
  }
end

#sizeObject

NOTE: move to container?



80
81
82
# File 'lib/lapillus/containers.rb', line 80

def size #NOTE: move to container?
  return components.size
end