app.js 5.4 KB

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