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
|
|
|
|
*/
|
2019-11-13 15:05:10 +03:00
|
|
|
const VersionModel = OC.Backbone.Model.extend({
|
2018-10-11 17:59:04 +03:00
|
|
|
sync: OC.Backbone.davSync,
|
|
|
|
|
|
|
|
davProperties: {
|
2020-07-31 10:31:39 +03:00
|
|
|
size: '{DAV:}getcontentlength',
|
|
|
|
mimetype: '{DAV:}getcontenttype',
|
|
|
|
timestamp: '{DAV:}getlastmodified',
|
2018-10-11 17:59:04 +03:00
|
|
|
},
|
2015-09-01 20:29:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores the original file to this revision
|
2019-09-25 19:19:42 +03:00
|
|
|
*
|
|
|
|
* @param {Object} [options] options
|
|
|
|
* @returns {Promise}
|
2015-09-01 20:29:55 +03:00
|
|
|
*/
|
2020-07-31 10:26:43 +03:00
|
|
|
revert(options) {
|
2019-09-25 19:19:42 +03:00
|
|
|
options = options ? _.clone(options) : {}
|
2019-11-13 15:05:10 +03:00
|
|
|
const model = this
|
2015-09-01 20:29:55 +03:00
|
|
|
|
2019-11-13 15:05:10 +03:00
|
|
|
const client = this.get('client')
|
2018-10-11 17:59:04 +03:00
|
|
|
|
|
|
|
return client.move('/versions/' + this.get('fileId') + '/' + this.get('id'), '/restore/target', true)
|
2019-09-25 19:19:42 +03:00
|
|
|
.done(function() {
|
2018-10-11 17:59:04 +03:00
|
|
|
if (options.success) {
|
2019-09-25 19:19:42 +03:00
|
|
|
options.success.call(options.context, model, {}, options)
|
2018-10-11 17:59:04 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
model.trigger('revert', model, options)
|
2018-10-11 17:59:04 +03:00
|
|
|
})
|
2019-09-25 19:19:42 +03:00
|
|
|
.fail(function() {
|
2018-10-11 17:59:04 +03:00
|
|
|
if (options.error) {
|
2019-09-25 19:19:42 +03:00
|
|
|
options.error.call(options.context, model, {}, options)
|
2015-09-01 20:29:55 +03:00
|
|
|
}
|
2019-09-25 19:19:42 +03:00
|
|
|
model.trigger('error', model, {}, options)
|
|
|
|
})
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2020-07-31 10:26:43 +03:00
|
|
|
getFullPath() {
|
2019-09-25 19:19:42 +03:00
|
|
|
return this.get('fullPath')
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2020-07-31 10:26:43 +03:00
|
|
|
getPreviewUrl() {
|
2019-11-13 15:05:10 +03:00
|
|
|
const url = OC.generateUrl('/apps/files_versions/preview')
|
|
|
|
const params = {
|
2015-09-01 20:29:55 +03:00
|
|
|
file: this.get('fullPath'),
|
2019-11-13 15:05:10 +03:00
|
|
|
version: this.get('id'),
|
2019-09-25 19:19:42 +03:00
|
|
|
}
|
|
|
|
return url + '?' + OC.buildQueryString(params)
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2020-07-31 10:26:43 +03:00
|
|
|
getDownloadUrl() {
|
2019-09-25 19:19:42 +03:00
|
|
|
return OC.linkToRemoteBase('dav') + '/versions/' + this.get('user') + '/versions/' + this.get('fileId') + '/' + this.get('id')
|
2019-11-13 15:05:10 +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.VersionModel = VersionModel
|
|
|
|
})()
|