favoritesfilelist.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. $(document).ready(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 #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('#emptycontent').toggleClass('hidden', !this.isEmpty);
  48. this.$el.find('#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. var tagName = OC.TAG_FAVORITE;
  63. this.showMask();
  64. if (this._reloadCall) {
  65. this._reloadCall.abort();
  66. }
  67. // there is only root
  68. this._setCurrentDir('/', false);
  69. this._reloadCall = this.filesClient.getFilteredFiles(
  70. {
  71. favorite: true
  72. },
  73. {
  74. properties: this._getWebdavProperties()
  75. }
  76. );
  77. var callBack = this.reloadCallback.bind(this);
  78. return this._reloadCall.then(callBack, callBack);
  79. },
  80. reloadCallback: function(status, result) {
  81. if (result) {
  82. // prepend empty dir info because original handler
  83. result.unshift({});
  84. }
  85. return OCA.Files.FileList.prototype.reloadCallback.call(this, status, result);
  86. }
  87. });
  88. OCA.Files.FavoritesFileList = FavoritesFileList;
  89. })(OCA);
  90. });