From 29386eccf96aec3e6a4c776f43e74c95474697bb Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 28 Jan 2016 14:24:12 +0100 Subject: Add pagination support for comments GUI --- apps/comments/js/commentcollection.js | 54 +++++++++++++++++++++++++++-------- apps/comments/js/commentstabview.js | 7 ++--- 2 files changed, 45 insertions(+), 16 deletions(-) (limited to 'apps/comments/js') diff --git a/apps/comments/js/commentcollection.js b/apps/comments/js/commentcollection.js index 61b5adb7da7..1fda4a4c709 100644 --- a/apps/comments/js/commentcollection.js +++ b/apps/comments/js/commentcollection.js @@ -10,9 +10,7 @@ (function(OC, OCA) { - function filterFunction(model, term) { - return model.get('name').substr(0, term.length) === term; - } + var NS_OWNCLOUD = 'http://owncloud.org/ns'; /** * @class OCA.Comments.CommentsCollection @@ -32,7 +30,7 @@ _objectId: null, _endReached: false, - _currentIndex: 0, + _limit : 5, initialize: function(models, options) { options = options || {}; @@ -58,22 +56,54 @@ return !this._endReached; }, + reset: function() { + this._endReached = false; + return OC.Backbone.Collection.prototype.reset.apply(this, arguments); + }, + /** * Fetch the next set of results */ - fetchNext: function() { + fetchNext: function(options) { + var self = this; if (!this.hasMoreResults()) { return null; } - if (this._currentIndex === 0) { - return this.fetch(); + + var body = '\n' + + '\n' + + ' ' + this._limit + '\n'; + + if (this.length > 0) { + body += ' ' + this.first().get('creationDateTime') + '\n'; } - return this.fetch({remove: false}); - }, - reset: function() { - this._currentIndex = 0; - OC.Backbone.Collection.prototype.reset.apply(this, arguments); + body += '\n'; + + var oldLength = this.length; + + options = options || {}; + var success = options.success; + options = _.extend({ + remove: false, + data: body, + davProperties: CommentsCollection.prototype.model.prototype.davProperties, + success: function(resp) { + if (resp.length === oldLength) { + // no new entries, end reached + self._endReached = true; + } + if (!self.set(resp, options)) { + return false; + } + if (success) { + success.apply(null, arguments); + } + self.trigger('sync', 'REPORT', self, options); + } + }, options); + + return this.sync('REPORT', this, options); } }); diff --git a/apps/comments/js/commentstabview.js b/apps/comments/js/commentstabview.js index b1a3f854fe1..6e511732803 100644 --- a/apps/comments/js/commentstabview.js +++ b/apps/comments/js/commentstabview.js @@ -19,10 +19,8 @@ ' ' + '' + '' + - /* '' + - */ ''; var COMMENT_TEMPLATE = @@ -44,7 +42,8 @@ className: 'tab commentsTabView', events: { - 'submit .newCommentForm': '_onSubmitComment' + 'submit .newCommentForm': '_onSubmitComment', + 'click .showMore': '_onClickShowMore' }, initialize: function() { @@ -144,7 +143,7 @@ this.collection.fetchNext(); }, - _onClickShowMoreVersions: function(ev) { + _onClickShowMore: function(ev) { ev.preventDefault(); this.nextPage(); }, -- cgit v1.2.3