pagination of results
This commit is contained in:
parent
e352e0a8b2
commit
785cb81386
@ -47,7 +47,6 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" id="current-offset" value="0" />
|
<input type="hidden" id="current-offset" value="0" />
|
||||||
<input type="hidden" id="current-pattern" value="" />
|
|
||||||
<div id="occurences">
|
<div id="occurences">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,14 +1,21 @@
|
|||||||
var pageLimit = 20;
|
var pageLimit = 20;
|
||||||
|
|
||||||
function secondStepSearch(caller) {
|
function secondStepSearch(fragment) {
|
||||||
|
|
||||||
|
var searchQuery = $('body').data('current_fragment');
|
||||||
|
if (typeof(fragment) !== "undefined") {
|
||||||
|
searchQuery = fragment;
|
||||||
|
$('body').data('current_fragment', fragment);
|
||||||
|
}
|
||||||
var fullSearchRequest = {
|
var fullSearchRequest = {
|
||||||
operation: 'fullSearch',
|
operation: 'fullSearch',
|
||||||
tmId: currentTmId,
|
tmId: currentTmId,
|
||||||
limit: pageLimit,
|
limit: pageLimit,
|
||||||
offset: $('#current-offset').val(),
|
offset: $('#current-offset').val(),
|
||||||
pattern:caller.innerHTML
|
pattern:searchQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/cat/concordia_gate.php',
|
url: '/cat/concordia_gate.php',
|
||||||
type: 'post',
|
type: 'post',
|
||||||
@ -21,17 +28,38 @@ function secondStepSearch(caller) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prevPage() {
|
||||||
|
var currentOffset = parseInt($('#current-offset').val());
|
||||||
|
if (currentOffset >= pageLimit) {
|
||||||
|
$('#current-offset').val(currentOffset-pageLimit)
|
||||||
|
secondStepSearch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function nextPage() {
|
||||||
|
var currentOffset = parseInt($('#current-offset').val());
|
||||||
|
var currentTotalCount = $('body').data('currentTotalCount');
|
||||||
|
if (currentOffset < currentTotalCount - pageLimit) {
|
||||||
|
$('#current-offset').val(currentOffset+pageLimit)
|
||||||
|
secondStepSearch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function presentFullSearchResults(data) {
|
function presentFullSearchResults(data) {
|
||||||
var pattern = $('#current-pattern').val();
|
var pattern = $('#current-pattern').val();
|
||||||
var offset = parseInt($('#current-offset').val());
|
var offset = parseInt($('#current-offset').val());
|
||||||
var begin = offset+1;
|
var begin = offset+1;
|
||||||
var end = offset + pageLimit;
|
var end = offset + pageLimit;
|
||||||
var totalCount = parseInt(data['result']['totalCount']);
|
var totalCount = parseInt(data['result']['totalCount']);
|
||||||
|
$('body').data('currentTotalCount', totalCount);
|
||||||
if (end > totalCount) {
|
if (end > totalCount) {
|
||||||
end = totalCount;
|
end = totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = 'Showing results '+begin+' - '+end+' of '+totalCount+'<br>';
|
var result = 'Showing results '+begin+' - '+end+' of '+totalCount+' ';
|
||||||
|
result += '<button onclick=prevPage()>previous page</button> ';
|
||||||
|
result += '<button onclick=nextPage()>next page</button><br>';
|
||||||
|
|
||||||
for (j=0;j<data['result']['occurences'].length;j++) {
|
for (j=0;j<data['result']['occurences'].length;j++) {
|
||||||
var occurence = data['result']['occurences'][j];
|
var occurence = data['result']['occurences'][j];
|
||||||
@ -165,7 +193,7 @@ function renderResult(data) {
|
|||||||
|
|
||||||
//the marked fragment
|
//the marked fragment
|
||||||
var textFragment = htmlEncode(inputSentence.slice(fragment['matchedPatternStart'], fragment['matchedPatternEnd']));
|
var textFragment = htmlEncode(inputSentence.slice(fragment['matchedPatternStart'], fragment['matchedPatternEnd']));
|
||||||
markedSentence += '<span onclick="secondStepSearch(this)" class="matchedFragment">'+textFragment+'</span>';
|
markedSentence += '<span onclick="secondStepSearch(this.innerHTML)" class="matchedFragment">'+textFragment+'</span>';
|
||||||
|
|
||||||
lastInsertedEnd = fragment['matchedPatternEnd'];
|
lastInsertedEnd = fragment['matchedPatternEnd'];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user