Commit f0f7fe2c by kevalbhatt Committed by Madhan Neethiraj

ATLAS-1816: button to navigate to next page in search-result is disabled incorrectly

parent 0cccec93
...@@ -235,20 +235,16 @@ define(['require', ...@@ -235,20 +235,16 @@ define(['require',
} }
} }
}, },
fetchCollection: function(value, deleteChecked) { fetchCollection: function(value, clickObj) {
var that = this; var that = this;
this.showLoader(); this.showLoader();
if (Globals.searchApiCallRef && Globals.searchApiCallRef.readyState === 1) { if (Globals.searchApiCallRef && Globals.searchApiCallRef.readyState === 1) {
Globals.searchApiCallRef.abort(); Globals.searchApiCallRef.abort();
} }
if (value && !value.paginationChange) { if (value) {
$.extend(this.searchCollection.queryParams, { limit: this.limit }); $.extend(this.searchCollection.queryParams, { limit: this.limit, excludeDeletedEntities: true });
if (value.searchType) { if (value.searchType) {
this.searchCollection.url = UrlLinks.searchApiUrl(value.searchType); this.searchCollection.url = UrlLinks.searchApiUrl(value.searchType);
if (deleteChecked === undefined) {
$.extend(this.searchCollection.queryParams, { limit: this.limit, excludeDeletedEntities: true });
}
this.offset = 0;
} }
_.extend(this.searchCollection.queryParams, { 'query': (value.query ? value.query.trim() : null), 'typeName': value.type || null, 'classification': value.tag || null }); _.extend(this.searchCollection.queryParams, { 'query': (value.query ? value.query.trim() : null), 'typeName': value.type || null, 'classification': value.tag || null });
} }
...@@ -259,54 +255,45 @@ define(['require', ...@@ -259,54 +255,45 @@ define(['require',
if (!(that.ui.pageRecordText instanceof jQuery)) { if (!(that.ui.pageRecordText instanceof jQuery)) {
return; return;
} }
if (value) {
if (that.searchCollection.models.length < that.limit) { if (that.searchCollection.models.length < that.limit) {
that.ui.nextData.attr('disabled', true); that.ui.nextData.attr('disabled', true);
} } else {
if (that.offset === 0) { that.ui.nextData.attr('disabled', false);
that.pageFrom = 1; }
that.pageTo = that.limit; if (that.offset === 0) {
if (that.searchCollection.length > 0) { that.pageFrom = 1;
that.ui.pageRecordText.html("Showing " + that.pageFrom + " - " + that.searchCollection.length); that.pageTo = that.limit;
} } else if (clickObj && clickObj.next) {
} else if (that.searchCollection.models.length && !that.previousClick) { //on next click, adding "1" for showing the another records.
//on next click, adding "1" for showing the another records.. that.pageTo = that.offset + that.limit;
that.pageFrom = that.pageTo + 1; that.pageFrom = that.offset + 1;
that.pageTo = that.pageTo + that.searchCollection.models.length; } else if (clickObj && clickObj.previous) {
if (that.pageFrom && that.pageTo) { that.pageTo = that.pageTo - that.limit;
that.ui.pageRecordText.html("Showing " + that.pageFrom + " - " + that.pageTo); that.pageFrom = (that.pageTo - that.limit) + 1;
} }
} else if (that.previousClick) { that.ui.pageRecordText.html("Showing <u>" + that.searchCollection.models.length + " records</u>, from " + that.pageFrom + " - " + that.pageTo);
that.pageTo = (that.pageTo - (that.pageTo - that.pageFrom)) - 1; if (that.offset < that.limit && that.pageFrom < 26) {
//if limit is 0 then result is change to 1 because page count is showing from 1 that.ui.previousData.attr('disabled', true);
that.pageFrom = (that.pageFrom - that.limit === 0 ? 1 : that.pageFrom - that.limit);
that.ui.pageRecordText.html("Showing " + that.pageFrom + " - " + that.pageTo);
}
if (that.offset < that.limit) {
that.ui.previousData.attr('disabled', true);
}
if (that.searchCollection.models.length === 0) {
that.offset = that.offset - that.limit;
}
} }
that.renderTableLayoutView(); that.renderTableLayoutView();
if (value) {
var resultArr = []; var resultArr = [];
if (that.searchCollection.queryParams.typeName) { if (that.searchCollection.queryParams.typeName) {
resultArr.push(that.searchCollection.queryParams.typeName) resultArr.push(that.searchCollection.queryParams.typeName)
} }
if (that.searchCollection.queryParams.classification) { if (that.searchCollection.queryParams.classification) {
resultArr.push(that.searchCollection.queryParams.classification) resultArr.push(that.searchCollection.queryParams.classification)
}
if (that.searchCollection.queryParams.query) {
resultArr.push(that.searchCollection.queryParams.query)
}
var searchString = 'Results for <b>' + _.escape(resultArr.join(that.searchType == 'Advanced Search' ? " " : " & ")) + '</b>';
if (Globals.entityCreate && Globals.entityTypeConfList && Utils.getUrlState.isSearchTab()) {
searchString += "<p>If you do not find the entity in search result below then you can" + '<a href="javascript:void(0)" data-id="createEntity"> create new entity</a></p>';
}
that.$('.searchResult').html(searchString);
} }
if (that.searchCollection.queryParams.query) {
resultArr.push(that.searchCollection.queryParams.query)
}
var searchString = 'Results for <b>' + _.escape(resultArr.join(that.searchType == 'Advanced Search' ? " " : " & ")) + '</b>';
if (Globals.entityCreate && Globals.entityTypeConfList && Utils.getUrlState.isSearchTab()) {
searchString += "<p>If you do not find the entity in search result below then you can" + '<a href="javascript:void(0)" data-id="createEntity"> create new entity</a></p>';
}
that.$('.searchResult').html(searchString);
}, },
silent: true, silent: true,
reset: true reset: true
...@@ -611,8 +598,9 @@ define(['require', ...@@ -611,8 +598,9 @@ define(['require',
$.extend(this.searchCollection.queryParams, { $.extend(this.searchCollection.queryParams, {
offset: that.offset offset: that.offset
}); });
this.previousClick = false; this.fetchCollection(null, {
this.fetchCollection({ paginationChange: true }); next: true
});
}, },
onClickpreviousData: function() { onClickpreviousData: function() {
var that = this; var that = this;
...@@ -621,8 +609,9 @@ define(['require', ...@@ -621,8 +609,9 @@ define(['require',
$.extend(this.searchCollection.queryParams, { $.extend(this.searchCollection.queryParams, {
offset: that.offset offset: that.offset
}); });
this.previousClick = true; this.fetchCollection(null, {
this.fetchCollection({ paginationChange: true }); previous: true
});
}, },
onClickEditEntity: function(e) { onClickEditEntity: function(e) {
...@@ -663,7 +652,7 @@ define(['require', ...@@ -663,7 +652,7 @@ define(['require',
} else { } else {
$.extend(this.searchCollection.queryParams, { limit: this.limit, excludeDeletedEntities: true }); $.extend(this.searchCollection.queryParams, { limit: this.limit, excludeDeletedEntities: true });
} }
this.fetchCollection(this.value, e.target.checked); this.fetchCollection();
} }
}); });
return SearchResultLayoutView; return SearchResultLayoutView;
......
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