1
0

app.js 6.2 KB

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