app.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.Sharing) {
  11. OCA.Sharing = {};
  12. }
  13. OCA.Sharing.App = {
  14. _inFileList: null,
  15. _outFileList: null,
  16. initSharingIn: function($el) {
  17. if (this._inFileList) {
  18. return this._inFileList;
  19. }
  20. this._inFileList = new OCA.Sharing.FileList(
  21. $el,
  22. {
  23. scrollContainer: $('#app-content'),
  24. sharedWithUser: true,
  25. fileActions: this._createFileActions()
  26. }
  27. );
  28. this._extendFileList(this._inFileList);
  29. this._inFileList.appName = t('files_sharing', 'Shared with you');
  30. this._inFileList.$el.find('#emptycontent').text(t('files_sharing', 'No files have been shared with you yet.'));
  31. return this._inFileList;
  32. },
  33. initSharingOut: function($el) {
  34. if (this._outFileList) {
  35. return this._outFileList;
  36. }
  37. this._outFileList = new OCA.Sharing.FileList(
  38. $el,
  39. {
  40. scrollContainer: $('#app-content'),
  41. sharedWithUser: false,
  42. fileActions: this._createFileActions()
  43. }
  44. );
  45. this._extendFileList(this._outFileList);
  46. this._outFileList.appName = t('files_sharing', 'Shared with others');
  47. this._outFileList.$el.find('#emptycontent').text(t('files_sharing', 'You haven\'t shared any files yet.'));
  48. return this._outFileList;
  49. },
  50. initSharingLinks: function($el) {
  51. if (this._linkFileList) {
  52. return this._linkFileList;
  53. }
  54. this._linkFileList = new OCA.Sharing.FileList(
  55. $el,
  56. {
  57. scrollContainer: $('#app-content'),
  58. linksOnly: true,
  59. fileActions: this._createFileActions()
  60. }
  61. );
  62. this._extendFileList(this._linkFileList);
  63. this._linkFileList.appName = t('files_sharing', 'Shared by link');
  64. this._linkFileList.$el.find('#emptycontent').text(t('files_sharing', 'You haven\'t shared any files by link yet.'));
  65. return this._linkFileList;
  66. },
  67. removeSharingIn: function() {
  68. if (this._inFileList) {
  69. this._inFileList.$fileList.empty();
  70. }
  71. },
  72. removeSharingOut: function() {
  73. if (this._outFileList) {
  74. this._outFileList.$fileList.empty();
  75. }
  76. },
  77. removeSharingLinks: function() {
  78. if (this._linkFileList) {
  79. this._linkFileList.$fileList.empty();
  80. }
  81. },
  82. /**
  83. * Destroy the app
  84. */
  85. destroy: function() {
  86. OCA.Files.fileActions.off('setDefault.app-sharing', this._onActionsUpdated);
  87. OCA.Files.fileActions.off('registerAction.app-sharing', this._onActionsUpdated);
  88. this.removeSharingIn();
  89. this.removeSharingOut();
  90. this.removeSharingLinks();
  91. this._inFileList = null;
  92. this._outFileList = null;
  93. this._linkFileList = null;
  94. delete this._globalActionsInitialized;
  95. },
  96. _createFileActions: function() {
  97. // inherit file actions from the files app
  98. var fileActions = new OCA.Files.FileActions();
  99. // note: not merging the legacy actions because legacy apps are not
  100. // compatible with the sharing overview and need to be adapted first
  101. fileActions.registerDefaultActions();
  102. fileActions.merge(OCA.Files.fileActions);
  103. if (!this._globalActionsInitialized) {
  104. // in case actions are registered later
  105. this._onActionsUpdated = _.bind(this._onActionsUpdated, this);
  106. OCA.Files.fileActions.on('setDefault.app-sharing', this._onActionsUpdated);
  107. OCA.Files.fileActions.on('registerAction.app-sharing', this._onActionsUpdated);
  108. this._globalActionsInitialized = true;
  109. }
  110. // when the user clicks on a folder, redirect to the corresponding
  111. // folder in the files app instead of opening it directly
  112. fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
  113. OCA.Files.App.setActiveView('files', {silent: true});
  114. OCA.Files.App.fileList.changeDirectory(context.$file.attr('data-path') + '/' + filename, true, true);
  115. });
  116. fileActions.setDefault('dir', 'Open');
  117. return fileActions;
  118. },
  119. _onActionsUpdated: function(ev) {
  120. _.each([this._inFileList, this._outFileList, this._linkFileList], function(list) {
  121. if (!list) {
  122. return;
  123. }
  124. if (ev.action) {
  125. list.fileActions.registerAction(ev.action);
  126. } else if (ev.defaultAction) {
  127. list.fileActions.setDefault(
  128. ev.defaultAction.mime,
  129. ev.defaultAction.name
  130. );
  131. }
  132. });
  133. },
  134. _extendFileList: function(fileList) {
  135. // remove size column from summary
  136. fileList.fileSummary.$el.find('.filesize').remove();
  137. }
  138. };
  139. $(document).ready(function() {
  140. $('#app-content-sharingin').on('show', function(e) {
  141. OCA.Sharing.App.initSharingIn($(e.target));
  142. });
  143. $('#app-content-sharingin').on('hide', function() {
  144. OCA.Sharing.App.removeSharingIn();
  145. });
  146. $('#app-content-sharingout').on('show', function(e) {
  147. OCA.Sharing.App.initSharingOut($(e.target));
  148. });
  149. $('#app-content-sharingout').on('hide', function() {
  150. OCA.Sharing.App.removeSharingOut();
  151. });
  152. $('#app-content-sharinglinks').on('show', function(e) {
  153. OCA.Sharing.App.initSharingLinks($(e.target));
  154. });
  155. $('#app-content-sharinglinks').on('hide', function() {
  156. OCA.Sharing.App.removeSharingLinks();
  157. });
  158. });