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.

FileReferencePickerElement.vue 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!--
  2. - @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
  3. -
  4. - @author Julius Härtl <jus@bitgrid.net>
  5. -
  6. - @license GNU AGPL version 3 or any later version
  7. -
  8. - This program is free software: you can redistribute it and/or modify
  9. - it under the terms of the GNU Affero General Public License as
  10. - published by the Free Software Foundation, either version 3 of the
  11. - License, or (at your option) any later version.
  12. -
  13. - This program is distributed in the hope that it will be useful,
  14. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. - GNU Affero General Public License for more details.
  17. -
  18. - You should have received a copy of the GNU Affero General Public License
  19. - along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. -->
  21. <template>
  22. <div ref="picker" class="reference-file-picker" />
  23. </template>
  24. <script>
  25. import { FilePickerType } from '@nextcloud/dialogs'
  26. import { generateUrl } from '@nextcloud/router'
  27. export default {
  28. name: 'FileReferencePickerElement',
  29. components: {
  30. },
  31. props: {
  32. providerId: {
  33. type: String,
  34. required: true,
  35. },
  36. accessible: {
  37. type: Boolean,
  38. default: false,
  39. },
  40. },
  41. mounted() {
  42. this.openFilePicker()
  43. window.addEventListener('click', this.onWindowClick)
  44. },
  45. beforeDestroy() {
  46. window.removeEventListener('click', this.onWindowClick)
  47. },
  48. methods: {
  49. onWindowClick(e) {
  50. if (e.target.tagName === 'A' && e.target.classList.contains('oc-dialog-close')) {
  51. this.$emit('cancel')
  52. }
  53. },
  54. async openFilePicker() {
  55. OC.dialogs.filepicker(
  56. t('files', 'Select file or folder to link to'),
  57. (file) => {
  58. const client = OC.Files.getClient()
  59. client.getFileInfo(file).then((_status, fileInfo) => {
  60. this.submit(fileInfo.id)
  61. })
  62. },
  63. false, // multiselect
  64. [], // mime filter
  65. false, // modal
  66. FilePickerType.Choose, // type
  67. '',
  68. {
  69. target: this.$refs.picker,
  70. },
  71. )
  72. },
  73. submit(fileId) {
  74. const fileLink = window.location.protocol + '//' + window.location.host
  75. + generateUrl('/f/{fileId}', { fileId })
  76. this.$emit('submit', fileLink)
  77. },
  78. },
  79. }
  80. </script>
  81. <style scoped lang="scss">
  82. .reference-file-picker {
  83. flex-grow: 1;
  84. margin-top: 44px;
  85. &:deep(.oc-dialog) {
  86. transform: none !important;
  87. box-shadow: none !important;
  88. flex-grow: 1 !important;
  89. position: static !important;
  90. width: 100% !important;
  91. height: auto !important;
  92. padding: 0 !important;
  93. max-width: initial;
  94. .oc-dialog-close {
  95. display: none;
  96. }
  97. .oc-dialog-buttonrow.onebutton.aside {
  98. position: absolute;
  99. padding: 12px 32px;
  100. }
  101. .oc-dialog-content {
  102. max-width: 100% !important;
  103. }
  104. }
  105. }
  106. </style>