2015-09-01 17:29:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
/**
|
|
|
|
* @memberof OCA.Versions
|
|
|
|
*/
|
|
|
|
var VersionCollection = OC.Backbone.Collection.extend({
|
|
|
|
model: OCA.Versions.VersionModel,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var OCA.Files.FileInfoModel
|
|
|
|
*/
|
|
|
|
_fileInfo: null,
|
|
|
|
|
|
|
|
_endReached: false,
|
|
|
|
_currentIndex: 0,
|
|
|
|
|
|
|
|
url: function() {
|
|
|
|
var url = OC.generateUrl('/apps/files_versions/ajax/getVersions.php');
|
|
|
|
var query = {
|
|
|
|
source: this._fileInfo.getFullPath(),
|
|
|
|
start: this._currentIndex
|
|
|
|
};
|
|
|
|
return url + '?' + OC.buildQueryString(query);
|
|
|
|
},
|
|
|
|
|
|
|
|
setFileInfo: function(fileInfo) {
|
|
|
|
this._fileInfo = fileInfo;
|
|
|
|
// reset
|
|
|
|
this._endReached = false;
|
|
|
|
this._currentIndex = 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
getFileInfo: function() {
|
|
|
|
return this._fileInfo;
|
|
|
|
},
|
|
|
|
|
|
|
|
hasMoreResults: function() {
|
|
|
|
return !this._endReached;
|
|
|
|
},
|
|
|
|
|
|
|
|
fetch: function(options) {
|
|
|
|
if (!options || options.remove) {
|
|
|
|
this._currentIndex = 0;
|
|
|
|
}
|
|
|
|
return OC.Backbone.Collection.prototype.fetch.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch the next set of results
|
|
|
|
*/
|
|
|
|
fetchNext: function() {
|
|
|
|
if (!this.hasMoreResults()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (this._currentIndex === 0) {
|
|
|
|
return this.fetch();
|
|
|
|
}
|
|
|
|
return this.fetch({remove: false});
|
|
|
|
},
|
|
|
|
|
2015-10-01 10:10:50 +00:00
|
|
|
reset: function() {
|
|
|
|
this._currentIndex = 0;
|
|
|
|
OC.Backbone.Collection.prototype.reset.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
2015-09-01 17:29:55 +00:00
|
|
|
parse: function(result) {
|
2016-02-10 12:39:25 +00:00
|
|
|
var fullPath = this._fileInfo.getFullPath();
|
2015-09-01 17:29:55 +00:00
|
|
|
var results = _.map(result.data.versions, function(version) {
|
|
|
|
var revision = parseInt(version.version, 10);
|
|
|
|
return {
|
|
|
|
id: revision,
|
|
|
|
name: version.name,
|
2016-02-10 12:39:25 +00:00
|
|
|
fullPath: fullPath,
|
2015-09-01 17:29:55 +00:00
|
|
|
timestamp: revision,
|
2016-11-29 19:35:19 +00:00
|
|
|
size: version.size,
|
|
|
|
mimetype: version.mimetype
|
2015-09-01 17:29:55 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
this._endReached = result.data.endReached;
|
|
|
|
this._currentIndex += results.length;
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OCA.Versions = OCA.Versions || {};
|
|
|
|
|
|
|
|
OCA.Versions.VersionCollection = VersionCollection;
|
|
|
|
})();
|
|
|
|
|