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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. scrollContainer: $('#app-content'),
  27. fileActions: this._createFileActions(),
  28. config: OCA.Files.App.getFilesConfig()
  29. }
  30. );
  31. this._fileList.appName = t('systemtags', 'Tags');
  32. return this._fileList;
  33. },
  34. removeFileList: function() {
  35. if (this._fileList) {
  36. this._fileList.$fileList.empty();
  37. }
  38. },
  39. _createFileActions: function() {
  40. // inherit file actions from the files app
  41. var fileActions = new OCA.Files.FileActions();
  42. // note: not merging the legacy actions because legacy apps are not
  43. // compatible with the sharing overview and need to be adapted first
  44. fileActions.registerDefaultActions();
  45. fileActions.merge(OCA.Files.fileActions);
  46. if (!this._globalActionsInitialized) {
  47. // in case actions are registered later
  48. this._onActionsUpdated = _.bind(this._onActionsUpdated, this);
  49. OCA.Files.fileActions.on('setDefault.app-systemtags', this._onActionsUpdated);
  50. OCA.Files.fileActions.on('registerAction.app-systemtags', this._onActionsUpdated);
  51. this._globalActionsInitialized = true;
  52. }
  53. // when the user clicks on a folder, redirect to the corresponding
  54. // folder in the files app instead of opening it directly
  55. fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
  56. OCA.Files.App.setActiveView('files', {silent: true});
  57. OCA.Files.App.fileList.changeDirectory(OC.joinPaths(context.$file.attr('data-path'), filename), true, true);
  58. });
  59. fileActions.setDefault('dir', 'Open');
  60. return fileActions;
  61. },
  62. _onActionsUpdated: function(ev) {
  63. if (!this._fileList) {
  64. return;
  65. }
  66. if (ev.action) {
  67. this._fileList.fileActions.registerAction(ev.action);
  68. } else if (ev.defaultAction) {
  69. this._fileList.fileActions.setDefault(
  70. ev.defaultAction.mime,
  71. ev.defaultAction.name
  72. );
  73. }
  74. },
  75. /**
  76. * Destroy the app
  77. */
  78. destroy: function() {
  79. OCA.Files.fileActions.off('setDefault.app-systemtags', this._onActionsUpdated);
  80. OCA.Files.fileActions.off('registerAction.app-systemtags', this._onActionsUpdated);
  81. this.removeFileList();
  82. this._fileList = null;
  83. delete this._globalActionsInitialized;
  84. }
  85. };
  86. })();
  87. $(document).ready(function() {
  88. $('#app-content-systemtagsfilter').on('show', function(e) {
  89. OCA.SystemTags.App.initFileList($(e.target));
  90. });
  91. $('#app-content-systemtagsfilter').on('hide', function() {
  92. OCA.SystemTags.App.removeFileList();
  93. });
  94. });