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

Pagination buttons aren't disabled

parent 28815040
...@@ -304,6 +304,13 @@ ...@@ -304,6 +304,13 @@
var lastWindowWidth; var lastWindowWidth;
var Page = {
FIRST : 1,
PREVIOUS : 2,
NEXT : 3,
LAST : 4
};
$(document).ready(function () { $(document).ready(function () {
$('#explore-li').find('a').addClass('active active-group'); $('#explore-li').find('a').addClass('active active-group');
$('#explore-li').addClass('active'); $('#explore-li').addClass('active');
...@@ -586,32 +593,40 @@ ...@@ -586,32 +593,40 @@
$("body").on("click", ".firstPage", function(e) { $("body").on("click", ".firstPage", function(e) {
e.preventDefault(); e.preventDefault();
applyFiltersWithPageNumber(1); if ($(this).closest("li").hasClass("disabled") === false) {
var element_to_scroll_to = $('#table-top')[0]; applyFiltersWithPageNumber(1);
element_to_scroll_to.scrollIntoView(); var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
}
}); });
$("body").on("click", ".nextPage", function(e) { $("body").on("click", ".nextPage", function(e) {
e.preventDefault(); e.preventDefault();
page = (page ) === 501 ? page : page + 1; if ($(this).closest("li").hasClass("disabled") === false) {
applyFiltersWithPageNumber(page + 1); page = (page ) === 501 ? page : page + 1;
var element_to_scroll_to = $('#table-top')[0]; applyFiltersWithPageNumber(page + 1);
element_to_scroll_to.scrollIntoView(); var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
}
}); });
$("body").on("click", ".previousPage", function(e) { $("body").on("click", ".previousPage", function(e) {
e.preventDefault(); e.preventDefault();
page = page === 0 ? 0 : (page - 1); if ($(this).closest("li").hasClass("disabled") === false) {
applyFiltersWithPageNumber(page + 1); page = page === 0 ? 0 : (page - 1);
var element_to_scroll_to = $('#table-top')[0]; applyFiltersWithPageNumber(page + 1);
element_to_scroll_to.scrollIntoView(); var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
}
}); });
$("body").on("click", ".lastPage", function(e) { $("body").on("click", ".lastPage", function(e) {
e.preventDefault(); e.preventDefault();
applyFiltersWithPageNumber(totalPages); if ($(this).closest("li").hasClass("disabled") === false) {
var element_to_scroll_to = $('#table-top')[0]; applyFiltersWithPageNumber(totalPages);
element_to_scroll_to.scrollIntoView(); var element_to_scroll_to = $('#table-top')[0];
element_to_scroll_to.scrollIntoView();
}
}); });
$("body").on("click", ".close", function(e) { $("body").on("click", ".close", function(e) {
...@@ -859,10 +874,45 @@ ...@@ -859,10 +874,45 @@
var totalPages = pagedData.totalPages.toString().replace(re, ","); var totalPages = pagedData.totalPages.toString().replace(re, ",");
$('nav').find(".results").html(messages["accessions.number"].replace("{0}", totalElements)); $('nav').find(".results").html(messages["accessions.number"].replace("{0}", totalElements));
$('.pagination').find(".totalPages").html(messages["paged.ofPages"].replace("{0}", totalPages)); $('.pagination').find(".totalPages").html(messages["paged.ofPages"].replace("{0}", totalPages));
setPageUrl($(".firstPage"), 1); var nextPage = $('.nextPage');
setPageUrl($(".previousPage"), page == 0 ? 1 : page); var lastPage = $('.lastPage');
setPageUrl($(".nextPage"), page + 2); var firstPage = $('.firstPage');
setPageUrl($(".lastPage"), pagedData.totalPages); 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); $(".pagination-input").find("input").val(page + 1);
$("input[name='filter']").val(JSON.stringify(jsonData)); $("input[name='filter']").val(JSON.stringify(jsonData));
...@@ -923,8 +973,23 @@ ...@@ -923,8 +973,23 @@
}); });
} }
function setPageUrl (element, page) { function setPageUrl (parentElement, pageNumber, pageSymbol) {
$(element).find("a").attr("href", "?page=" + page + "&filter=" + encodeURI(JSON.stringify(jsonData))); 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) { function renderLinks (pagedData) {
......
...@@ -14,48 +14,67 @@ ...@@ -14,48 +14,67 @@
<spring:message code="accessions.number" arguments="${pagedData.totalElements}"/> <spring:message code="accessions.number" arguments="${pagedData.totalElements}"/>
</span> </span>
</li> </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-label="<spring:message code="pagination.previous-page" />" class="firstPage">
<span aria-hidden="true"> <span aria-hidden="true">
<a href="<spring:url value=""><spring:param name="page" value="1" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>"> <a href="<spring:url value=""><spring:param name="page" value="1" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>">&laquo;</a>
&laquo;
</a>
</span> </span>
</span> </span>
</li> </li>
<li> <li>
<span aria-label="<spring:message code="pagination.previous-page" />" class="previousPage"> <span aria-label="<spring:message code="pagination.previous-page" />" class="previousPage">
<span aria-hidden="true"> <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>"> <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>
&lsaquo;
</a>
</span> </span>
</span> </span>
</li> </li>
</c:if>
<li> <li>
<span class="pagination-input"> <span class="pagination-input">
<input class="form-control" id="paginationInputField" style="display: inline; max-width: 5em; text-align: center" <input class="form-control" id="paginationInputField" style="display: inline; max-width: 5em; text-align: center" type="text" name="page" value="${pagedData.number + 1}"/>
type="text" name="page" value="${pagedData.number + 1}"/>
</span> </span>
</li> </li>
<li> <c:if test="${pagedData.number ge pagedData.totalPages-1}">
<span aria-label="<spring:message code="pagination.next-page" />" class="nextPage"> <li class="disabled">
<span aria-hidden="true"> <span class="nextPage" aria-label="<spring:message code="pagination.next-page" />">
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.number + 2}" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>"> <span aria-hidden="true">&rsaquo;</span>
&rsaquo; </span>
</a> </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>
</span> </li>
</li> <li>
<li> <span aria-label="<spring:message code="pagination.next-page" />" class="lastPage">
<span aria-label="<spring:message code="pagination.next-page" />" class="lastPage"> <span aria-hidden="true">
<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>
<a href="<spring:url value=""><spring:param name="page" value="${pagedData.totalPages}" /><spring:param name="filter" value="${jsonFilter}" /></spring:url>"> </span>
&raquo;
</a>
</span> </span>
</span> </li>
</li> </c:if>
<li> <li>
<span class="totalPages"> <span class="totalPages">
<spring:message code="paged.ofPages" arguments="${pagedData.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