Class: Carnival::Paginator

Inherits:
Object
  • Object
show all
Defined in:
app/view_objects/carnival/paginator.rb

Instance Method Summary collapse

Constructor Details

#initialize(actual_page, last_page, max_fast_pages = 5) ⇒ Paginator

Returns a new instance of Paginator.



4
5
6
7
8
# File 'app/view_objects/carnival/paginator.rb', line 4

def initialize(actual_page, last_page, max_fast_pages = 5)
  @actual_page = actual_page 
  @last_page = last_page >= 1 ? last_page : 1
  @max_fast_pages = max_fast_pages
end

Instance Method Details



22
23
24
25
26
27
28
# File 'app/view_objects/carnival/paginator.rb', line 22

def fast_pages_links_html
  htmls = []
  fast_pages_links_indexes.each do |page| 
    htmls << {:label => page, :css_class => get_css_class(page), :js_function => get_js_function(page)}
  end
  htmls
end


10
11
12
13
14
15
16
17
18
19
20
# File 'app/view_objects/carnival/paginator.rb', line 10

def fast_pages_links_indexes
  fast_page_links = []
  first_index = -(@max_fast_pages/2)
  while fast_page_links.size < @max_fast_pages do
    fast_page = @actual_page + first_index
    break if fast_page > @last_page
    fast_page_links << fast_page if fast_page > 0
    first_index = first_index + 1
  end
  fast_page_links
end

#get_css_class(page) ⇒ Object



34
35
36
37
# File 'app/view_objects/carnival/paginator.rb', line 34

def get_css_class page
  return 'carnival-selected-page-button' if page == @actual_page
  return 'carnival-page-button'
end

#get_js_function(page) ⇒ Object



30
31
32
# File 'app/view_objects/carnival/paginator.rb', line 30

def get_js_function page
  "javascript:Carnival.goToPage(#{page})" 
end

#next_pageObject



44
45
46
47
# File 'app/view_objects/carnival/paginator.rb', line 44

def next_page
  return @actual_page if @actual_page + 1 > @last_page 
  @actual_page + 1
end

#pagesObject



49
50
51
52
53
54
55
56
# File 'app/view_objects/carnival/paginator.rb', line 49

def pages
  htmls = [] 
  htmls << {:label => ('paginate_first'), :js_function => get_js_function(1)}
  htmls << {:label => ('paginate_previous'), :js_function => get_js_function(previous_page)}
  htmls = htmls + fast_pages_links_html
  htmls << {:label => ('paginate_next'), :js_function => get_js_function(next_page)}
  htmls << {:label => ('paginate_last'), :js_function => get_js_function(@last_page)}
end

#previous_pageObject



39
40
41
42
# File 'app/view_objects/carnival/paginator.rb', line 39

def previous_page
  return @actual_page if @actual_page - 1 < 1 
  @actual_page - 1
end