2022-05-17 16:39:17 +08:00
|
|
|
<template>
|
2023-09-15 18:39:56 +08:00
|
|
|
<div class="asset-context-menu" ref="menu">
|
|
|
|
<a class="marvinjs-edit-button hidden"
|
|
|
|
v-if="attachment.attributes.asset_type == 'marvinjs' && attachment.attributes.urls.marvin_js_start_edit"
|
|
|
|
ref="marvinjsEditButton"
|
|
|
|
:data-sketch-id="attachment.id"
|
|
|
|
:data-update-url="attachment.attributes.urls.marvin_js"
|
|
|
|
:data-sketch-start-edit-url="attachment.attributes.urls.marvin_js_start_edit"
|
|
|
|
:data-sketch-name="attachment.attributes.metadata.name"
|
|
|
|
:data-sketch-description="attachment.attributes.metadata.description"
|
|
|
|
></a>
|
|
|
|
<a class="image-edit-button hidden"
|
|
|
|
v-if="attachment.attributes.asset_type != 'marvinjs'
|
|
|
|
&& attachment.attributes.image_editable
|
|
|
|
&& attachment.attributes.urls.start_edit_image"
|
|
|
|
ref="imageEditButton"
|
|
|
|
:data-image-id="attachment.id"
|
|
|
|
:data-image-name="attachment.attributes.file_name"
|
|
|
|
:data-image-url="attachment.attributes.urls.asset_file"
|
|
|
|
:data-image-quality="attachment.attributes.image_context.quality"
|
|
|
|
:data-image-mime-type="attachment.attributes.image_context.type"
|
|
|
|
:data-image-start-edit-url="attachment.attributes.urls.start_edit_image"
|
|
|
|
></a>
|
|
|
|
<MenuDropdown
|
|
|
|
class="ml-auto"
|
|
|
|
:listItems="this.menu"
|
2023-09-18 21:32:53 +08:00
|
|
|
:btnClasses="`btn btn-sm icon-btn !bg-sn-white ${ withBorder ? 'btn-secondary' : 'btn-light'}`"
|
2023-09-15 18:39:56 +08:00
|
|
|
:position="'right'"
|
|
|
|
:btnIcon="'sn-icon sn-icon-more-hori'"
|
|
|
|
@open_ove_editor="openOVEditor(attachment.attributes.urls.open_vector_editor_edit)"
|
|
|
|
@open_marvinjs_editor="openMarvinJsEditor"
|
|
|
|
@open_scinote_editor="openScinoteEditor"
|
|
|
|
@delete="deleteModal = true"
|
|
|
|
@viewMode="changeViewMode"
|
|
|
|
@move="showMoveModal"
|
|
|
|
></MenuDropdown>
|
2022-05-17 16:39:17 +08:00
|
|
|
<deleteAttachmentModal
|
|
|
|
v-if="deleteModal"
|
2022-10-19 17:12:27 +08:00
|
|
|
:fileName="attachment.attributes.file_name"
|
2022-05-17 16:39:17 +08:00
|
|
|
@confirm="deleteAttachment"
|
|
|
|
@cancel="deleteModal = false"
|
|
|
|
/>
|
2023-08-24 21:55:20 +08:00
|
|
|
<moveAssetModal v-if="movingAttachment"
|
|
|
|
:parent_type="attachment.attributes.parent_type"
|
|
|
|
:targets_url="attachment.attributes.urls.move_targets"
|
|
|
|
@confirm="moveAttachment($event)" @cancel="closeMoveModal"/>
|
2022-05-17 16:39:17 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import deleteAttachmentModal from './delete_modal.vue'
|
2023-08-24 21:55:20 +08:00
|
|
|
import moveAssetModal from '../modal/move.vue'
|
|
|
|
import MoveMixin from './mixins/move.js'
|
2023-09-15 18:39:56 +08:00
|
|
|
import MenuDropdown from '../../menu_dropdown.vue'
|
2022-05-17 16:39:17 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'contextMenu',
|
2023-09-15 18:39:56 +08:00
|
|
|
components: { deleteAttachmentModal, moveAssetModal, MenuDropdown },
|
2023-08-24 21:55:20 +08:00
|
|
|
mixins: [MoveMixin],
|
2022-05-17 16:39:17 +08:00
|
|
|
props: {
|
|
|
|
attachment: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
2023-09-18 21:32:53 +08:00
|
|
|
},
|
|
|
|
withBorder: {default: false, type: Boolean }
|
2022-05-17 16:39:17 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
viewModeOptions: ['inline', 'thumbnail', 'list'],
|
|
|
|
deleteModal: false
|
|
|
|
}
|
|
|
|
},
|
2023-09-15 18:39:56 +08:00
|
|
|
computed: {
|
|
|
|
menu() {
|
|
|
|
let menu = [];
|
|
|
|
if (this.attachment.attributes.wopi && this.attachment.attributes.urls.edit_asset) {
|
|
|
|
menu.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 == 'gene_sequence' && this.attachment.attributes.urls.open_vector_editor_edit) {
|
|
|
|
menu.push({
|
|
|
|
text: this.i18n.t('open_vector_editor.edit_sequence'),
|
|
|
|
emit: 'open_ove_editor',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (this.attachment.attributes.asset_type == 'marvinjs' && this.attachment.attributes.urls.marvin_js_start_edit) {
|
|
|
|
menu.push({
|
|
|
|
text: this.i18n.t('assets.file_preview.edit_in_marvinjs'),
|
|
|
|
emit: 'open_marvinjs_editor',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (this.attachment.attributes.asset_type != 'marvinjs'
|
|
|
|
&& this.attachment.attributes.image_editable
|
|
|
|
&& this.attachment.attributes.urls.start_edit_image) {
|
|
|
|
menu.push({
|
|
|
|
text: this.i18n.t('assets.file_preview.edit_in_scinote'),
|
|
|
|
emit: 'open_scinote_editor',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
menu.push({
|
|
|
|
text: this.i18n.t('Download'),
|
|
|
|
url: this.attachment.attributes.urls.download,
|
|
|
|
url_target: '_blank'
|
|
|
|
})
|
|
|
|
if (this.attachment.attributes.urls.move_targets) {
|
|
|
|
menu.push({
|
|
|
|
text: this.i18n.t('assets.context_menu.move'),
|
|
|
|
emit: 'move'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (this.attachment.attributes.urls.delete) {
|
|
|
|
menu.push({
|
|
|
|
text: this.i18n.t('assets.context_menu.delete'),
|
|
|
|
emit: 'delete'
|
|
|
|
})
|
2022-05-17 16:39:17 +08:00
|
|
|
}
|
2023-09-15 18:39:56 +08:00
|
|
|
if (this.attachment.attributes.urls.toggle_view_mode) {
|
|
|
|
this.viewModeOptions.forEach((viewMode, i) => {
|
|
|
|
menu.push({
|
2023-09-25 21:03:35 +08:00
|
|
|
active: this.attachment.attributes.view_mode == viewMode,
|
2023-09-15 18:39:56 +08:00
|
|
|
text: this.i18n.t(`assets.context_menu.${viewMode}_html`),
|
|
|
|
emit: 'viewMode',
|
|
|
|
params: viewMode,
|
|
|
|
dividerBefore: i === 0
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return menu;
|
|
|
|
}
|
2022-05-17 16:39:17 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
changeViewMode(viewMode) {
|
|
|
|
this.$emit('attachment:viewMode', viewMode)
|
|
|
|
$.ajax({
|
|
|
|
url: this.attachment.attributes.urls.toggle_view_mode,
|
|
|
|
type: 'PATCH',
|
|
|
|
dataType: 'json',
|
|
|
|
data: { asset: { view_mode: viewMode } }
|
2023-09-22 16:36:07 +08:00
|
|
|
}).done(data => {
|
|
|
|
this.$nextTick(function() {
|
|
|
|
$(`.asset[data-asset-id=${this.attachment.id}] img`)
|
|
|
|
.replaceWith($(data.html).find(`.asset[data-asset-id=${this.attachment.id}] img`));
|
|
|
|
ActiveStoragePreviews.reloadPreview(`.asset[data-asset-id=${this.attachment.id}] img`);
|
|
|
|
})
|
2022-05-17 16:39:17 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
deleteAttachment() {
|
|
|
|
this.deleteModal = false
|
|
|
|
this.$emit('attachment:delete')
|
2023-08-02 20:13:04 +08:00
|
|
|
},
|
|
|
|
openOVEditor(url) {
|
|
|
|
window.showIFrameModal(url);
|
2023-09-15 18:39:56 +08:00
|
|
|
},
|
2023-10-05 21:44:41 +08:00
|
|
|
reloadAttachments() {
|
|
|
|
this.$emit('attachment:uploaded');
|
|
|
|
},
|
2023-09-15 18:39:56 +08:00
|
|
|
openMarvinJsEditor() {
|
2023-10-05 21:44:41 +08:00
|
|
|
MarvinJsEditor.initNewButton(
|
|
|
|
this.$refs.marvinjsEditButton,
|
|
|
|
this.reloadAttachments
|
|
|
|
);
|
2023-09-15 18:39:56 +08:00
|
|
|
$(this.$refs.marvinjsEditButton).trigger('click');
|
|
|
|
},
|
|
|
|
openScinoteEditor() {
|
|
|
|
$(this.$refs.imageEditButton).trigger('click');
|
|
|
|
},
|
2022-05-17 16:39:17 +08:00
|
|
|
}
|
|
|
|
}
|
2022-05-18 17:12:53 +08:00
|
|
|
</script>
|