mountsfilelist.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.Files_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.Files_External.FileList.prototype */ {
  29. appName: 'External storages',
  30. _allowSelection: false,
  31. /**
  32. * @private
  33. */
  34. initialize: function($el, options) {
  35. OCA.Files.FileList.prototype.initialize.apply(this, arguments);
  36. if (this.initialized) {
  37. return;
  38. }
  39. },
  40. /**
  41. * @param {OCA.Files_External.MountPointInfo} fileData
  42. */
  43. _createRow: function(fileData) {
  44. // TODO: hook earlier and render the whole row here
  45. var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments);
  46. var $scopeColumn = $('<td class="column-scope column-last"><span></span></td>');
  47. var $backendColumn = $('<td class="column-backend"></td>');
  48. var scopeText = t('files_external', 'Personal');
  49. if (fileData.scope === 'system') {
  50. scopeText = t('files_external', 'System');
  51. }
  52. $tr.find('.filesize,.date').remove();
  53. $scopeColumn.find('span').text(scopeText);
  54. $backendColumn.text(fileData.backend);
  55. $tr.find('td.filename').after($scopeColumn).after($backendColumn);
  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.Files_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.Files_External.FileList = FileList;
  131. })();