Fixed pagination.

This commit is contained in:
Martin Edenhofer 2014-07-24 01:49:15 +02:00
parent 838756e30d
commit 43ac0e2872
2 changed files with 27 additions and 29 deletions

View file

@ -5,7 +5,7 @@ class App.DashboardTicket extends App.Controller
constructor: -> constructor: ->
super super
@start_page = 1 @item_from = 1
# set new key # set new key
@key = 'ticket_overview_' + @view @key = 'ticket_overview_' + @view
@ -71,30 +71,29 @@ class App.DashboardTicket extends App.Controller
@overview = data.overview @overview = data.overview
@tickets_count = data.tickets_count @tickets_count = data.tickets_count
@ticket_ids = data.ticket_ids @ticket_ids = data.ticket_ids
per_page = Math.min(@overview.view.per_page || 10, @tickets_count) items_total = @tickets_count
tickets_from = @start_page * per_page items_per_page = Math.min(@overview.view.per_page || 10, @tickets_count)
tickets_till = Math.max(tickets_from + per_page-1, 0) items_from = @item_from
pages_total = parseInt( ( @tickets_count / per_page ) + 0.99999 ) || 1 items_till = items_from-1 + items_per_page
if items_till > items_total
items_till = items_total
html = App.view('dashboard/ticket')( html = App.view('dashboard/ticket')(
overview: @overview, overview: @overview
pages_total: pages_total, items_per_page: items_per_page
start_page: @start_page, items_from: items_from
tickets_from: tickets_from, items_till: items_till
tickets_till: tickets_till, items_total: items_total
tickets_count: @tickets_count
) )
html = $(html) html = $(html)
html.find('li').removeClass('active') html.find('li').removeClass('active')
html.find(".page [data-id=\"#{@start_page}\"]").parents('li').addClass('active') html.find(".page [data-id=\"#{@start_page}\"]").parents('li').addClass('active')
@tickets_in_table = [] @tickets_in_table = []
start = ( @start_page-1 ) * 5 i = items_from - 1
end = ( @start_page ) * 5 while i < items_till
i = start if @ticket_ids[ i ]
while i < end @tickets_in_table.push App.Ticket.retrieve( @ticket_ids[ i ] )
i = i + 1 i = i + 1
if @ticket_ids[ i - 1 ]
@tickets_in_table.push App.Ticket.retrieve( @ticket_ids[ i - 1 ] )
openTicket = (id,e) => openTicket = (id,e) =>
ticket = App.Ticket.retrieve(id) ticket = App.Ticket.retrieve(id)
@ -183,7 +182,8 @@ class App.DashboardTicket extends App.Controller
page: (e) => page: (e) =>
e.preventDefault() e.preventDefault()
id = $(e.target).data('id') @item_from = $(e.target).data('from')
@start_page = id if !@item_from
@item_from = $(e.target).parent().data('from')
return if !@item_from
@fetch() @fetch()

View file

@ -5,29 +5,27 @@
</div> </div>
<div class="page-header-meta horizontal"> <div class="page-header-meta horizontal">
<div class="pagination-counter"> <div class="pagination-counter">
<span class="pagination-items-range"><%- @tickets_from %>-<%- @tickets_till %></span> <%- @T("of") %> <span class="pagination-total-items"><%- @tickets_count %></span> <span class="pagination-items-range"><%- @items_from %>-<%- @items_till %></span> <%- @T("of") %> <span class="pagination-total-items"><%- @items_total %></span>
</div> </div>
<ul class="pagination"> <ul class="pagination">
<li> <li>
<% if @start_page != 1: %> <% if @items_from != 1: %>
<a class="centered" href="#" data-id="<%= @start_page - 1 %>" data-type="page"> <a class="centered" href="#" data-from="<%= @items_from - @items_per_page %>" data-type="page">
<span class="left arrow icon"></span> <span class="left arrow icon"></span>
</a> </a>
<% else: %> <% else: %>
<a class="disabled centered" href="#" data-id="<%= @start_page %>" data-type="page"> <a class="disabled centered" href="#" data-from="" data-type="page">
<span class="disabled left arrow icon"></span> <span class="disabled left arrow icon"></span>
</a> </a>
<% end %> <% end %>
</li> </li>
<% for item in [1..@pages_total]: %>
<% end %>
<li> <li>
<% if @start_page != @pages_total: %> <% if @items_till != @items_total: %>
<a class="centered" href="#" data-id="<%= @start_page + 1 %>" data-type="page"> <a class="centered" href="#" data-from="<%= @items_from + @items_per_page %>" data-type="page">
<span class="right arrow icon"></span> <span class="right arrow icon"></span>
</a> </a>
<% else: %> <% else: %>
<a class="disabled centered" href="#" data-id="<%= @start_page %>" data-type="page"> <a class="disabled centered" href="#" data-from="" data-type="page">
<span class="disabled right arrow icon"></span> <span class="disabled right arrow icon"></span>
</a> </a>
</li> </li>