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.

versioncollection.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 VersionCollection = OC.Backbone.Collection.extend({
  15. model: OCA.Versions.VersionModel,
  16. sync: OC.Backbone.davSync,
  17. /**
  18. * @var OCA.Files.FileInfoModel
  19. */
  20. _fileInfo: null,
  21. _currentUser: null,
  22. _client: null,
  23. setFileInfo: function(fileInfo) {
  24. this._fileInfo = fileInfo
  25. },
  26. getFileInfo: function() {
  27. return this._fileInfo
  28. },
  29. setCurrentUser: function(user) {
  30. this._currentUser = user
  31. },
  32. getCurrentUser: function() {
  33. return this._currentUser || OC.getCurrentUser().uid
  34. },
  35. setClient: function(client) {
  36. this._client = client
  37. },
  38. getClient: function() {
  39. return this._client || new OC.Files.Client({
  40. host: OC.getHost(),
  41. root: OC.linkToRemoteBase('dav') + '/versions/' + this.getCurrentUser(),
  42. useHTTPS: OC.getProtocol() === 'https'
  43. })
  44. },
  45. url: function() {
  46. return OC.linkToRemoteBase('dav') + '/versions/' + this.getCurrentUser() + '/versions/' + this._fileInfo.get('id')
  47. },
  48. parse: function(result) {
  49. var fullPath = this._fileInfo.getFullPath()
  50. var fileId = this._fileInfo.get('id')
  51. var name = this._fileInfo.get('name')
  52. var user = this.getCurrentUser()
  53. var client = this.getClient()
  54. return _.map(result, function(version) {
  55. version.fullPath = fullPath
  56. version.fileId = fileId
  57. version.name = name
  58. version.timestamp = parseInt(moment(new Date(version.timestamp)).format('X'), 10)
  59. version.id = OC.basename(version.href)
  60. version.size = parseInt(version.size, 10)
  61. version.user = user
  62. version.client = client
  63. return version
  64. })
  65. }
  66. })
  67. OCA.Versions = OCA.Versions || {}
  68. OCA.Versions.VersionCollection = VersionCollection
  69. })()