2023-12-14 03:54:41 +08:00
|
|
|
<template>
|
|
|
|
<div class="sn-open-locally-menu">
|
2024-01-22 23:41:10 +08:00
|
|
|
<div v-if="!this.canOpenLocally && (this.attachment.attributes.wopi && this.attachment.attributes.urls.edit_asset)">
|
|
|
|
<a :href="`${this.attachment.attributes.urls.edit_asset}`" target="_blank"
|
2024-01-04 07:13:21 +08:00
|
|
|
class="block whitespace-nowrap rounded px-3 py-2.5
|
|
|
|
hover:!text-sn-blue hover:no-underline cursor-pointer hover:bg-sn-super-light-grey">
|
2024-01-22 23:41:10 +08:00
|
|
|
{{ this.attachment.attributes.wopi_context.button_text }}
|
2023-12-14 03:54:41 +08:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
<MenuDropdown
|
2024-01-22 23:41:10 +08:00
|
|
|
v-if="this.menu.length > 1"
|
2023-12-14 03:54:41 +08:00
|
|
|
class="ml-auto"
|
|
|
|
:listItems="this.menu"
|
|
|
|
:btnClasses="`btn btn-light icon-btn !bg-sn-white`"
|
|
|
|
:position="'right'"
|
2024-01-22 23:41:10 +08:00
|
|
|
:btnText="i18n.t('attachments.open_in')"
|
|
|
|
:caret="true"
|
|
|
|
@openLocally="openLocally"
|
|
|
|
@openImageEditor="openImageEditor"
|
2023-12-14 03:54:41 +08:00
|
|
|
></MenuDropdown>
|
2024-01-22 23:41:10 +08:00
|
|
|
<a v-else-if="this.menu.length === 1" class="btn btn-light !bg-sn-white" :href="this.menu[0].url" :target="this.menu[0].target" @click="this[this.menu[0].emit]()">
|
|
|
|
{{ this.menu[0].text }}
|
|
|
|
</a>
|
2023-12-14 03:54:41 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-01-04 07:13:21 +08:00
|
|
|
import OpenLocallyMixin from './mixins/open_locally.js';
|
|
|
|
import MenuDropdown from '../../menu_dropdown.vue';
|
2023-12-14 03:54:41 +08:00
|
|
|
|
2024-01-04 07:13:21 +08:00
|
|
|
export default {
|
|
|
|
name: 'OpenLocallyMenu',
|
|
|
|
mixins: [OpenLocallyMixin],
|
|
|
|
components: { MenuDropdown },
|
|
|
|
props: {
|
|
|
|
data: { type: String, required: true },
|
|
|
|
},
|
|
|
|
created() {
|
2024-01-22 23:41:10 +08:00
|
|
|
this.attachment = { attributes: JSON.parse(this.data) };
|
|
|
|
this.fetchLocalAppInfo();
|
2024-01-04 07:13:21 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
menu() {
|
|
|
|
const menu = [];
|
2023-12-14 03:54:41 +08:00
|
|
|
|
2024-01-22 23:41:10 +08:00
|
|
|
if (this.attachment.attributes.wopi && this.attachment.attributes.urls.edit_asset) {
|
2024-01-04 07:13:21 +08:00
|
|
|
menu.push({
|
2024-01-22 23:41:10 +08:00
|
|
|
text: this.attachment.attributes.wopi_context.button_text,
|
|
|
|
url: this.attachment.attributes.urls.edit_asset,
|
|
|
|
url_target: '_blank'
|
2024-01-17 00:31:12 +08:00
|
|
|
});
|
2024-01-04 07:13:21 +08:00
|
|
|
}
|
2024-01-22 23:41:10 +08:00
|
|
|
|
|
|
|
if (this.attachment.attributes.image_editable) {
|
|
|
|
menu.push({
|
|
|
|
text: this.i18n.t('assets.file_preview.edit_in_scinote'),
|
|
|
|
emit: 'openImageEditor'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-04 07:13:21 +08:00
|
|
|
if (this.canOpenLocally) {
|
|
|
|
const text = this.localAppName
|
|
|
|
? this.i18n.t('attachments.open_locally_in', { application: this.localAppName })
|
|
|
|
: this.i18n.t('attachments.open_locally');
|
2023-12-19 16:19:19 +08:00
|
|
|
|
2024-01-04 07:13:21 +08:00
|
|
|
menu.push({
|
|
|
|
text,
|
2024-01-22 23:41:10 +08:00
|
|
|
emit: 'openLocally'
|
2024-01-04 07:13:21 +08:00
|
|
|
});
|
2023-12-14 03:54:41 +08:00
|
|
|
}
|
2024-01-04 07:13:21 +08:00
|
|
|
|
|
|
|
return menu;
|
|
|
|
},
|
|
|
|
},
|
2024-01-22 23:41:10 +08:00
|
|
|
methods: {
|
|
|
|
openImageEditor() {
|
|
|
|
document.getElementById('editImageButton').click();
|
|
|
|
}
|
|
|
|
}
|
2024-01-04 07:13:21 +08:00
|
|
|
};
|
2023-12-14 03:54:41 +08:00
|
|
|
</script>
|