2015-09-01 20:29:55 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
(function () {
|
2015-09-01 20:29:55 +03:00
|
|
|
/**
|
|
|
|
* @memberof OCA.Versions
|
|
|
|
*/
|
|
|
|
var VersionCollection = OC.Backbone.Collection.extend({
|
|
|
|
model: OCA.Versions.VersionModel,
|
2018-10-11 17:59:04 +03:00
|
|
|
sync: OC.Backbone.davSync,
|
2015-09-01 20:29:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var OCA.Files.FileInfoModel
|
|
|
|
*/
|
|
|
|
_fileInfo: null,
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
_currentUser: null,
|
2015-09-01 20:29:55 +03:00
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
_client: null,
|
2015-09-01 20:29:55 +03:00
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
setFileInfo: function (fileInfo) {
|
2015-09-01 20:29:55 +03:00
|
|
|
this._fileInfo = fileInfo;
|
|
|
|
},
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
getFileInfo: function () {
|
2015-09-01 20:29:55 +03:00
|
|
|
return this._fileInfo;
|
|
|
|
},
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
setCurrentUser: function(user) {
|
|
|
|
this._currentUser = user;
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
getCurrentUser: function() {
|
|
|
|
return this._currentUser || OC.getCurrentUser().uid;
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
setClient: function(client) {
|
|
|
|
this._client = client;
|
|
|
|
},
|
|
|
|
|
|
|
|
getClient: function() {
|
|
|
|
return this._client || new OC.Files.Client({
|
|
|
|
host: OC.getHost(),
|
|
|
|
root: OC.linkToRemoteBase('dav') + '/versions/' + this.getCurrentUser(),
|
|
|
|
useHTTPS: OC.getProtocol() === 'https'
|
|
|
|
});
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
url: function () {
|
|
|
|
return OC.linkToRemoteBase('dav') + '/versions/' + this.getCurrentUser() + '/versions/' + this._fileInfo.get('id');
|
2015-10-01 13:10:50 +03:00
|
|
|
},
|
|
|
|
|
2015-09-01 20:29:55 +03:00
|
|
|
parse: function(result) {
|
2016-02-10 15:39:25 +03:00
|
|
|
var fullPath = this._fileInfo.getFullPath();
|
2018-10-11 17:59:04 +03:00
|
|
|
var fileId = this._fileInfo.get('id');
|
|
|
|
var name = this._fileInfo.get('name');
|
|
|
|
var user = this.getCurrentUser();
|
|
|
|
var client = this.getClient();
|
|
|
|
return _.map(result, function(version) {
|
|
|
|
version.fullPath = fullPath;
|
|
|
|
version.fileId = fileId;
|
|
|
|
version.name = name;
|
|
|
|
version.timestamp = parseInt(moment(new Date(version.timestamp)).format('X'), 10);
|
|
|
|
version.id = parseInt(OC.basename(version.href), 10);
|
|
|
|
version.size = parseInt(version.size, 10);
|
|
|
|
version.user = user;
|
|
|
|
version.client = client;
|
|
|
|
return version;
|
2015-09-01 20:29:55 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OCA.Versions = OCA.Versions || {};
|
|
|
|
|
|
|
|
OCA.Versions.VersionCollection = VersionCollection;
|
|
|
|
})();
|
|
|
|
|