|
| 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 | + |
| 22 | +<template> |
| 23 | + <div ref="picker" class="reference-file-picker" /> |
| 24 | +</template> |
| 25 | + |
| 26 | +<script> |
| 27 | +import { FilePickerType } from '@nextcloud/dialogs' |
| 28 | +import { generateUrl } from '@nextcloud/router' |
| 29 | +export default { |
| 30 | + name: 'FileReferencePickerElement', |
| 31 | + components: { |
| 32 | + }, |
| 33 | + props: { |
| 34 | + providerId: { |
| 35 | + type: String, |
| 36 | + required: true, |
| 37 | + }, |
| 38 | + accessible: { |
| 39 | + type: Boolean, |
| 40 | + default: false, |
| 41 | + }, |
| 42 | + }, |
| 43 | + mounted() { |
| 44 | + this.openFilePicker() |
| 45 | + window.addEventListener('click', this.onWindowClick) |
| 46 | + }, |
| 47 | + beforeDestroy() { |
| 48 | + window.removeEventListener('click', this.onWindowClick) |
| 49 | + }, |
| 50 | + methods: { |
| 51 | + onWindowClick(e) { |
| 52 | + if (e.target.tagName === 'A' && e.target.classList.contains('oc-dialog-close')) { |
| 53 | + this.$emit('cancel') |
| 54 | + } |
| 55 | + }, |
| 56 | + async openFilePicker() { |
| 57 | + OC.dialogs.filepicker( |
| 58 | + t('files', 'Select file or folder to link to'), |
| 59 | + (file) => { |
| 60 | + const client = OC.Files.getClient() |
| 61 | + client.getFileInfo(file).then((_status, fileInfo) => { |
| 62 | + this.submit(fileInfo.id) |
| 63 | + }) |
| 64 | + }, |
| 65 | + false, // multiselect |
| 66 | + [], // mime filter |
| 67 | + false, // modal |
| 68 | + FilePickerType.Choose, // type |
| 69 | + '', |
| 70 | + { |
| 71 | + target: this.$refs.picker, |
| 72 | + }, |
| 73 | + ) |
| 74 | + }, |
| 75 | + submit(fileId) { |
| 76 | + const fileLink = window.location.protocol + '//' + window.location.host |
| 77 | + + generateUrl('/f/{fileId}', { fileId }) |
| 78 | + this.$emit('submit', fileLink) |
| 79 | + }, |
| 80 | + }, |
| 81 | +} |
| 82 | +</script> |
| 83 | + |
| 84 | +<style scoped lang="scss"> |
| 85 | +.reference-file-picker { |
| 86 | + flex-grow: 1; |
| 87 | + margin-top: 44px; |
| 88 | +
|
| 89 | + &:deep(.oc-dialog) { |
| 90 | + transform: none !important; |
| 91 | + box-shadow: none !important; |
| 92 | + flex-grow: 1 !important; |
| 93 | + position: static !important; |
| 94 | + width: 100% !important; |
| 95 | + height: auto !important; |
| 96 | + padding: 0 !important; |
| 97 | + max-width: initial; |
| 98 | +
|
| 99 | + .oc-dialog-close { |
| 100 | + display: none; |
| 101 | + } |
| 102 | +
|
| 103 | + .oc-dialog-buttonrow.onebutton.aside { |
| 104 | + position: absolute; |
| 105 | + padding: 12px 32px; |
| 106 | + } |
| 107 | +
|
| 108 | + .oc-dialog-content { |
| 109 | + max-width: 100% !important; |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | +</style> |
0 commit comments