first pass of supprot functions to allow query/entry_list to drive pagination, and do not go back to the server to calc next/prev page
This commit is contained in:
@@ -316,3 +316,90 @@ function NoSel() {
|
||||
else
|
||||
return true
|
||||
}
|
||||
|
||||
function handlePageOfData()
|
||||
{
|
||||
// FIXME: this should get back a json'd array of entries, and I can/should
|
||||
// use this to redraw the figures dynamically on the page
|
||||
}
|
||||
|
||||
|
||||
// Function to get the 'page' of entry ids out of entryList
|
||||
function getPage(pageNumber)
|
||||
{
|
||||
const startIndex = (pageNumber - 1) * howMany;
|
||||
const endIndex = startIndex + howMany;
|
||||
pageList = entryList.slice(startIndex, endIndex);
|
||||
// FIXME: should POST here to get the data for new pl
|
||||
return
|
||||
}
|
||||
|
||||
// Quick Function to check if we are on the first page
|
||||
function isFirstPage(pageNumber)
|
||||
{
|
||||
return pageNumber <= 1;
|
||||
}
|
||||
|
||||
// Function to check if we are on the last page
|
||||
function isLastPage(pageNumber)
|
||||
{
|
||||
const totalPages = Math.ceil(entryList.length / howMany);
|
||||
return pageNumber >= totalPages;
|
||||
}
|
||||
|
||||
// given an id in the list, return which page we are on (page 1 is first page)
|
||||
function getPageNumberForId(id) {
|
||||
const idx = entryList.indexOf(id);
|
||||
// should be impossible but jic
|
||||
if (idx === -1) {
|
||||
return -1; // or null, if you prefer
|
||||
}
|
||||
return Math.floor(idx / howMany) + 1;
|
||||
}
|
||||
|
||||
// if we are on first page, disable prev, it not ensure next is enabled
|
||||
// if we are on last page, disable next, it not ensure prev is enabled
|
||||
function resetNextPrevButtons()
|
||||
{
|
||||
if ( isFirstPage( getPageNumberForId(pageList[0]) ) )
|
||||
$('.prev').prop('disabled', true).addClass('disabled');
|
||||
else
|
||||
$('.prev').prop('disabled', false).removeClass('disabled');
|
||||
|
||||
if ( isLastPage( getPageNumberForId(pageList[0]) ) )
|
||||
$('.next').prop('disabled', true).addClass('disabled');
|
||||
else
|
||||
$('.next').prop('disabled', false).removeClass('disabled');
|
||||
}
|
||||
|
||||
// get list of eids for the next page, also make sure next/prev buttons make sense for page we are on
|
||||
function nextPage()
|
||||
{
|
||||
// pageList[0] is the first entry on this page
|
||||
const currentPage=getPageNumberForId( pageList[0] )
|
||||
// should never happen / just return pageList unchanged
|
||||
if ( currentPage === -1 || isLastPage( currentPage ) )
|
||||
{
|
||||
console.log( "WARNING: seems first on pg=" + firstEntryOnPage + " of how many=" + howMany + " gives currentPage=" + currentPage + " and we cant go next page?" )
|
||||
return
|
||||
}
|
||||
getPage( currentPage+1 )
|
||||
resetNextPrevButtons()
|
||||
return
|
||||
}
|
||||
|
||||
// get list of eids for the prev page, also make sure next/prev buttons make sense for page we are on
|
||||
function prevPage()
|
||||
{
|
||||
// pageList[0] is the first entry on this page
|
||||
const currentPage=getPageNumberForId( pageList[0] )
|
||||
// should never happen / just return pageList unchanged
|
||||
if (currentPage === 1 || currentPage === -1 )
|
||||
{
|
||||
console.log( "WARNING: seems first on pg=" + firstEntryOnPage + " of how many=" + howMany + " gives currentPage=" + currentPage + " and we cant go prev page?" )
|
||||
return
|
||||
}
|
||||
getPage( currentPage-1 )
|
||||
resetNextPrevButtons()
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user