2016-01-27 17:28:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function(OC, OCA) {
|
|
|
|
|
2016-01-28 13:24:12 +00:00
|
|
|
var NS_OWNCLOUD = 'http://owncloud.org/ns';
|
2016-01-27 17:28:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class OCA.Comments.CommentsCollection
|
|
|
|
* @classdesc
|
|
|
|
*
|
|
|
|
* Collection of comments assigned to a file
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
var CommentsCollection = OC.Backbone.Collection.extend(
|
|
|
|
/** @lends OCA.Comments.CommentsCollection.prototype */ {
|
|
|
|
|
|
|
|
sync: OC.Backbone.davSync,
|
|
|
|
|
|
|
|
model: OCA.Comments.CommentModel,
|
|
|
|
|
|
|
|
_objectType: 'files',
|
|
|
|
_objectId: null,
|
|
|
|
|
|
|
|
_endReached: false,
|
2016-02-01 15:54:18 +00:00
|
|
|
_limit : 20,
|
2016-01-27 17:28:55 +00:00
|
|
|
|
|
|
|
initialize: function(models, options) {
|
|
|
|
options = options || {};
|
|
|
|
if (options.objectType) {
|
|
|
|
this._objectType = options.objectType;
|
|
|
|
}
|
|
|
|
if (options.objectId) {
|
|
|
|
this._objectId = options.objectId;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
url: function() {
|
|
|
|
return OC.linkToRemote('dav') + '/comments/' +
|
|
|
|
encodeURIComponent(this._objectType) + '/' +
|
|
|
|
encodeURIComponent(this._objectId) + '/';
|
|
|
|
},
|
|
|
|
|
|
|
|
setObjectId: function(objectId) {
|
|
|
|
this._objectId = objectId;
|
|
|
|
},
|
|
|
|
|
|
|
|
hasMoreResults: function() {
|
|
|
|
return !this._endReached;
|
|
|
|
},
|
|
|
|
|
2016-01-28 13:24:12 +00:00
|
|
|
reset: function() {
|
|
|
|
this._endReached = false;
|
|
|
|
return OC.Backbone.Collection.prototype.reset.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
2016-01-27 17:28:55 +00:00
|
|
|
/**
|
|
|
|
* Fetch the next set of results
|
|
|
|
*/
|
2016-01-28 13:24:12 +00:00
|
|
|
fetchNext: function(options) {
|
|
|
|
var self = this;
|
2016-01-27 17:28:55 +00:00
|
|
|
if (!this.hasMoreResults()) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-01-28 13:24:12 +00:00
|
|
|
|
|
|
|
var body = '<?xml version="1.0" encoding="utf-8" ?>\n' +
|
|
|
|
'<D:report xmlns:D="DAV:" xmlns:oc="http://owncloud.org/ns">\n' +
|
2016-02-01 15:54:18 +00:00
|
|
|
// load one more so we know there is more
|
|
|
|
' <oc:limit>' + (this._limit + 1) + '</oc:limit>\n' +
|
|
|
|
' <oc:offset>' + this.length + '</oc:offset>\n' +
|
|
|
|
'</D:report>\n';
|
2016-01-28 13:24:12 +00:00
|
|
|
|
|
|
|
options = options || {};
|
|
|
|
var success = options.success;
|
|
|
|
options = _.extend({
|
|
|
|
remove: false,
|
|
|
|
data: body,
|
|
|
|
davProperties: CommentsCollection.prototype.model.prototype.davProperties,
|
|
|
|
success: function(resp) {
|
2016-02-01 15:54:18 +00:00
|
|
|
if (resp.length <= self._limit) {
|
2016-01-28 13:24:12 +00:00
|
|
|
// no new entries, end reached
|
|
|
|
self._endReached = true;
|
2016-02-01 15:54:18 +00:00
|
|
|
} else {
|
|
|
|
// remove last entry, for next page load
|
|
|
|
resp = _.initial(resp);
|
2016-01-28 13:24:12 +00:00
|
|
|
}
|
|
|
|
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);
|
2016-01-27 17:28:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OCA.Comments.CommentsCollection = CommentsCollection;
|
|
|
|
})(OC, OCA);
|
|
|
|
|