Class: Lapillus::Pager

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

Defined Under Namespace

Classes: FirstButton, LastButton, NextButton, PagerButton, PreviousButton

Instance Attribute Summary collapse

Attributes inherited from Container

#components

Attributes inherited from Component

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

Instance Method Summary collapse

Methods inherited from Container

#[], #add, add_component, #component, fileuploadfield, image, label, listview, panel, password_textfield, #post, #render_container, textarea, textfield

Methods inherited from Component

#add_behaviour, #behaviour, #has_behaviour?, #has_model?, #has_parent?, #on_render, #parent, #path, #render_component, #response_page=, #session, #value, #visible?, #webpage

Constructor Details

#initialize(id, pages, &block) ⇒ Pager

Returns a new instance of Pager.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lapillus/pager.rb', line 9

def initialize(id, pages, &block)
  super(id)
  raise "no block given!" if !block_given?
  @pages = pages
  @current = 1
  @block = block
  @navigation = Lapillus::Container.new("navigation")
  @first_button = FirstButton.new("first", self)
  @previous_button = PreviousButton.new("previous", self)
  @next_button = NextButton.new("next", self)
  @last_button = LastButton.new("last", self)
  @position = Label.new("position")
  navigation.add(first_button)
  navigation.add(previous_button)
  navigation.add(next_button)
  navigation.add(last_button)
  navigation.add(position)
  build_hierarchy
end

Instance Attribute Details

#currentObject

Returns the value of attribute current.



6
7
8
# File 'lib/lapillus/pager.rb', line 6

def current
  @current
end

#first_buttonObject

Returns the value of attribute first_button.



7
8
9
# File 'lib/lapillus/pager.rb', line 7

def first_button
  @first_button
end

#last_buttonObject

Returns the value of attribute last_button.



8
9
10
# File 'lib/lapillus/pager.rb', line 8

def last_button
  @last_button
end

Returns the value of attribute navigation.



7
8
9
# File 'lib/lapillus/pager.rb', line 7

def navigation
  @navigation
end

#next_buttonObject

Returns the value of attribute next_button.



8
9
10
# File 'lib/lapillus/pager.rb', line 8

def next_button
  @next_button
end

#page_containerObject (readonly)

Returns the value of attribute page_container.



6
7
8
# File 'lib/lapillus/pager.rb', line 6

def page_container
  @page_container
end

#pagesObject

Returns the value of attribute pages.



7
8
9
# File 'lib/lapillus/pager.rb', line 7

def pages
  @pages
end

#positionObject

Returns the value of attribute position.



8
9
10
# File 'lib/lapillus/pager.rb', line 8

def position
  @position
end

#previous_buttonObject

Returns the value of attribute previous_button.



7
8
9
# File 'lib/lapillus/pager.rb', line 7

def previous_button
  @previous_button
end

Instance Method Details

#build_hierarchyObject

TODO: this is not so handy components are recreated and stuff; split in constructor/on_render also parent and path do not work



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/lapillus/pager.rb', line 32

def build_hierarchy
  @page_container = ListItem.new("page") 
  @page_container.parent = self #NOTE: I could do this in the constructor!  
  if !@pages.empty?
    @page_container.instance_exec(page_content, &@block)
#        @components << @page_container ???
    first_button.visible= previous_button.visible = current > 1
    last_button.visible= next_button.visible = current < pages.size
    position.model = "#{@current} van #{@pages.size}"
    page_container.visible = true
    navigation.visible = true
  else
    page_container.visible = false
    navigation.visible = false
  end
  @components = []
  add(page_container)
  add(navigation)
end

#page_contentObject



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

def page_content
  @pages[@current-1]
end