2b235279 by Adam Heath

Refactored, to increase coverage, and remove duplicate code paths.

1 parent bd7f86a9
......@@ -27,11 +27,18 @@ define(function(require) {
var currentPage = parseInt(this.get('currentPage'));
var pageSize = parseInt(this.get('pageSize'));
var totalCount = parseInt(this.get('totalCount'));
if (!currentPage || !pageSize || !totalCount) {
if (!totalCount) {
return;
}
var pages = [];
var totalPages = Math.floor((totalCount + pageSize - 1) / pageSize);
if (currentPage < 0) {
this.set('currentPage', 1);
return;
} else if (currentPage > totalPages) {
this.set('currentPage', totalPages);
return;
}
function addPage(self, i) {
pages.push({
current: i === currentPage,
......@@ -59,9 +66,7 @@ define(function(require) {
}
for (var i = startAt; i < endAt; i++) {
if (i > 0 && i <= totalPages) {
addPage(this, i);
}
addPage(this, i);
}
var hasPrevious = currentPage > 1;
var hasNext = currentPage < totalPages;
......@@ -89,21 +94,6 @@ define(function(require) {
totalPages: totalPages,
});
};
this.on('change:pageSize change:currentPage change:totalCount', function() {
var currentPage = parseInt(this.get('currentPage'));
var pageSize = parseInt(this.get('pageSize'));
var totalCount = parseInt(this.get('totalCount'));
if (!currentPage || !pageSize || !totalCount) {
return;
}
var pages = [];
var totalPages = Math.floor((totalCount + pageSize - 1) / pageSize);
if (currentPage < 0) {
this.set('currentPage', 1);
} else if (currentPage > totalPages) {
this.set('currentPage', totalPages);
}
}, this);
this.on('change:pageSize change:currentPage change:totalCount', buildPages, this);
var installActions = _.bind(function installActions(eventName, nextName, hasNextName, previousName, hasPreviousName, pageCount) {
this.on(eventName, function() {
......