You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

versionmodel.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2015
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. (function() {
  11. /**
  12. * @memberof OCA.Versions
  13. */
  14. var VersionModel = OC.Backbone.Model.extend({
  15. sync: OC.Backbone.davSync,
  16. davProperties: {
  17. 'size': '{DAV:}getcontentlength',
  18. 'mimetype': '{DAV:}getcontenttype',
  19. 'timestamp': '{DAV:}getlastmodified'
  20. },
  21. /**
  22. * Restores the original file to this revision
  23. *
  24. * @param {Object} [options] options
  25. * @returns {Promise}
  26. */
  27. revert: function(options) {
  28. options = options ? _.clone(options) : {}
  29. var model = this
  30. var client = this.get('client')
  31. return client.move('/versions/' + this.get('fileId') + '/' + this.get('id'), '/restore/target', true)
  32. .done(function() {
  33. if (options.success) {
  34. options.success.call(options.context, model, {}, options)
  35. }
  36. model.trigger('revert', model, options)
  37. })
  38. .fail(function() {
  39. if (options.error) {
  40. options.error.call(options.context, model, {}, options)
  41. }
  42. model.trigger('error', model, {}, options)
  43. })
  44. },
  45. getFullPath: function() {
  46. return this.get('fullPath')
  47. },
  48. getPreviewUrl: function() {
  49. var url = OC.generateUrl('/apps/files_versions/preview')
  50. var params = {
  51. file: this.get('fullPath'),
  52. version: this.get('id')
  53. }
  54. return url + '?' + OC.buildQueryString(params)
  55. },
  56. getDownloadUrl: function() {
  57. return OC.linkToRemoteBase('dav') + '/versions/' + this.get('user') + '/versions/' + this.get('fileId') + '/' + this.get('id')
  58. }
  59. })
  60. OCA.Versions = OCA.Versions || {}
  61. OCA.Versions.VersionModel = VersionModel
  62. })()