diff --git a/app/assets/javascripts/app/controllers/_application_controller/reorder_modal.coffee b/app/assets/javascripts/app/controllers/_application_controller/reorder_modal.coffee index 5116d4acd..59957b9d2 100644 --- a/app/assets/javascripts/app/controllers/_application_controller/reorder_modal.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller/reorder_modal.coffee @@ -4,6 +4,7 @@ class App.ControllerReorderModal extends App.ControllerModal view = $(App.view('reorder_modal')()) table = new App.ControllerTable( + pager: false baseColWidth: null dndCallback: -> true diff --git a/app/assets/javascripts/app/controllers/_application_controller/table.coffee b/app/assets/javascripts/app/controllers/_application_controller/table.coffee index 2b0b43c0d..809c767f4 100644 --- a/app/assets/javascripts/app/controllers/_application_controller/table.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller/table.coffee @@ -111,8 +111,9 @@ class App.ControllerTable extends App.Controller groupBy: undefined groupDirection: undefined - shownPerPage: 150 - shownPage: 0 + pagerEnabled: true + pagerItemsPerPage: 150 + pagerShownPage: 0 destroy: false customActions: [] @@ -197,6 +198,8 @@ class App.ControllerTable extends App.Controller App.QueueManager.run('tableRender') renderPager: (el, find = false) => + return if !@pagerEnabled + if @pagerAjax @renderPagerAjax(el, find) else @@ -220,7 +223,7 @@ class App.ControllerTable extends App.Controller el.filter('.js-pager').html(pager) renderPagerStatic: (el, find = false) => - pages = parseInt(((@objects.length - 1) / @shownPerPage)) + pages = parseInt(((@objects.length - 1) / @pagerItemsPerPage)) if pages < 1 if find el.find('.js-pager').html('') @@ -228,7 +231,7 @@ class App.ControllerTable extends App.Controller el.filter('.js-pager').html('') return pager = App.view('generic/table_pager')( - page: @shownPage + page: @pagerShownPage pages: pages ) if find @@ -500,7 +503,7 @@ class App.ControllerTable extends App.Controller groupLast = '' groupLastName = '' tableBody = [] - objectsToShow = @objectsOfPage(@shownPage) + objectsToShow = @objectsOfPage(@pagerShownPage) for object in objectsToShow objectActions = [] @@ -663,13 +666,17 @@ class App.ControllerTable extends App.Controller ['new headers', @headers] setMaxPage: => - pages = parseInt(((@objects.length - 1) / @shownPerPage)) - if parseInt(@shownPage) > pages - @shownPage = pages + return if !@pagerEnabled + + pages = parseInt(((@objects.length - 1) / @pagerItemsPerPage)) + if parseInt(@pagerShownPage) > pages + @pagerShownPage = pages objectsOfPage: (page = 0) => + return @objects if !@pagerEnabled + page = parseInt(page) - @objects.slice(page * @shownPerPage, (page + 1) * @shownPerPage) + @objects.slice(page * @pagerItemsPerPage, (page + 1) * @pagerItemsPerPage) paginate: (e) => e.stopPropagation() @@ -678,7 +685,7 @@ class App.ControllerTable extends App.Controller @navigate "#{@pagerBaseUrl}#{(parseInt(page) + 1)}" else render = => - @shownPage = page + @pagerShownPage = page @renderTableFull() App.QueueManager.add('tableRender', render) App.QueueManager.run('tableRender') diff --git a/public/assets/tests/table_extended.js b/public/assets/tests/table_extended.js index 082861c2f..12bba40db 100644 --- a/public/assets/tests/table_extended.js +++ b/public/assets/tests/table_extended.js @@ -1705,4 +1705,73 @@ test('table new - initial list', function() { equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2') equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '', 'check row 2') + $('#table').append('

table with large data and pager and 10 per page

') + var el = $('#table-new12') + + var objects = []; + var created_at = Date.parse('2014-06-10T11:17:34.000Z') + + for (i = 0; i < 35; i++) { + local_created_at = new Date(created_at - (1000 * 60 * 60 * 24 * i)).toISOString() + item = { + id: i, + name: i + ' prio', + note: 'some note', + active: true, + created_at: local_created_at, + } + objects.push(item) + } + + App.TicketPriority.refresh(objects, {clear: true}) + + var table = new App.ControllerTable({ + tableId: 'large_table_test_pager', + el: el, + overviewAttributes: ['name', 'created_at', 'active'], + model: App.TicketPriority, + objects: App.TicketPriority.all(), + checkbox: false, + radio: false, + pagerItemsPerPage: 10, + ttt: true + }) + + equal(el.find('tbody > tr').length, 10) + equal(el.find('.js-pager:first-child .js-page').length, 4) + + $('#table').append('

table with large data and pager disabled

') + var el = $('#table-new13') + + var objects = []; + var created_at = Date.parse('2014-06-10T11:17:34.000Z') + + for (i = 0; i < 200; i++) { + local_created_at = new Date(created_at - (1000 * 60 * 60 * 24 * i)).toISOString() + item = { + id: i, + name: i + ' prio', + note: 'some note', + active: true, + created_at: local_created_at, + } + objects.push(item) + } + + App.TicketPriority.refresh(objects, {clear: true}) + + var table = new App.ControllerTable({ + tableId: 'large_table_test_pager', + el: el, + overviewAttributes: ['name', 'created_at', 'active'], + model: App.TicketPriority, + objects: App.TicketPriority.all(), + checkbox: false, + radio: false, + pagerEnabled: false, + ttt: true + }) + + equal(el.find('tbody > tr').length, 200) + equal(el.find('.js-pager:first-child .js-page').length, 0) })