% content_for :css do %>
.index-paging {
text-align: center;
padding-left: 1em;
padding-right: 1em;
background-color: whitesmoke;
}
.paging-number {
display: inline-block;
min-width: 1.2em;
}
<% end %>
<% results.fetch_multiple_pages(false) %>
<% if results.respond_to? :result_offset and
results.respond_to? :result_limit and
results.respond_to? :items_available and
results.result_offset != nil and
results.result_limit != nil and
results.items_available != nil
%>
Displaying <%= results.result_offset+1 %> –
<%= if results.result_offset + results.result_limit > results.items_available
results.items_available
else
results.result_offset + results.result_limit
end %>
out of <%= results.items_available %>
<% if not (results.result_offset == 0 and results.items_available <= results.result_limit) %>
<% if results.result_offset > 0 %>
<% if results.result_offset > results.result_limit %>
<% prev_offset = results.result_offset - results.result_limit %>
<% else %>
<% prev_offset = 0 %>
<% end %>
<% else %>
<% prev_offset = nil %>
<% end %>
<% this_offset = results.result_offset %>
<% if (results.result_offset + results.result_limit) < results.items_available %>
<% next_offset = results.result_offset + results.result_limit %>
<% else %>
<% next_offset = nil %>
<% end %>
<% if results.result_offset > 0 %>
<%= link_to raw(""), {:id => object, :offset => 0, :limit => results.result_limit} %>
<% else %>
<% end %>
<% if prev_offset %>
<%= link_to raw(""), {:id => object, :offset => prev_offset, :limit => results.result_limit} %>
<% else %>
<% end %>
<% first = this_offset - (10 * results.result_limit) %>
<% last = this_offset + (11 * results.result_limit) %>
<% lastpage_offset = (results.items_available / results.result_limit) * results.result_limit %>
<% if last > results.items_available %>
<% first -= (last - lastpage_offset) %>
<% last -= (last - results.items_available) %>
<% end %>
<% if first < 0 %>
<% d = -first %>
<% first += d %>
<% last += d %>
<% end %>
<% last = results.items_available if last > results.items_available %>
<% i = first %>
<% n = first / results.result_limit %>
<% if first > 0 %>
…
<% end %>
<% while i < last %>
<% if i != this_offset %>
<%= link_to "#{n+1}", {:id => @object, :offset => i, :limit => results.result_limit}, class: 'paging-number' %>
<% else %>
<%= n+1 %>
<% end %>
<% i += results.result_limit %>
<% n += 1 %>
<% end %>
<% if last < results.items_available %>
…
<% end %>
<% if next_offset %>
<%= link_to raw(""), {:id => @object, :offset => next_offset, :limit => results.result_limit} %>
<% else %>
<% end %>
<% if (results.items_available - results.result_offset) >= results.result_limit %>
<%= link_to raw(""), {:id => @object, :offset => results.items_available - (results.items_available % results.result_limit),
:limit => results.result_limit} %>
<% else %>
<% end %>
<% end %>
<% end %>