Commit edbb830f authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Pagination buttons aren't disabled

parent 28815040
......@@ -304,6 +304,13 @@
var lastWindowWidth;
var Page = {
FIRST : 1,
PREVIOUS : 2,
NEXT : 3,
LAST : 4
};
$(document).ready(function () {
$('#explore-li').find('a').addClass('active active-group');
$('#explore-li').addClass('active');
......@@ -586,32 +593,40 @@
$("body").on("click", ".firstPage", function(e) {
e.preventDefault();
applyFiltersWithPageNumber(1);
var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
if ($(this).closest("li").hasClass("disabled") === false) {
applyFiltersWithPageNumber(1);
var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
}
});
$("body").on("click", ".nextPage", function(e) {
e.preventDefault();
page = (page ) === 501 ? page : page + 1;
applyFiltersWithPageNumber(page + 1);
var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
if ($(this).closest("li").hasClass("disabled") === false) {
page = (page ) === 501 ? page : page + 1;
applyFiltersWithPageNumber(page + 1);
var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
}
});
$("body").on("click", ".previousPage", function(e) {
e.preventDefault();
page = page === 0 ? 0 : (page - 1);
applyFiltersWithPageNumber(page + 1);
var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
if ($(this).closest("li").hasClass("disabled") === false) {
page = page === 0 ? 0 : (page - 1);
applyFiltersWithPageNumber(page + 1);
var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
}
});
$("body").on("click", ".lastPage", function(e) {
e.preventDefault();
applyFiltersWithPageNumber(totalPages);
var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
if ($(this).closest("li").hasClass("disabled") === false) {
applyFiltersWithPageNumber(totalPages);
var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
}
});
$("body").on("click", ".close", function(e) {
......@@ -859,10 +874,45 @@
var totalPages = pagedData.totalPages.toString().replace(re, ",");
$('nav').find(".results").html(messages["accessions.number"].replace("{0}", totalElements));
$('.pagination').find(".totalPages").html(messages["paged.ofPages"].replace("{0}", totalPages));
setPageUrl($(".firstPage"), 1);
setPageUrl($(".previousPage"), page == 0 ? 1 : page);
setPageUrl($(".nextPage"), page + 2);
setPageUrl($(".lastPage"), pagedData.totalPages);
var nextPage = $('.nextPage');
var lastPage = $('.lastPage');
var firstPage = $('.firstPage');
var previousPage = $('.previousPage');
if (page + 1 === 1) {
firstPage.closest("li").addClass("disabled");
previousPage.closest("li").addClass("disabled");
firstPage.children().remove();
firstPage.append($("<span aria-hidden='true'>&laquo;</span>"));
previousPage.children().remove();
previousPage.append($("<span aria-hidden='true'>&lsaquo;</span>"))
} else {
firstPage.closest("li").removeClass("disabled");
previousPage.closest("li").removeClass("disabled");
previousPage.children().remove();
previousPage.append($("<span aria-hidden='true'/>"));
firstPage.children().remove();
firstPage.append($("<span aria-hidden='true' />"));
setPageUrl(firstPage.children(), 1, Page.FIRST);
setPageUrl(previousPage.children(), page === 0 ? 1 : page, Page.PREVIOUS);
}
if (page + 1 === pagedData.totalPages) {
nextPage.closest("li").addClass("disabled");
lastPage.closest("li").addClass("disabled");
nextPage.children().remove();
nextPage.append($("<span aria-hidden='true'>&rsaquo;</span>"));
lastPage.children().remove();
lastPage.append($("<span aria-hidden='true'>&raquo;</span>"));
} else {
nextPage.closest("li").removeClass("disabled");
lastPage.closest("li").removeClass("disabled");
lastPage.children().remove();
lastPage.append($("<span aria-hidden='true'/>"));
nextPage.children().remove();
nextPage.append($("<span aria-hidden='true'/>"));
setPageUrl(nextPage.children(), page + 2, Page.NEXT);
setPageUrl(lastPage.children(), pagedData.totalPages, Page.LAST);
}
$(".pagination-input").find("input").val(page + 1);
$("input[name='filter']").val(JSON.stringify(jsonData));
......@@ -923,8 +973,23 @@
});
}
function setPageUrl (element, page) {
$(element).find("a").attr("href", "?page=" + page + "&filter=" + encodeURI(JSON.stringify(jsonData)));
function setPageUrl (parentElement, pageNumber, pageSymbol) {
var el;
switch (pageSymbol) {
case Page.PREVIOUS:
el = $("<a>&lsaquo;</a>");
break;
case Page.FIRST:
el = $("<a>&laquo;</a>");
break;
case Page.NEXT:
el = $("<a>&rsaquo;</a>");
break;
case Page.LAST:
el = $("<a>&raquo;</a>");
break;
}
$(parentElement).append($(el).attr("href", "?page=" + pageNumber + "&filter=" + encodeURI(JSON.stringify(jsonData))));
}
function renderLinks (pagedData) {
......
......@@ -14,48 +14,67 @@
<spring:message code="accessions.number" arguments="${pagedData.totalElements}"/>
</span>
</li>
<li>
<c:if test="${pagedData.number eq 0}">
<li class="disabled">
<span class="firstPage" aria-label="<spring:message code="pagination.previous-page" />">
<span aria-hidden="true">&laquo;</span>
</span>
</li>
<li class="disabled">
<span class="previousPage" aria-label="<spring:message code="pagination.previous-page" />">
<span aria-hidden="true">&lsaquo;</span>
</span>
</li>
</c:if>
<c:if test="${pagedData.number gt 0}">
<li>
<span aria-label="<spring:message code="pagination.previous-page" />" class="firstPage">
<span aria-hidden="true">
<a href="<spring:url value=""><spring:param name="page" value="1" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>">
&laquo;
</a>
<a href="<spring:url value=""><spring:param name="page" value="1" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>">&laquo;</a>
</span>
</span>
</li>
<li>
</li>
<li>
<span aria-label="<spring:message code="pagination.previous-page" />" class="previousPage">
<span aria-hidden="true">
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.number eq 0 ? 1 : pagedData.number}" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>">
&lsaquo;
</a>
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.number eq 0 ? 1 : pagedData.number}" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>">&lsaquo;</a>
</span>
</span>
</li>
</li>
</c:if>
<li>
<span class="pagination-input">
<input class="form-control" id="paginationInputField" style="display: inline; max-width: 5em; text-align: center"
type="text" name="page" value="${pagedData.number + 1}"/>
<input class="form-control" id="paginationInputField" style="display: inline; max-width: 5em; text-align: center" type="text" name="page" value="${pagedData.number + 1}"/>
</span>
</li>
<li>
<span aria-label="<spring:message code="pagination.next-page" />" class="nextPage">
<span aria-hidden="true">
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.number + 2}" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>">
&rsaquo;
</a>
<c:if test="${pagedData.number ge pagedData.totalPages-1}">
<li class="disabled">
<span class="nextPage" aria-label="<spring:message code="pagination.next-page" />">
<span aria-hidden="true">&rsaquo;</span>
</span>
</li>
<li class="disabled">
<span class="lastPage" aria-label="<spring:message code="pagination.next-page" />">
<span aria-hidden="true">&raquo;</span>
</span>
</li>
</c:if>
<c:if test="${pagedData.number lt pagedData.totalPages-1}">
<li>
<span aria-label="<spring:message code="pagination.next-page" />" class="nextPage">
<span aria-hidden="true">
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.number + 2}" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>">&rsaquo;</a>
</span>
</span>
</span>
</li>
<li>
<span aria-label="<spring:message code="pagination.next-page" />" class="lastPage">
<span aria-hidden="true">
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.totalPages}" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>">
&raquo;
</a>
</li>
<li>
<span aria-label="<spring:message code="pagination.next-page" />" class="lastPage">
<span aria-hidden="true">
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.totalPages}" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>">&raquo;</a>
</span>
</span>
</span>
</li>
</li>
</c:if>
<li>
<span class="totalPages">
<spring:message code="paged.ofPages" arguments="${pagedData.totalPages}"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment