app.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. _overviewFileList: null,
  23. initSharingIn: function($el) {
  24. if (this._inFileList) {
  25. return this._inFileList;
  26. }
  27. this._inFileList = new OCA.Sharing.FileList(
  28. $el,
  29. {
  30. id: 'shares.self',
  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. sharedWithUser: false,
  56. fileActions: this._createFileActions(),
  57. config: OCA.Files.App.getFilesConfig(),
  58. // The file list is created when a "show" event is handled, so
  59. // it should be marked as "shown" like it would have been done
  60. // if handling the event with the file list already created.
  61. shown: true
  62. }
  63. );
  64. this._extendFileList(this._outFileList);
  65. this._outFileList.appName = t('files_sharing', 'Shared with others');
  66. this._outFileList.$el.find('#emptycontent').html('<div class="icon-shared"></div>' +
  67. '<h2>' + t('files_sharing', 'Nothing shared yet') + '</h2>' +
  68. '<p>' + t('files_sharing', 'Files and folders you share will show up here') + '</p>');
  69. return this._outFileList;
  70. },
  71. initSharingLinks: function($el) {
  72. if (this._linkFileList) {
  73. return this._linkFileList;
  74. }
  75. this._linkFileList = new OCA.Sharing.FileList(
  76. $el,
  77. {
  78. id: 'shares.link',
  79. linksOnly: true,
  80. fileActions: this._createFileActions(),
  81. config: OCA.Files.App.getFilesConfig(),
  82. // The file list is created when a "show" event is handled, so
  83. // it should be marked as "shown" like it would have been done
  84. // if handling the event with the file list already created.
  85. shown: true
  86. }
  87. );
  88. this._extendFileList(this._linkFileList);
  89. this._linkFileList.appName = t('files_sharing', 'Shared by link');
  90. this._linkFileList.$el.find('#emptycontent').html('<div class="icon-public"></div>' +
  91. '<h2>' + t('files_sharing', 'No shared links') + '</h2>' +
  92. '<p>' + t('files_sharing', 'Files and folders you share by link will show up here') + '</p>');
  93. return this._linkFileList;
  94. },
  95. initSharingDeleted: function($el) {
  96. if (this._deletedFileList) {
  97. return this._deletedFileList;
  98. }
  99. this._deletedFileList = new OCA.Sharing.FileList(
  100. $el,
  101. {
  102. id: 'shares.deleted',
  103. showDeleted: true,
  104. sharedWithUser: true,
  105. fileActions: this._restoreShareAction(),
  106. config: OCA.Files.App.getFilesConfig(),
  107. // The file list is created when a "show" event is handled, so
  108. // it should be marked as "shown" like it would have been done
  109. // if handling the event with the file list already created.
  110. shown: true
  111. }
  112. );
  113. this._extendFileList(this._deletedFileList);
  114. this._deletedFileList.appName = t('files_sharing', 'Deleted shares');
  115. this._deletedFileList.$el.find('#emptycontent').html('<div class="icon-share"></div>' +
  116. '<h2>' + t('files_sharing', 'No deleted shares') + '</h2>' +
  117. '<p>' + t('files_sharing', 'Shares you deleted will show up here') + '</p>');
  118. return this._deletedFileList;
  119. },
  120. initShareingOverview: function($el) {
  121. if (this._overviewFileList) {
  122. return this._overviewFileList;
  123. }
  124. this._overviewFileList = new OCA.Sharing.FileList(
  125. $el,
  126. {
  127. id: 'shares.overview',
  128. config: OCA.Files.App.getFilesConfig(),
  129. isOverview: true,
  130. // The file list is created when a "show" event is handled, so
  131. // it should be marked as "shown" like it would have been done
  132. // if handling the event with the file list already created.
  133. shown: true
  134. }
  135. );
  136. this._extendFileList(this._overviewFileList);
  137. this._overviewFileList.appName = t('files_sharing', 'Shares');
  138. this._overviewFileList.$el.find('#emptycontent').html('<div class="icon-share"></div>' +
  139. '<h2>' + t('files_sharing', 'No shares') + '</h2>' +
  140. '<p>' + t('files_sharing', 'Shares will show up here') + '</p>');
  141. return this._overviewFileList;
  142. },
  143. removeSharingIn: function() {
  144. if (this._inFileList) {
  145. this._inFileList.$fileList.empty();
  146. }
  147. },
  148. removeSharingOut: function() {
  149. if (this._outFileList) {
  150. this._outFileList.$fileList.empty();
  151. }
  152. },
  153. removeSharingLinks: function() {
  154. if (this._linkFileList) {
  155. this._linkFileList.$fileList.empty();
  156. }
  157. },
  158. removeSharingDeleted: function() {
  159. if (this._deletedFileList) {
  160. this._deletedFileList.$fileList.empty();
  161. }
  162. },
  163. removeSharingOverview: function() {
  164. if (this._overviewFileList) {
  165. this._overviewFileList.$fileList.empty();
  166. }
  167. },
  168. /**
  169. * Destroy the app
  170. */
  171. destroy: function() {
  172. OCA.Files.fileActions.off('setDefault.app-sharing', this._onActionsUpdated);
  173. OCA.Files.fileActions.off('registerAction.app-sharing', this._onActionsUpdated);
  174. this.removeSharingIn();
  175. this.removeSharingOut();
  176. this.removeSharingLinks();
  177. this._inFileList = null;
  178. this._outFileList = null;
  179. this._linkFileList = null;
  180. this._overviewFileList = null;
  181. delete this._globalActionsInitialized;
  182. },
  183. _createFileActions: function() {
  184. // inherit file actions from the files app
  185. var fileActions = new OCA.Files.FileActions();
  186. // note: not merging the legacy actions because legacy apps are not
  187. // compatible with the sharing overview and need to be adapted first
  188. fileActions.registerDefaultActions();
  189. fileActions.merge(OCA.Files.fileActions);
  190. if (!this._globalActionsInitialized) {
  191. // in case actions are registered later
  192. this._onActionsUpdated = _.bind(this._onActionsUpdated, this);
  193. OCA.Files.fileActions.on('setDefault.app-sharing', this._onActionsUpdated);
  194. OCA.Files.fileActions.on('registerAction.app-sharing', this._onActionsUpdated);
  195. this._globalActionsInitialized = true;
  196. }
  197. // when the user clicks on a folder, redirect to the corresponding
  198. // folder in the files app instead of opening it directly
  199. fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
  200. OCA.Files.App.setActiveView('files', {silent: true});
  201. OCA.Files.App.fileList.changeDirectory(OC.joinPaths(context.$file.attr('data-path'), filename), true, true);
  202. });
  203. fileActions.setDefault('dir', 'Open');
  204. return fileActions;
  205. },
  206. _restoreShareAction: function() {
  207. var fileActions = new OCA.Files.FileActions();
  208. fileActions.registerAction({
  209. name: 'Restore',
  210. displayName: '',
  211. altText: t('files_sharing', 'Restore share'),
  212. mime: 'all',
  213. permissions: OC.PERMISSION_ALL,
  214. iconClass: 'icon-history',
  215. type: OCA.Files.FileActions.TYPE_INLINE,
  216. actionHandler: function(fileName, context) {
  217. var shareId = context.$file.data('shareId');
  218. $.post(OC.linkToOCS('apps/files_sharing/api/v1/deletedshares', 2) + shareId)
  219. .success(function(result) {
  220. context.fileList.remove(context.fileInfoModel.attributes.name);
  221. }).fail(function() {
  222. OC.Notification.showTemporary(t('files_sharing', 'Something happened. Unable to restore the share.'));
  223. });
  224. }
  225. });
  226. return fileActions;
  227. },
  228. _onActionsUpdated: function(ev) {
  229. _.each([this._inFileList, this._outFileList, this._linkFileList], function(list) {
  230. if (!list) {
  231. return;
  232. }
  233. if (ev.action) {
  234. list.fileActions.registerAction(ev.action);
  235. } else if (ev.defaultAction) {
  236. list.fileActions.setDefault(
  237. ev.defaultAction.mime,
  238. ev.defaultAction.name
  239. );
  240. }
  241. });
  242. },
  243. _extendFileList: function(fileList) {
  244. // remove size column from summary
  245. fileList.fileSummary.$el.find('.filesize').remove();
  246. }
  247. };
  248. $(document).ready(function() {
  249. $('#app-content-sharingin').on('show', function(e) {
  250. OCA.Sharing.App.initSharingIn($(e.target));
  251. });
  252. $('#app-content-sharingin').on('hide', function() {
  253. OCA.Sharing.App.removeSharingIn();
  254. });
  255. $('#app-content-sharingout').on('show', function(e) {
  256. OCA.Sharing.App.initSharingOut($(e.target));
  257. });
  258. $('#app-content-sharingout').on('hide', function() {
  259. OCA.Sharing.App.removeSharingOut();
  260. });
  261. $('#app-content-sharinglinks').on('show', function(e) {
  262. OCA.Sharing.App.initSharingLinks($(e.target));
  263. });
  264. $('#app-content-sharinglinks').on('hide', function() {
  265. OCA.Sharing.App.removeSharingLinks();
  266. });
  267. $('#app-content-deletedshares').on('show', function(e) {
  268. OCA.Sharing.App.initSharingDeleted($(e.target));
  269. });
  270. $('#app-content-deletedshares').on('hide', function() {
  271. OCA.Sharing.App.removeSharingDeleted();
  272. });
  273. $('#app-content-shareoverview').on('show', function(e) {
  274. OCA.Sharing.App.initShareingOverview($(e.target));
  275. });
  276. $('#app-content-shareoverview').on('hide', function() {
  277. OCA.Sharing.App.removeSharingOverview();
  278. });
  279. });