mountsfilelist.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. this._reloadCall = $.ajax({
  82. url: OC.linkToOCS('apps/files_external/api/v1') + 'mounts',
  83. data: {
  84. format: 'json'
  85. },
  86. type: 'GET',
  87. beforeSend: function(xhr) {
  88. xhr.setRequestHeader('OCS-APIREQUEST', 'true');
  89. }
  90. });
  91. var callBack = this.reloadCallback.bind(this);
  92. return this._reloadCall.then(callBack, callBack);
  93. },
  94. reloadCallback: function(result) {
  95. delete this._reloadCall;
  96. this.hideMask();
  97. if (result.ocs && result.ocs.data) {
  98. this.setFiles(this._makeFiles(result.ocs.data));
  99. }
  100. else {
  101. // TODO: error handling
  102. }
  103. },
  104. /**
  105. * Converts the OCS API response data to a file info
  106. * list
  107. * @param OCS API mounts array
  108. * @return array of file info maps
  109. */
  110. _makeFiles: function(data) {
  111. var files = _.map(data, function(fileData) {
  112. fileData.icon = OC.imagePath('core', 'filetypes/folder-external');
  113. fileData.mountType = 'external';
  114. return fileData;
  115. });
  116. files.sort(this._sortComparator);
  117. return files;
  118. }
  119. });
  120. /**
  121. * Mount point info attributes.
  122. *
  123. * @typedef {Object} OCA.External.MountPointInfo
  124. *
  125. * @property {String} name mount point name
  126. * @property {String} scope mount point scope "personal" or "system"
  127. * @property {String} backend external storage backend name
  128. */
  129. OCA.External.FileList = FileList;
  130. })();