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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-09-25 19:19:42 +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
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
setFileInfo: function(fileInfo) {
|
|
|
|
this._fileInfo = fileInfo
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
getFileInfo: function() {
|
|
|
|
return this._fileInfo
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
setCurrentUser: function(user) {
|
2019-09-25 19:19:42 +03:00
|
|
|
this._currentUser = user
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
getCurrentUser: function() {
|
2019-09-25 19:19:42 +03:00
|
|
|
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) {
|
2019-09-25 19:19:42 +03:00
|
|
|
this._client = client
|
2018-10-11 17:59:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getClient: function() {
|
|
|
|
return this._client || new OC.Files.Client({
|
|
|
|
host: OC.getHost(),
|
|
|
|
root: OC.linkToRemoteBase('dav') + '/versions/' + this.getCurrentUser(),
|
|
|
|
useHTTPS: OC.getProtocol() === 'https'
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2019-09-25 19:19:42 +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) {
|
2019-09-25 19:19:42 +03:00
|
|
|
var fullPath = this._fileInfo.getFullPath()
|
|
|
|
var fileId = this._fileInfo.get('id')
|
|
|
|
var name = this._fileInfo.get('name')
|
|
|
|
var user = this.getCurrentUser()
|
|
|
|
var client = this.getClient()
|
2018-10-11 17:59:04 +03:00
|
|
|
return _.map(result, function(version) {
|
2019-09-25 19:19:42 +03:00
|
|
|
version.fullPath = fullPath
|
|
|
|
version.fileId = fileId
|
|
|
|
version.name = name
|
|
|
|
version.timestamp = parseInt(moment(new Date(version.timestamp)).format('X'), 10)
|
|
|
|
version.id = OC.basename(version.href)
|
|
|
|
version.size = parseInt(version.size, 10)
|
|
|
|
version.user = user
|
|
|
|
version.client = client
|
|
|
|
return version
|
|
|
|
})
|
2015-09-01 20:29:55 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
})
|
2015-09-01 20:29:55 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
OCA.Versions = OCA.Versions || {}
|
2015-09-01 20:29:55 +03:00
|
|
|
|
2019-09-25 19:19:42 +03:00
|
|
|
OCA.Versions.VersionCollection = VersionCollection
|
|
|
|
})()
|