Fixed pagination.

This commit is contained in:
Martin Edenhofer 2014-09-20 20:31:16 +02:00
parent 3131f945c4
commit a56da6fbb9

View file

@ -4,16 +4,18 @@ class App.DashboardTicketSearch extends App.Controller
constructor: -> constructor: ->
super super
@start_page = 1 @item_from = 1
@navupdate '#' @navupdate '#'
@key = @name + @Session.get('id')
# render # render
@fetch() @fetch()
fetch: (force) => fetch: (force) =>
@ajax( @ajax(
id: 'dashboard_ticket_search' + @name, id: 'dashboard_ticket_search' + @key,
type: 'GET', type: 'GET',
url: @apiPath + '/tickets/search', url: @apiPath + '/tickets/search',
data: data:
@ -30,7 +32,7 @@ class App.DashboardTicketSearch extends App.Controller
load: (data = false, ajax = false) => load: (data = false, ajax = false) =>
if ajax if ajax
App.Store.write( 'dashboard_ticket_search' + @name, data ) App.Store.write( 'dashboard_ticket_search' + @key, data )
# load assets # load assets
App.Collection.loadAssets( data.assets ) App.Collection.loadAssets( data.assets )
@ -38,7 +40,7 @@ class App.DashboardTicketSearch extends App.Controller
@render( data ) @render( data )
else else
data = App.Store.get( 'dashboard_ticket_search' + @name ) data = App.Store.get( 'dashboard_ticket_search' + @key )
if data if data
@render( data ) @render( data )
@ -52,24 +54,30 @@ class App.DashboardTicketSearch extends App.Controller
@tickets_count = data.tickets_count @tickets_count = data.tickets_count
@ticket_ids = data.tickets @ticket_ids = data.tickets
per_page = @per_page || 5 per_page = @per_page || 5
pages_total = parseInt( ( @tickets_count / per_page ) + 0.99999 ) || 1
items_total = @tickets_count
items_per_page = Math.min(per_page || 10, @tickets_count)
items_from = @item_from
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
items_till: items_till
items_total: items_total
) )
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.fullLocal( @ticket_ids[ i - 1 ] )
openTicket = (id,e) => openTicket = (id,e) =>
ticket = App.Ticket.fullLocal(id) ticket = App.Ticket.fullLocal(id)
@ -127,6 +135,13 @@ class App.DashboardTicketSearch extends App.Controller
page: (e) => page: (e) =>
e.preventDefault() e.preventDefault()
id = $(e.target).data('id') id = $(e.target).data('id')
@start_page = id @item_from = id
@load() @load()
page: (e) =>
e.preventDefault()
@item_from = $(e.target).data('from')
if !@item_from
@item_from = $(e.target).parent().data('from')
return if !@item_from
@load()