mountsfilelist.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. (function() {
  11. /**
  12. * @class OCA.External.FileList
  13. * @augments OCA.Files.FileList
  14. *
  15. * @classdesc External storage file list.
  16. *
  17. * Displays a list of mount points visible
  18. * for the current user.
  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 FileList = function($el, options) {
  25. this.initialize($el, options);
  26. };
  27. FileList.prototype = _.extend({}, OCA.Files.FileList.prototype,
  28. /** @lends OCA.External.FileList.prototype */ {
  29. appName: 'External storage',
  30. /**
  31. * @private
  32. */
  33. initialize: function($el, options) {
  34. OCA.Files.FileList.prototype.initialize.apply(this, arguments);
  35. if (this.initialized) {
  36. return;
  37. }
  38. },
  39. /**
  40. * @param {OCA.External.MountPointInfo} fileData
  41. */
  42. _createRow: function(fileData) {
  43. // TODO: hook earlier and render the whole row here
  44. var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments);
  45. var $scopeColumn = $('<td class="column-scope column-last"><span></span></td>');
  46. var $backendColumn = $('<td class="column-backend"></td>');
  47. var scopeText = t('files_external', 'Personal');
  48. if (fileData.scope === 'system') {
  49. scopeText = t('files_external', 'System');
  50. }
  51. $tr.find('.filesize,.date').remove();
  52. $scopeColumn.find('span').text(scopeText);
  53. $backendColumn.text(fileData.backend);
  54. $tr.find('td.filename').after($scopeColumn).after($backendColumn);
  55. $tr.find('td.filename input:checkbox').remove();
  56. return $tr;
  57. },
  58. updateEmptyContent: function() {
  59. var dir = this.getCurrentDirectory();
  60. if (dir === '/') {
  61. // root has special permissions
  62. this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty);
  63. this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty);
  64. }
  65. else {
  66. OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments);
  67. }
  68. },
  69. getDirectoryPermissions: function() {
  70. return OC.PERMISSION_READ | OC.PERMISSION_DELETE;
  71. },
  72. updateStorageStatistics: function() {
  73. // no op because it doesn't have
  74. // storage info like free space / used space
  75. },
  76. reload: function() {
  77. this.showMask();
  78. if (this._reloadCall) {
  79. this._reloadCall.abort();
  80. }
  81. // there is only root
  82. this._setCurrentDir('/', false);
  83. this._reloadCall = $.ajax({
  84. url: OC.linkToOCS('apps/files_external/api/v1') + 'mounts',
  85. data: {
  86. format: 'json'
  87. },
  88. type: 'GET',
  89. beforeSend: function(xhr) {
  90. xhr.setRequestHeader('OCS-APIREQUEST', 'true');
  91. }
  92. });
  93. var callBack = this.reloadCallback.bind(this);
  94. return this._reloadCall.then(callBack, callBack);
  95. },
  96. reloadCallback: function(result) {
  97. delete this._reloadCall;
  98. this.hideMask();
  99. if (result.ocs && result.ocs.data) {
  100. this.setFiles(this._makeFiles(result.ocs.data));
  101. return true;
  102. }
  103. return false;
  104. },
  105. /**
  106. * Converts the OCS API response data to a file info
  107. * list
  108. * @param OCS API mounts array
  109. * @return array of file info maps
  110. */
  111. _makeFiles: function(data) {
  112. var files = _.map(data, function(fileData) {
  113. fileData.icon = OC.imagePath('core', 'filetypes/folder-external');
  114. fileData.mountType = 'external';
  115. return fileData;
  116. });
  117. files.sort(this._sortComparator);
  118. return files;
  119. }
  120. });
  121. /**
  122. * Mount point info attributes.
  123. *
  124. * @typedef {Object} OCA.External.MountPointInfo
  125. *
  126. * @property {String} name mount point name
  127. * @property {String} scope mount point scope "personal" or "system"
  128. * @property {String} backend external storage backend name
  129. */
  130. OCA.External.FileList = FileList;
  131. })();