favoritesfilelist.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.FavoritesFileList
  15. * @augments OCA.Files.FavoritesFileList
  16. *
  17. * @classdesc Favorites file list.
  18. * Displays the list of files marked as favorites
  19. *
  20. * @param $el container element with existing markup for the .files-controls
  21. * and a table
  22. * @param [options] map of options, see other parameters
  23. */
  24. var FavoritesFileList = function($el, options) {
  25. this.initialize($el, options);
  26. };
  27. FavoritesFileList.prototype = _.extend({}, OCA.Files.FileList.prototype,
  28. /** @lends OCA.Files.FavoritesFileList.prototype */ {
  29. id: 'favorites',
  30. appName: t('files','Favorites'),
  31. _clientSideSort: true,
  32. _allowSelection: false,
  33. /**
  34. * @private
  35. */
  36. initialize: function($el, options) {
  37. OCA.Files.FileList.prototype.initialize.apply(this, arguments);
  38. if (this.initialized) {
  39. return;
  40. }
  41. OC.Plugins.attach('OCA.Files.FavoritesFileList', this);
  42. },
  43. updateEmptyContent: function() {
  44. var dir = this.getCurrentDirectory();
  45. if (dir === '/') {
  46. // root has special permissions
  47. this.$el.find('.emptyfilelist.emptycontent').toggleClass('hidden', !this.isEmpty);
  48. this.$el.find('.files-filestable thead th').toggleClass('hidden', this.isEmpty);
  49. }
  50. else {
  51. OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments);
  52. }
  53. },
  54. getDirectoryPermissions: function() {
  55. return OC.PERMISSION_READ | OC.PERMISSION_DELETE;
  56. },
  57. updateStorageStatistics: function() {
  58. // no op because it doesn't have
  59. // storage info like free space / used space
  60. },
  61. reload: function() {
  62. this.showMask();
  63. if (this._reloadCall) {
  64. this._reloadCall.abort();
  65. }
  66. // there is only root
  67. this._setCurrentDir('/', false);
  68. this._reloadCall = this.filesClient.getFilteredFiles(
  69. {
  70. favorite: true
  71. },
  72. {
  73. properties: this._getWebdavProperties()
  74. }
  75. );
  76. var callBack = this.reloadCallback.bind(this);
  77. return this._reloadCall.then(callBack, callBack);
  78. },
  79. reloadCallback: function(status, result) {
  80. if (result) {
  81. // prepend empty dir info because original handler
  82. result.unshift({});
  83. }
  84. return OCA.Files.FileList.prototype.reloadCallback.call(this, status, result);
  85. },
  86. });
  87. OCA.Files.FavoritesFileList = FavoritesFileList;
  88. })(OCA);
  89. });