recentfilelist.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
  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. // HACK: this piece needs to be loaded AFTER the files app (for unit tests)
  11. window.addEventListener('DOMContentLoaded', function () {
  12. (function (OCA) {
  13. /**
  14. * @class OCA.Files.RecentFileList
  15. * @augments OCA.Files.RecentFileList
  16. *
  17. * @classdesc Recent file list.
  18. * Displays the list of recently modified files
  19. *
  20. * @param $el container element with existing markup for the #controls
  21. * and a table
  22. * @param [options] map of options, see other parameters
  23. */
  24. var RecentFileList = function ($el, options) {
  25. options.sorting = {
  26. mode: 'mtime',
  27. direction: 'desc'
  28. };
  29. this.initialize($el, options);
  30. this._allowSorting = false;
  31. };
  32. RecentFileList.prototype = _.extend({}, OCA.Files.FileList.prototype,
  33. /** @lends OCA.Files.RecentFileList.prototype */ {
  34. id: 'recent',
  35. appName: t('files', 'Recent'),
  36. _clientSideSort: true,
  37. _allowSelection: false,
  38. /**
  39. * @private
  40. */
  41. initialize: function () {
  42. OCA.Files.FileList.prototype.initialize.apply(this, arguments);
  43. if (this.initialized) {
  44. return;
  45. }
  46. OC.Plugins.attach('OCA.Files.RecentFileList', this);
  47. },
  48. updateEmptyContent: function () {
  49. var dir = this.getCurrentDirectory();
  50. if (dir === '/') {
  51. // root has special permissions
  52. this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty);
  53. this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty);
  54. }
  55. else {
  56. OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments);
  57. }
  58. },
  59. getDirectoryPermissions: function () {
  60. return OC.PERMISSION_READ | OC.PERMISSION_DELETE;
  61. },
  62. updateStorageStatistics: function () {
  63. // no op because it doesn't have
  64. // storage info like free space / used space
  65. },
  66. reload: function () {
  67. this.showMask();
  68. if (this._reloadCall) {
  69. this._reloadCall.abort();
  70. }
  71. // there is only root
  72. this._setCurrentDir('/', false);
  73. this._reloadCall = $.ajax({
  74. url: OC.generateUrl('/apps/files/api/v1/recent'),
  75. type: 'GET',
  76. dataType: 'json'
  77. });
  78. var callBack = this.reloadCallback.bind(this);
  79. return this._reloadCall.then(callBack, callBack);
  80. },
  81. reloadCallback: function (result) {
  82. delete this._reloadCall;
  83. this.hideMask();
  84. if (result.files) {
  85. this.setFiles(result.files.sort(this._sortComparator));
  86. return true;
  87. }
  88. return false;
  89. }
  90. });
  91. OCA.Files.RecentFileList = RecentFileList;
  92. })(OCA);
  93. });