From 64ad99db70a18bafdbcf906dd400db6e0712fe29 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 1 Feb 2016 16:54:18 +0100 Subject: Better comments pagination logic --- apps/comments/js/commentcollection.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'apps') diff --git a/apps/comments/js/commentcollection.js b/apps/comments/js/commentcollection.js index eaa7a1d53fa..055752f327c 100644 --- a/apps/comments/js/commentcollection.js +++ b/apps/comments/js/commentcollection.js @@ -30,7 +30,7 @@ _objectId: null, _endReached: false, - _limit : 5, + _limit : 20, initialize: function(models, options) { options = options || {}; @@ -72,15 +72,10 @@ var body = '\n' + '\n' + - ' ' + this._limit + '\n'; - - if (this.length > 0) { - body += ' ' + this.last().get('creationDateTime') + '\n'; - } - - body += '\n'; - - var oldLength = this.length; + // load one more so we know there is more + ' ' + (this._limit + 1) + '\n' + + ' ' + this.length + '\n' + + '\n'; options = options || {}; var success = options.success; @@ -89,9 +84,12 @@ data: body, davProperties: CommentsCollection.prototype.model.prototype.davProperties, success: function(resp) { - if (resp.length === oldLength) { + if (resp.length <= self._limit) { // no new entries, end reached self._endReached = true; + } else { + // remove last entry, for next page load + resp = _.initial(resp); } if (!self.set(resp, options)) { return false; -- cgit v1.2.3