You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.js 5.5KB

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