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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
  3. *
  4. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  5. * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
  6. * @author John Molakvoæ <skjnldsv@protonmail.com>
  7. * @author Vincent Petry <vincent@nextcloud.com>
  8. *
  9. * @license AGPL-3.0-or-later
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. (function() {
  26. if (!OCA.SystemTags) {
  27. /**
  28. * @namespace
  29. */
  30. OCA.SystemTags = {}
  31. }
  32. OCA.SystemTags.App = {
  33. initFileList($el) {
  34. if (this._fileList) {
  35. return this._fileList
  36. }
  37. const tagsParam = (new URL(window.location.href)).searchParams.get('tags')
  38. const initialTags = tagsParam ? tagsParam.split(',').map(parseInt) : []
  39. this._fileList = new OCA.SystemTags.FileList(
  40. $el,
  41. {
  42. id: 'systemtags',
  43. fileActions: this._createFileActions(),
  44. config: OCA.Files.App.getFilesConfig(),
  45. // The file list is created when a "show" event is handled,
  46. // so it should be marked as "shown" like it would have been
  47. // done if handling the event with the file list already
  48. // created.
  49. shown: true,
  50. systemTagIds: initialTags,
  51. }
  52. )
  53. this._fileList.appName = t('systemtags', 'Tags')
  54. return this._fileList
  55. },
  56. removeFileList() {
  57. if (this._fileList) {
  58. this._fileList.$fileList.empty()
  59. }
  60. },
  61. _createFileActions() {
  62. // inherit file actions from the files app
  63. const fileActions = new OCA.Files.FileActions()
  64. // note: not merging the legacy actions because legacy apps are not
  65. // compatible with the sharing overview and need to be adapted first
  66. fileActions.registerDefaultActions()
  67. fileActions.merge(OCA.Files.fileActions)
  68. if (!this._globalActionsInitialized) {
  69. // in case actions are registered later
  70. this._onActionsUpdated = _.bind(this._onActionsUpdated, this)
  71. OCA.Files.fileActions.on('setDefault.app-systemtags', this._onActionsUpdated)
  72. OCA.Files.fileActions.on('registerAction.app-systemtags', this._onActionsUpdated)
  73. this._globalActionsInitialized = true
  74. }
  75. // when the user clicks on a folder, redirect to the corresponding
  76. // folder in the files app instead of opening it directly
  77. fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function(filename, context) {
  78. OCA.Files.App.setActiveView('files', { silent: true })
  79. OCA.Files.App.fileList.changeDirectory(OC.joinPaths(context.$file.attr('data-path'), filename), true, true)
  80. })
  81. fileActions.setDefault('dir', 'Open')
  82. return fileActions
  83. },
  84. _onActionsUpdated(ev) {
  85. if (!this._fileList) {
  86. return
  87. }
  88. if (ev.action) {
  89. this._fileList.fileActions.registerAction(ev.action)
  90. } else if (ev.defaultAction) {
  91. this._fileList.fileActions.setDefault(
  92. ev.defaultAction.mime,
  93. ev.defaultAction.name
  94. )
  95. }
  96. },
  97. /**
  98. * Destroy the app
  99. */
  100. destroy() {
  101. OCA.Files.fileActions.off('setDefault.app-systemtags', this._onActionsUpdated)
  102. OCA.Files.fileActions.off('registerAction.app-systemtags', this._onActionsUpdated)
  103. this.removeFileList()
  104. this._fileList = null
  105. delete this._globalActionsInitialized
  106. },
  107. }
  108. })()
  109. window.addEventListener('DOMContentLoaded', function() {
  110. $('#app-content-systemtagsfilter').on('show', function(e) {
  111. OCA.SystemTags.App.initFileList($(e.target))
  112. })
  113. $('#app-content-systemtagsfilter').on('hide', function() {
  114. OCA.SystemTags.App.removeFileList()
  115. })
  116. })