2022-05-12 23:05:07 +08:00
|
|
|
<template>
|
2024-03-20 23:06:46 +08:00
|
|
|
<div
|
|
|
|
class="inline-attachment-container asset"
|
|
|
|
:class="[{'menu-dropdown-open': isMenuDropdownOpen}, {'context-menu-open': isContextMenuOpen }]"
|
|
|
|
ref="inlineAttachmentContainer"
|
|
|
|
:data-asset-id="attachment.id"
|
2022-05-13 19:07:50 +08:00
|
|
|
>
|
2024-03-20 23:06:46 +08:00
|
|
|
<div class="header justify-between">
|
2022-05-13 19:07:50 +08:00
|
|
|
<div class="file-info">
|
|
|
|
<a :href="attachment.attributes.urls.blob"
|
|
|
|
class="file-preview-link file-name"
|
|
|
|
:id="`modal_link${attachment.id}`"
|
|
|
|
data-no-turbolink="true"
|
|
|
|
:data-id="attachment.id"
|
2023-07-24 19:28:44 +08:00
|
|
|
:data-gallery-view-id="parentId"
|
2022-05-13 19:07:50 +08:00
|
|
|
:data-preview-url="attachment.attributes.urls.preview"
|
|
|
|
>
|
2023-02-28 13:59:45 +08:00
|
|
|
<span data-toggle="tooltip"
|
|
|
|
data-placement="bottom"
|
2022-08-16 18:20:37 +08:00
|
|
|
:title="`${ attachment.attributes.file_name }`">
|
|
|
|
{{ attachment.attributes.file_name }}
|
|
|
|
</span>
|
2022-05-13 19:07:50 +08:00
|
|
|
</a>
|
|
|
|
<div class="file-metadata">
|
|
|
|
<span>
|
2022-05-16 17:05:18 +08:00
|
|
|
{{ attachment.attributes.updated_at_formatted }}
|
2022-05-13 19:07:50 +08:00
|
|
|
</span>
|
|
|
|
<span>
|
2024-03-20 23:06:46 +08:00
|
|
|
{{ attachment.attributes.file_size_formatted }}
|
2022-05-13 19:07:50 +08:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-03-20 23:06:46 +08:00
|
|
|
<div class="inline-attachment-action-buttons">
|
|
|
|
<!-- open -->
|
|
|
|
<OpenMenu
|
|
|
|
:attachment="attachment"
|
|
|
|
:multipleOpenOptions="multipleOpenOptions"
|
|
|
|
@menu-dropdown-toggle="toggleMenuDropdown"
|
|
|
|
>
|
|
|
|
</OpenMenu>
|
|
|
|
|
|
|
|
<!-- move -->
|
|
|
|
<a v-if="attachment.attributes.urls.move"
|
|
|
|
@click.prevent.stop="showMoveModal"
|
|
|
|
class="btn btn-light icon-btn thumbnail-action-btn"
|
|
|
|
:title="i18n.t('attachments.thumbnail.buttons.move')">
|
|
|
|
<i class="sn-icon sn-icon-move"></i>
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<!-- download -->
|
|
|
|
<a class="btn btn-light icon-btn thumbnail-action-btn"
|
|
|
|
:title="i18n.t('attachments.thumbnail.buttons.download')"
|
|
|
|
:href="attachment.attributes.urls.download" data-turbolinks="false">
|
|
|
|
<i class="sn-icon sn-icon-export"></i>
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<!-- more options -->
|
|
|
|
<ContextMenu
|
|
|
|
:attachment="attachment"
|
|
|
|
@attachment:viewMode="updateViewMode"
|
|
|
|
@attachment:delete="deleteAttachment"
|
|
|
|
@attachment:moved="attachmentMoved"
|
|
|
|
@attachment:uploaded="reloadAttachments"
|
|
|
|
@menu-toggle="toggleContextMenu"
|
|
|
|
/>
|
|
|
|
</div>
|
2022-05-13 19:07:50 +08:00
|
|
|
</div>
|
|
|
|
<template v-if="attachment.attributes.wopi">
|
2023-05-30 21:49:38 +08:00
|
|
|
<div v-if="showWopi"
|
2022-05-13 19:07:50 +08:00
|
|
|
class="iframe-placeholder"
|
|
|
|
:data-iframe-url="attachment.attributes.urls.wopi_action"></div>
|
|
|
|
<div v-else class="empty-office-file">
|
|
|
|
<h2>{{ i18n.t('assets.empty_office_file.description') }}</h2>
|
|
|
|
<a :href="attachment.attributes.urls.load_asset"
|
|
|
|
class="btn btn-primary reload-asset"
|
2023-05-30 21:49:38 +08:00
|
|
|
@click.prevent="reloadAsset">
|
2022-05-13 19:07:50 +08:00
|
|
|
{{ i18n.t('assets.empty_office_file.reload') }}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</template>
|
2023-05-16 16:24:08 +08:00
|
|
|
<template v-else-if="attachment.attributes.pdf_previewable && attachment.attributes.pdf !== null">
|
2022-08-09 16:13:43 +08:00
|
|
|
<PdfViewer :pdf="attachment.attributes.pdf" />
|
2022-05-13 19:07:50 +08:00
|
|
|
</template>
|
|
|
|
<template v-else-if="attachment.attributes.large_preview !== null">
|
|
|
|
<div class="image-container">
|
2022-05-16 17:05:18 +08:00
|
|
|
<img :src="attachment.attributes.large_preview"
|
2022-05-13 19:07:50 +08:00
|
|
|
style='opacity: 0' />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<div class="general-file-container">
|
2023-10-04 22:16:55 +08:00
|
|
|
<i class="text-sn-grey sn-icon" :class="attachment.attributes.icon"></i>
|
2022-05-13 19:07:50 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
2022-05-12 23:05:07 +08:00
|
|
|
</div>
|
2024-03-20 23:06:46 +08:00
|
|
|
<Teleport to="body">
|
|
|
|
<MoveAssetModal
|
|
|
|
v-if="movingAttachment"
|
|
|
|
:parent_type="attachment.attributes.parent_type"
|
|
|
|
:targets_url="attachment.attributes.urls.move_targets"
|
|
|
|
@confirm="moveAttachment($event)" @cancel="closeMoveModal"
|
|
|
|
/>
|
|
|
|
</Teleport>
|
2022-05-12 23:05:07 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-01-04 23:34:36 +08:00
|
|
|
import AttachmentMovedMixin from './mixins/attachment_moved.js';
|
|
|
|
import ContextMenuMixin from './mixins/context_menu.js';
|
|
|
|
import ContextMenu from './context_menu.vue';
|
|
|
|
import PdfViewer from '../../pdf_viewer.vue';
|
2024-03-20 23:06:46 +08:00
|
|
|
import MoveAssetModal from '../modal/move.vue';
|
|
|
|
import MoveMixin from './mixins/move.js';
|
|
|
|
import OpenLocallyMixin from './mixins/open_locally.js';
|
|
|
|
import OpenMenu from './open_menu.vue';
|
2022-05-17 16:39:17 +08:00
|
|
|
|
2024-01-04 23:34:36 +08:00
|
|
|
export default {
|
|
|
|
name: 'inlineAttachment',
|
2024-03-20 23:06:46 +08:00
|
|
|
mixins: [ContextMenuMixin, AttachmentMovedMixin, MoveMixin, OpenLocallyMixin],
|
|
|
|
components: {
|
|
|
|
ContextMenu,
|
|
|
|
PdfViewer,
|
|
|
|
MoveAssetModal,
|
|
|
|
OpenMenu
|
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
props: {
|
|
|
|
attachment: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
2022-05-13 19:07:50 +08:00
|
|
|
},
|
2024-01-04 23:34:36 +08:00
|
|
|
parentId: {
|
|
|
|
type: Number,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2024-03-20 23:06:46 +08:00
|
|
|
showWopi: false,
|
|
|
|
isMenuDropdownOpen: false,
|
|
|
|
isContextMenuOpen: false
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.showWopi = this.attachment.attributes.file_size > 0;
|
|
|
|
$(this.$nextTick(() => {
|
|
|
|
$('.image-container img')
|
|
|
|
.on('error', (event) => ActiveStoragePreviews.reCheckPreview(event))
|
|
|
|
.on('load', (event) => ActiveStoragePreviews.showPreview(event));
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
reloadAsset() {
|
|
|
|
$.ajax({
|
|
|
|
method: 'GET',
|
|
|
|
url: this.attachment.attributes.urls.load_asset,
|
|
|
|
data: {
|
|
|
|
asset: { view_mode: this.attachment.attributes.view_mode }
|
|
|
|
},
|
|
|
|
success: (data) => {
|
|
|
|
if (!(data.html.includes('empty-office-file'))) {
|
|
|
|
this.showWopi = true;
|
2023-05-30 21:49:38 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
}
|
|
|
|
});
|
2024-03-20 23:06:46 +08:00
|
|
|
},
|
|
|
|
toggleContextMenu(isOpen) {
|
|
|
|
this.isContextMenuOpen = isOpen;
|
|
|
|
},
|
|
|
|
toggleMenuDropdown(isOpen) {
|
|
|
|
this.isMenuDropdownOpen = isOpen;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
multipleOpenOptions() {
|
|
|
|
const options = [];
|
|
|
|
if (this.attachment.attributes.wopi && this.attachment.attributes.urls.edit_asset) {
|
|
|
|
options.push({
|
|
|
|
text: this.attachment.attributes.wopi_context.button_text,
|
|
|
|
url: this.attachment.attributes.urls.edit_asset,
|
|
|
|
url_target: '_blank'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.attachment.attributes.asset_type !== 'marvinjs'
|
|
|
|
&& this.attachment.attributes.image_editable
|
|
|
|
&& this.attachment.attributes.urls.start_edit_image) {
|
|
|
|
options.push({
|
|
|
|
text: this.i18n.t('assets.file_preview.edit_in_scinote'),
|
|
|
|
emit: 'open_scinote_editor'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.canOpenLocally) {
|
|
|
|
const text = this.localAppName
|
|
|
|
? this.i18n.t('attachments.open_locally_in', { application: this.localAppName })
|
|
|
|
: this.i18n.t('attachments.open_locally');
|
|
|
|
|
|
|
|
options.push({
|
|
|
|
text,
|
|
|
|
emit: 'open_locally',
|
|
|
|
data_e2e: 'e2e-BT-attachmentOptions-openLocally'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return options;
|
2024-01-04 23:34:36 +08:00
|
|
|
}
|
2022-05-12 23:05:07 +08:00
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
2022-05-12 23:05:07 +08:00
|
|
|
</script>
|