2022-05-19 17:13:34 +08:00
|
|
|
<template>
|
2023-07-24 19:28:44 +08:00
|
|
|
<div class="content__attachments" :id='"content__attachments-" + parent.id'>
|
|
|
|
<div class="content__attachments-actions">
|
2022-05-19 17:13:34 +08:00
|
|
|
<div class="title">
|
2022-07-11 18:31:54 +08:00
|
|
|
<h3>{{ i18n.t('protocols.steps.files', {count: attachments.length}) }}</h3>
|
2022-05-19 17:13:34 +08:00
|
|
|
</div>
|
2023-07-25 21:10:09 +08:00
|
|
|
<div class="flex items-center gap-2" v-if="parent.attributes.attachments_manageble && attachmentsReady">
|
2022-08-18 17:35:30 +08:00
|
|
|
<div ref="actionsDropdownButton" class="dropdown sci-dropdown">
|
2022-05-19 17:13:34 +08:00
|
|
|
<button class="btn btn-light dropdown-toggle" type="button" id="dropdownAttachmentsOptions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
2023-08-11 20:48:20 +08:00
|
|
|
<span>{{ i18n.t("attachments.preview_menu") }}</span>
|
2023-06-19 21:45:22 +08:00
|
|
|
<span class="sn-icon sn-icon-down"></span>
|
2022-05-19 17:13:34 +08:00
|
|
|
</button>
|
2022-08-18 17:35:30 +08:00
|
|
|
<ul ref="actionsDropdown" class="dropdown-menu dropdown-menu-right dropdown-attachment-options"
|
2022-05-19 17:13:34 +08:00
|
|
|
aria-labelledby="dropdownAttachmentsOptions"
|
2023-07-24 19:28:44 +08:00
|
|
|
:data-parent-id="parent.id"
|
2022-05-19 17:13:34 +08:00
|
|
|
>
|
2023-07-24 19:28:44 +08:00
|
|
|
<template v-if="parent.attributes.urls.update_asset_view_mode_url">
|
2022-06-03 17:52:10 +08:00
|
|
|
<li v-for="(viewMode, index) in viewModeOptions" :key="`viewMode_${index}`">
|
|
|
|
<a
|
|
|
|
class="attachments-view-mode action-link"
|
2023-07-24 19:28:44 +08:00
|
|
|
:class="viewMode == parent.attributes.assets_view_mode ? 'selected' : ''"
|
2022-06-03 17:52:10 +08:00
|
|
|
@click="changeAttachmentsViewMode(viewMode)"
|
2023-08-11 20:48:20 +08:00
|
|
|
v-html="i18n.t(`attachments.view_mode.${viewMode}_html`)"
|
2022-06-03 17:52:10 +08:00
|
|
|
></a>
|
|
|
|
</li>
|
|
|
|
</template>
|
2022-05-19 17:13:34 +08:00
|
|
|
</ul>
|
|
|
|
</div>
|
2023-07-25 21:10:09 +08:00
|
|
|
<div ref="sortDropdownButton" class="dropdown sci-dropdown">
|
|
|
|
<button class="btn btn-light icon-btn dropdown-toggle" type="button" id="dropdownSortAttachmentsOptions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
|
|
|
<i class="sn-icon sn-icon-sort-up"></i>
|
|
|
|
</button>
|
|
|
|
<ul ref="sortDropdown" class="dropdown-menu dropdown-menu-right dropdown-attachment-options"
|
|
|
|
aria-labelledby="dropdownSortAttachmentsOptions"
|
|
|
|
:data-parent-id="parent.id"
|
|
|
|
>
|
|
|
|
<li v-for="(orderOption, index) in orderOptions" :key="`orderOption_${index}`" :class="{'divider' : (orderOption == 'divider')}">
|
|
|
|
<a v-if="orderOption != 'divider'" class="action-link change-order"
|
|
|
|
@click="changeAttachmentsOrder(orderOption)"
|
|
|
|
:class="parent.attributes.assets_order == orderOption ? 'selected' : ''"
|
|
|
|
>
|
|
|
|
{{ i18n.t(`general.sort_new.${orderOption}`) }}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2022-05-19 17:13:34 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-07-24 19:28:44 +08:00
|
|
|
<div class="attachments" :data-parent-id="parent.id">
|
2022-05-19 17:13:34 +08:00
|
|
|
<template v-for="(attachment, index) in attachmentsOrdered">
|
|
|
|
<component
|
2022-05-23 19:40:23 +08:00
|
|
|
:is="attachment_view_mode(attachmentsOrdered[index])"
|
2022-07-26 19:42:25 +08:00
|
|
|
:key="attachment.id"
|
|
|
|
:attachment="attachment"
|
2023-07-24 19:28:44 +08:00
|
|
|
:parentId="parseInt(parent.id)"
|
2022-05-19 17:13:34 +08:00
|
|
|
@attachment:viewMode="updateAttachmentViewMode"
|
2022-07-26 19:42:25 +08:00
|
|
|
@attachment:delete="deleteAttachment(attachment.id)"
|
2023-08-24 21:55:20 +08:00
|
|
|
@attachment:moved="attachmentMoved"
|
2022-05-19 17:13:34 +08:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2023-08-24 21:55:20 +08:00
|
|
|
import AttachmentMovedMixin from './attachments/mixins/attachment_moved.js'
|
2023-07-24 19:28:44 +08:00
|
|
|
import listAttachment from './attachments/list.vue'
|
|
|
|
import inlineAttachment from './attachments/inline.vue'
|
|
|
|
import thumbnailAttachment from './attachments/thumbnail.vue'
|
|
|
|
import uploadingAttachment from './attachments/uploading.vue'
|
|
|
|
import emptyAttachment from './attachments/empty.vue'
|
2022-05-19 17:13:34 +08:00
|
|
|
|
2023-07-24 19:28:44 +08:00
|
|
|
import WopiFileModal from './attachments/mixins/wopi_file_modal.js'
|
2022-08-01 19:14:04 +08:00
|
|
|
|
2022-05-19 17:13:34 +08:00
|
|
|
export default {
|
|
|
|
name: 'Attachments',
|
|
|
|
props: {
|
|
|
|
attachments: {
|
|
|
|
type: Array,
|
|
|
|
required: true
|
|
|
|
},
|
2023-07-24 19:28:44 +08:00
|
|
|
parent: {
|
2022-05-19 17:13:34 +08:00
|
|
|
type: Object,
|
|
|
|
required: true
|
2022-09-02 21:09:56 +08:00
|
|
|
},
|
|
|
|
attachmentsReady: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true
|
2022-05-19 17:13:34 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
viewModeOptions: ['inline', 'thumbnail', 'list'],
|
2023-07-25 21:10:09 +08:00
|
|
|
orderOptions: ['new', 'old', 'divider', 'atoz', 'ztoa']
|
2022-05-19 17:13:34 +08:00
|
|
|
}
|
|
|
|
},
|
2023-08-24 21:55:20 +08:00
|
|
|
mixins: [WopiFileModal, AttachmentMovedMixin],
|
2022-05-19 17:13:34 +08:00
|
|
|
components: {
|
|
|
|
thumbnailAttachment,
|
|
|
|
inlineAttachment,
|
|
|
|
listAttachment,
|
2022-09-02 21:09:56 +08:00
|
|
|
uploadingAttachment,
|
|
|
|
emptyAttachment
|
2022-05-19 17:13:34 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
attachmentsOrdered() {
|
|
|
|
return this.attachments.sort((a, b) => {
|
|
|
|
if (a.attributes.asset_order == b.attributes.asset_order) {
|
2023-07-24 19:28:44 +08:00
|
|
|
switch(this.parent.attributes.assets_order) {
|
2022-05-19 17:13:34 +08:00
|
|
|
case 'new':
|
|
|
|
return b.attributes.updated_at - a.attributes.updated_at;
|
|
|
|
case 'old':
|
|
|
|
return a.attributes.updated_at - b.attributes.updated_at;
|
|
|
|
case 'atoz':
|
|
|
|
return a.attributes.file_name.toLowerCase() > b.attributes.file_name.toLowerCase() ? 1 : -1;
|
|
|
|
case 'ztoa':
|
|
|
|
return b.attributes.file_name.toLowerCase() > a.attributes.file_name.toLowerCase() ? 1 : -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return a.attributes.asset_order > b.attributes.asset_order ? 1 : -1;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2022-07-21 20:28:21 +08:00
|
|
|
mounted() {
|
|
|
|
this.initMarvinJS();
|
2022-08-18 17:35:30 +08:00
|
|
|
$(this.$refs.actionsDropdownButton).on('shown.bs.dropdown hidden.bs.dropdown', this.handleDropdownPosition);
|
2022-07-21 20:28:21 +08:00
|
|
|
},
|
2022-05-19 17:13:34 +08:00
|
|
|
methods: {
|
|
|
|
changeAttachmentsOrder(order) {
|
|
|
|
this.$emit('attachments:order', order)
|
|
|
|
},
|
|
|
|
changeAttachmentsViewMode(viewMode) {
|
|
|
|
this.$emit('attachments:viewMode', viewMode)
|
|
|
|
},
|
|
|
|
updateAttachmentViewMode(id, viewMode) {
|
|
|
|
this.$emit('attachment:viewMode', id, viewMode)
|
2022-05-23 19:40:23 +08:00
|
|
|
},
|
|
|
|
attachment_view_mode(attachment) {
|
|
|
|
if (attachment.attributes.uploading) {
|
|
|
|
return 'uploadingAttachment'
|
2022-09-02 21:09:56 +08:00
|
|
|
} else if (!attachment.attributes.attached) {
|
|
|
|
return 'emptyAttachment'
|
2022-05-23 19:40:23 +08:00
|
|
|
}
|
|
|
|
return `${attachment.attributes.view_mode}Attachment`
|
2022-07-15 19:46:48 +08:00
|
|
|
},
|
2022-07-26 19:42:25 +08:00
|
|
|
deleteAttachment(id) {
|
2023-08-24 21:55:20 +08:00
|
|
|
this.$emit('attachment:deleted', id, )
|
2022-07-15 19:46:48 +08:00
|
|
|
},
|
2022-07-21 20:28:21 +08:00
|
|
|
initMarvinJS() {
|
|
|
|
// legacy logic from app/assets/javascripts/sitewide/marvinjs_editor.js
|
|
|
|
MarvinJsEditor.initNewButton(
|
2023-07-24 19:28:44 +08:00
|
|
|
`#content__attachments-${this.parent.id} .new-marvinjs-upload-button`,
|
2022-07-21 20:28:21 +08:00
|
|
|
() => this.$emit('attachment:uploaded')
|
|
|
|
);
|
2022-08-01 19:14:04 +08:00
|
|
|
},
|
|
|
|
openWopiFileModal() {
|
2023-07-24 19:28:44 +08:00
|
|
|
this.initWopiFileModal(this.parent, (_e, data, status) => {
|
2022-08-01 19:14:04 +08:00
|
|
|
if (status === 'success') {
|
|
|
|
this.$emit('attachment:uploaded', data);
|
|
|
|
} else {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger');
|
|
|
|
}
|
|
|
|
});
|
2022-08-18 17:35:30 +08:00
|
|
|
},
|
|
|
|
handleDropdownPosition() {
|
|
|
|
this.$refs.actionsDropdownButton.classList.toggle("dropup", !this.isInViewport(this.$refs.actionsDropdown));
|
|
|
|
},
|
|
|
|
isInViewport(el) {
|
|
|
|
let rect = el.getBoundingClientRect();
|
|
|
|
|
|
|
|
return (
|
|
|
|
rect.top >= 0 &&
|
|
|
|
rect.left >= 0 &&
|
|
|
|
rect.bottom <= (window.innerHeight || $(window).height()) &&
|
|
|
|
rect.right <= (window.innerWidth || $(window).width())
|
|
|
|
);
|
|
|
|
},
|
2022-05-19 17:13:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|