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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2015 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. (function() {
  11. if (!OCA.SystemTags) {
  12. /**
  13. * @namespace
  14. */
  15. OCA.SystemTags = {};
  16. }
  17. OCA.SystemTags.App = {
  18. initFileList: function($el) {
  19. if (this._fileList) {
  20. return this._fileList;
  21. }
  22. this._fileList = new OCA.SystemTags.FileList(
  23. $el,
  24. {
  25. id: 'systemtags',
  26. fileActions: this._createFileActions(),
  27. config: OCA.Files.App.getFilesConfig(),
  28. // The file list is created when a "show" event is handled,
  29. // so it should be marked as "shown" like it would have been
  30. // done if handling the event with the file list already
  31. // created.
  32. shown: true
  33. }
  34. );
  35. this._fileList.appName = t('systemtags', 'Tags');
  36. return this._fileList;
  37. },
  38. removeFileList: function() {
  39. if (this._fileList) {
  40. this._fileList.$fileList.empty();
  41. }
  42. },
  43. _createFileActions: function() {
  44. // inherit file actions from the files app
  45. var fileActions = new OCA.Files.FileActions();
  46. // note: not merging the legacy actions because legacy apps are not
  47. // compatible with the sharing overview and need to be adapted first
  48. fileActions.registerDefaultActions();
  49. fileActions.merge(OCA.Files.fileActions);
  50. if (!this._globalActionsInitialized) {
  51. // in case actions are registered later
  52. this._onActionsUpdated = _.bind(this._onActionsUpdated, this);
  53. OCA.Files.fileActions.on('setDefault.app-systemtags', this._onActionsUpdated);
  54. OCA.Files.fileActions.on('registerAction.app-systemtags', this._onActionsUpdated);
  55. this._globalActionsInitialized = true;
  56. }
  57. // when the user clicks on a folder, redirect to the corresponding
  58. // folder in the files app instead of opening it directly
  59. fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
  60. OCA.Files.App.setActiveView('files', {silent: true});
  61. OCA.Files.App.fileList.changeDirectory(OC.joinPaths(context.$file.attr('data-path'), filename), true, true);
  62. });
  63. fileActions.setDefault('dir', 'Open');
  64. return fileActions;
  65. },
  66. _onActionsUpdated: function(ev) {
  67. if (!this._fileList) {
  68. return;
  69. }
  70. if (ev.action) {
  71. this._fileList.fileActions.registerAction(ev.action);
  72. } else if (ev.defaultAction) {
  73. this._fileList.fileActions.setDefault(
  74. ev.defaultAction.mime,
  75. ev.defaultAction.name
  76. );
  77. }
  78. },
  79. /**
  80. * Destroy the app
  81. */
  82. destroy: function() {
  83. OCA.Files.fileActions.off('setDefault.app-systemtags', this._onActionsUpdated);
  84. OCA.Files.fileActions.off('registerAction.app-systemtags', this._onActionsUpdated);
  85. this.removeFileList();
  86. this._fileList = null;
  87. delete this._globalActionsInitialized;
  88. }
  89. };
  90. })();
  91. $(document).ready(function() {
  92. $('#app-content-systemtagsfilter').on('show', function(e) {
  93. OCA.SystemTags.App.initFileList($(e.target));
  94. });
  95. $('#app-content-systemtagsfilter').on('hide', function() {
  96. OCA.SystemTags.App.removeFileList();
  97. });
  98. });