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
|
|
|
/* global moment */
|
|
|
|
|
|
|
|
(function () {
|
2015-09-01 20:29:55 +03:00
|
|
|
/**
|
|
|
|
* @memberof OCA.Versions
|
|
|
|
*/
|
|
|
|
var VersionModel = OC.Backbone.Model.extend({
|
2018-10-11 17:59:04 +03:00
|
|
|
sync: OC.Backbone.davSync,
|
|
|
|
|
|
|
|
davProperties: {
|
|
|
|
'size': '{DAV:}getcontentlength',
|
|
|
|
'mimetype': '{DAV:}getcontenttype',
|
|
|
|
'timestamp': '{DAV:}getlastmodified',
|
|
|
|
},
|
2015-09-01 20:29:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores the original file to this revision
|
|
|
|
*/
|
2018-10-11 17:59:04 +03:00
|
|
|
revert: function (options) {
|
2015-09-01 20:29:55 +03:00
|
|
|
options = options ? _.clone(options) : {};
|
|
|
|
var model = this;
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
var client = this.get('client');
|
|
|
|
|
|
|
|
return client.move('/versions/' + this.get('fileId') + '/' + this.get('id'), '/restore/target', true)
|
|
|
|
.done(function () {
|
|
|
|
if (options.success) {
|
|
|
|
options.success.call(options.context, model, {}, options);
|
|
|
|
}
|
|
|
|
model.trigger('revert', model, options);
|
|
|
|
})
|
|
|
|
.fail(function () {
|
|
|
|
if (options.error) {
|
|
|
|
options.error.call(options.context, model, {}, options);
|
2015-09-01 20:29:55 +03:00
|
|
|
}
|
2018-10-11 17:59:04 +03:00
|
|
|
model.trigger('error', model, {}, options);
|
|
|
|
});
|
2015-09-01 20:29:55 +03:00
|
|
|
},
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
getFullPath: function () {
|
2015-09-01 20:29:55 +03:00
|
|
|
return this.get('fullPath');
|
|
|
|
},
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
getPreviewUrl: function () {
|
2015-09-01 20:29:55 +03:00
|
|
|
var url = OC.generateUrl('/apps/files_versions/preview');
|
|
|
|
var params = {
|
|
|
|
file: this.get('fullPath'),
|
|
|
|
version: this.get('timestamp')
|
|
|
|
};
|
|
|
|
return url + '?' + OC.buildQueryString(params);
|
|
|
|
},
|
|
|
|
|
2018-10-11 17:59:04 +03:00
|
|
|
getDownloadUrl: function () {
|
|
|
|
return OC.linkToRemoteBase('dav') + '/versions/' + this.get('user') + '/versions/' + this.get('fileId') + '/' + this.get('id');
|
2015-09-01 20:29:55 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
OCA.Versions = OCA.Versions || {};
|
|
|
|
|
|
|
|
OCA.Versions.VersionModel = VersionModel;
|
|
|
|
})();
|
|
|
|
|