Add pagination support for comments GUI
This commit is contained in:
parent
d1518045ec
commit
29386eccf9
|
@ -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();
|
||||
}
|
||||
return this.fetch({remove: false});
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this._currentIndex = 0;
|
||||
OC.Backbone.Collection.prototype.reset.apply(this, arguments);
|
||||
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';
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -19,10 +19,8 @@
|
|||
' </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 =
|
||||
|
@ -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();
|
||||
},
|
||||
|
|
|
@ -76,6 +76,11 @@
|
|||
* @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
|
||||
};
|
||||
|
@ -151,15 +156,10 @@
|
|||
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);
|
||||
|
@ -217,7 +217,13 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -249,7 +255,7 @@
|
|||
* 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))) {
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
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) {
|
||||
|
@ -79,17 +79,16 @@ dav.Client.prototype = {
|
|||
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
|
||||
};
|
||||
}
|
||||
|
@ -161,6 +160,7 @@ dav.Client.prototype = {
|
|||
*/
|
||||
request : function(method, url, headers, body) {
|
||||
|
||||
var self = this;
|
||||
var xhr = this.xhrProvider();
|
||||
|
||||
if (this.userName) {
|
||||
|
@ -182,8 +182,13 @@ dav.Client.prototype = {
|
|||
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
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue