1
0

app.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. if (!OCA.Files_External) {
  11. /**
  12. * @namespace
  13. */
  14. OCA.Files_External = {};
  15. }
  16. /**
  17. * @namespace
  18. */
  19. OCA.Files_External.App = {
  20. fileList: null,
  21. initList: function($el) {
  22. if (this.fileList) {
  23. return this.fileList;
  24. }
  25. this.fileList = new OCA.Files_External.FileList(
  26. $el,
  27. {
  28. fileActions: this._createFileActions()
  29. }
  30. );
  31. this._extendFileList(this.fileList);
  32. this.fileList.appName = t('files_external', 'External storage');
  33. return this.fileList;
  34. },
  35. removeList: function() {
  36. if (this.fileList) {
  37. this.fileList.$fileList.empty();
  38. }
  39. },
  40. _createFileActions: function() {
  41. // inherit file actions from the files app
  42. var fileActions = new OCA.Files.FileActions();
  43. fileActions.registerDefaultActions();
  44. // when the user clicks on a folder, redirect to the corresponding
  45. // folder in the files app instead of opening it directly
  46. fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
  47. OCA.Files.App.setActiveView('files', {silent: true});
  48. OCA.Files.App.fileList.changeDirectory(OC.joinPaths(context.$file.attr('data-path'), filename), true, true);
  49. });
  50. fileActions.setDefault('dir', 'Open');
  51. return fileActions;
  52. },
  53. _extendFileList: function(fileList) {
  54. // remove size column from summary
  55. fileList.fileSummary.$el.find('.filesize').remove();
  56. }
  57. };
  58. window.addEventListener('DOMContentLoaded', function() {
  59. $('#app-content-extstoragemounts').on('show', function(e) {
  60. OCA.Files_External.App.initList($(e.target));
  61. });
  62. $('#app-content-extstoragemounts').on('hide', function() {
  63. OCA.Files_External.App.removeList();
  64. });
  65. /* Status Manager */
  66. if ($('#filesApp').val()) {
  67. $('#app-content-files')
  68. .add('#app-content-extstoragemounts')
  69. .on('changeDirectory', function(e){
  70. if (e.dir === '/') {
  71. var mount_point = e.previousDir.split('/', 2)[1];
  72. // Every time that we return to / root folder from a mountpoint, mount_point status is rechecked
  73. OCA.Files_External.StatusManager.getMountPointList(function() {
  74. OCA.Files_External.StatusManager.recheckConnectivityForMount([mount_point], true);
  75. });
  76. }
  77. })
  78. .on('fileActionsReady', function(e){
  79. if ($.isArray(e.$files)) {
  80. if (OCA.Files_External.StatusManager.mountStatus === null ||
  81. OCA.Files_External.StatusManager.mountPointList === null ||
  82. _.size(OCA.Files_External.StatusManager.mountStatus) !== _.size(OCA.Files_External.StatusManager.mountPointList)) {
  83. // Will be the very first check when the files view will be loaded
  84. OCA.Files_External.StatusManager.launchFullConnectivityCheckOneByOne();
  85. } else {
  86. // When we change between general files view and external files view
  87. OCA.Files_External.StatusManager.getMountPointList(function(){
  88. var fileNames = [];
  89. $.each(e.$files, function(key, value){
  90. fileNames.push(value.attr('data-file'));
  91. });
  92. // Recheck if launched but work from cache
  93. OCA.Files_External.StatusManager.recheckConnectivityForMount(fileNames, false);
  94. });
  95. }
  96. }
  97. });
  98. }
  99. /* End Status Manager */
  100. });