pagination of results
This commit is contained in:
parent
e352e0a8b2
commit
785cb81386
@ -47,7 +47,6 @@
|
||||
|
||||
</div>
|
||||
<input type="hidden" id="current-offset" value="0" />
|
||||
<input type="hidden" id="current-pattern" value="" />
|
||||
<div id="occurences">
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,14 +1,21 @@
|
||||
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 = {
|
||||
operation: 'fullSearch',
|
||||
tmId: currentTmId,
|
||||
limit: pageLimit,
|
||||
offset: $('#current-offset').val(),
|
||||
pattern:caller.innerHTML
|
||||
pattern:searchQuery
|
||||
}
|
||||
|
||||
|
||||
$.ajax({
|
||||
url: '/cat/concordia_gate.php',
|
||||
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) {
|
||||
var pattern = $('#current-pattern').val();
|
||||
var offset = parseInt($('#current-offset').val());
|
||||
var begin = offset+1;
|
||||
var end = offset + pageLimit;
|
||||
var totalCount = parseInt(data['result']['totalCount']);
|
||||
$('body').data('currentTotalCount', totalCount);
|
||||
if (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++) {
|
||||
var occurence = data['result']['occurences'][j];
|
||||
@ -165,7 +193,7 @@ function renderResult(data) {
|
||||
|
||||
//the marked fragment
|
||||
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'];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user