favoritesfilelist.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. this._reloadCall = $.ajax({
  68. url: OC.generateUrl('/apps/files/api/v1/tags/{tagName}/files', {tagName: tagName}),
  69. type: 'GET',
  70. dataType: 'json'
  71. });
  72. var callBack = this.reloadCallback.bind(this);
  73. return this._reloadCall.then(callBack, callBack);
  74. },
  75. reloadCallback: function(result) {
  76. delete this._reloadCall;
  77. this.hideMask();
  78. if (result.files) {
  79. this.setFiles(result.files.sort(this._sortComparator));
  80. }
  81. else {
  82. // TODO: error handling
  83. }
  84. }
  85. });
  86. OCA.Files.FavoritesFileList = FavoritesFileList;
  87. })(OCA);
  88. });