versionmodel.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /**
  16. * Restores the original file to this revision
  17. */
  18. revert: function(options) {
  19. options = options ? _.clone(options) : {};
  20. var model = this;
  21. var file = this.getFullPath();
  22. var revision = this.get('timestamp');
  23. $.ajax({
  24. type: 'GET',
  25. url: OC.generateUrl('/apps/files_versions/ajax/rollbackVersion.php'),
  26. dataType: 'json',
  27. data: {
  28. file: file,
  29. revision: revision
  30. },
  31. success: function(response) {
  32. if (response.status === 'error') {
  33. if (options.error) {
  34. options.error.call(options.context, model, response, options);
  35. }
  36. model.trigger('error', model, response, options);
  37. } else {
  38. if (options.success) {
  39. options.success.call(options.context, model, response, options);
  40. }
  41. model.trigger('revert', model, response, options);
  42. }
  43. }
  44. });
  45. },
  46. getFullPath: function() {
  47. return this.get('fullPath');
  48. },
  49. getPreviewUrl: function() {
  50. var url = OC.generateUrl('/apps/files_versions/preview');
  51. var params = {
  52. file: this.get('fullPath'),
  53. version: this.get('timestamp')
  54. };
  55. return url + '?' + OC.buildQueryString(params);
  56. },
  57. getDownloadUrl: function() {
  58. var url = OC.generateUrl('/apps/files_versions/download.php');
  59. var params = {
  60. file: this.get('fullPath'),
  61. revision: this.get('timestamp')
  62. };
  63. return url + '?' + OC.buildQueryString(params);
  64. }
  65. });
  66. OCA.Versions = OCA.Versions || {};
  67. OCA.Versions.VersionModel = VersionModel;
  68. })();