(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
_objectId: null,
_endReached: false,
- _currentIndex: 0,
+ _limit : 5,
initialize: function(models, options) {
options = options || {};
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 = '<?xml version="1.0" encoding="utf-8" ?>\n' +
+ '<D:report xmlns:D="DAV:" xmlns:oc="http://owncloud.org/ns">\n' +
+ ' <oc:limit>' + this._limit + '</oc:limit>\n';
+
+ if (this.length > 0) {
+ body += ' <oc:datetime>' + this.first().get('creationDateTime') + '</oc:datetime>\n';
}
- return this.fetch({remove: false});
- },
- reset: function() {
- this._currentIndex = 0;
- OC.Backbone.Collection.prototype.reset.apply(this, arguments);
+ body += '</D:report>\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);
}
});
' </ul>' +
'</div>' +
'<div class="empty hidden">{{emptyResultLabel}}</div>' +
- /*
'<input type="button" class="showMore hidden" value="{{moreLabel}}"' +
' name="show-more" id="show-more" />' +
- */
'<div class="loading hidden" style="height: 50px"></div>';
var COMMENT_TEMPLATE =
className: 'tab commentsTabView',
events: {
- 'submit .newCommentForm': '_onSubmitComment'
+ 'submit .newCommentForm': '_onSubmitComment',
+ 'click .showMore': '_onClickShowMore'
},
initialize: function() {
this.collection.fetchNext();
},
- _onClickShowMoreVersions: function(ev) {
+ _onClickShowMore: function(ev) {
ev.preventDefault();
this.nextPage();
},
* @param {Object} davProperties properties mapping
*/
function parsePropFindResult(result, davProperties) {
+ if (_.isArray(result)) {
+ return _.map(result, function(subResult) {
+ return parsePropFindResult(subResult, davProperties);
+ });
+ }
var props = {
href: result.href
};
if (isSuccessStatus(response.status)) {
if (_.isFunction(options.success)) {
var propsMapping = _.invert(options.davProperties);
- var results;
+ var results = parsePropFindResult(response.body, propsMapping);
if (options.depth > 0) {
- results = _.map(response.body, function(data) {
- return parsePropFindResult(data, propsMapping);
- });
// discard root entry
results.shift();
- } else {
- results = parsePropFindResult(response.body, propsMapping);
}
options.success(results);
options.success(responseJson);
return;
}
- options.success(result.body);
+ // if multi-status, parse
+ if (result.status === 207) {
+ var propsMapping = _.invert(options.davProperties);
+ options.success(parsePropFindResult(result.body, propsMapping));
+ } else {
+ options.success(result.body);
+ }
}
});
}
* DAV transport
*/
function davSync(method, model, options) {
- var params = {type: methodMap[method]};
+ var params = {type: methodMap[method] || method};
var isCollection = (model instanceof Backbone.Collection);
if (method === 'update' && (model.usePUT || (model.collection && model.collection.usePUT))) {
if (typeof dav == 'undefined') { dav = {}; };
dav._XML_CHAR_MAP = {
- '<': '<',
- '>': '>',
- '&': '&',
- '"': '"',
- "'": '''
+ '<': '<',
+ '>': '>',
+ '&': '&',
+ '"': '"',
+ "'": '''
};
dav._escapeXml = function(s) {
- return s.replace(/[<>&"']/g, function (ch) {
- return dav._XML_CHAR_MAP[ch];
- });
+ return s.replace(/[<>&"']/g, function (ch) {
+ return dav._XML_CHAR_MAP[ch];
+ });
};
dav.Client = function(options) {
return this.request('PROPFIND', url, headers, body).then(
function(result) {
- var resultBody = this.parseMultiStatus(result.body);
if (depth===0) {
return {
status: result.status,
- body: resultBody[0],
+ body: result.body[0],
xhr: result.xhr
};
} else {
return {
status: result.status,
- body: resultBody,
+ body: result.body,
xhr: result.xhr
};
}
*/
request : function(method, url, headers, body) {
+ var self = this;
var xhr = this.xhrProvider();
if (this.userName) {
return;
}
+ var resultBody = xhr.response;
+ if (xhr.status === 207) {
+ resultBody = self.parseMultiStatus(xhr.response);
+ }
+
fulfill({
- body: xhr.response,
+ body: resultBody,
status: xhr.status,
xhr: xhr
});