app.js 3.1 KB

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