var latestDocumentIndex = 0; var latestDocumentMobileIndex = 0; var latestDocuments = []; var lastPageIndex = 0; var currentPage = 0; var totalDocuments = 0 var lastPage = 0; // makes a POST request to a specified endpoint for filters and then parse the JSON response. Uses these documents to build the latestDocumentContainer and latestDocumentMobileContainer. async function getLatestDocuments() { var request = await SendRequest('POST', baseUrl + 'savedFilters', { GetDocs: true }); var json = JSON.parse(request.response); var docs = await json2array(json); latestDocuments = docs; lastPageIndex = Math.ceil(docs.length / 7); totalDocuments = docs.length; if (totalDocuments !== 0) { await buildLatestDocuments(0); await buildLatestDocumentsMobile(); $("#latestDocumentWidget-mobile").remove(); } else { $("#latestDocumentLoadingText").text("No documents published"); $("#latestDocumentMobileLoadingText").text("No documents published"); } } // updates the current page number and sets the page numbers in the navigation bar for latest documents widget async function calculateCurrentPage(pageNumber) { var amountOfPages = lastPageIndex; if (pageNumber === 0) { pageNumber++; } $('#pageCount').text('Page ' + pageNumber + ' of ' + lastPageIndex); currentPage = pageNumber; } // moves the user to the next page and rebuilds the latestDocumentContainer async function PageNext(addition) { if (currentPage < (lastPageIndex)) { addSkeletonLoader(); latestDocumentIndex = latestDocumentIndex + addition; await rebuildLatestDocuments(++currentPage); } } // moves the user to the previous page and rebuilds the latestDocumentContainer async function PagePrevious(subtraction) { if (currentPage != 1) { addSkeletonLoader(); latestDocumentIndex = latestDocumentIndex - subtraction; await rebuildLatestDocuments(--currentPage); } } // takes the user back to the first page and rebuilds the latestDocumentContainer async function PageFirst() { if (currentPage != 1) { addSkeletonLoader(); latestDocumentIndex = 0; await rebuildLatestDocuments(0); } } // takes the user to the last page and rebuilds the latestDocumentContainer async function PageLast() { if (currentPage < lastPageIndex) { addSkeletonLoader(); latestDocumentIndex = totalDocuments - 2; lastPage = (lastPageIndex); await rebuildLatestDocuments(lastPage); } } /// Desktop View // takes a pageNumber as a parameter and builds a set of HTML elements for the latestDocumentPane. It loops through 7 documents starting from the most recent and formats their data. async function buildLatestDocuments(pageNumber) { setTimeout(async function () { var startArray = latestDocumentIndex; var docs = ""; var TodayAdded = false; var YesterdayAdded = false; var EarlyAdded = false; docs += `
' + document["title"] + '
' + '' + document["title"] + '
' + '' + document["title"] + '
' + '