Files
online.tbbank.gov.tm-larave…/nova/resources/js/fields/Detail/AudioField.vue
2024-09-01 18:54:23 +05:00

83 lines
2.0 KiB
Vue

<template>
<PanelItem :index="index" :field="field">
<template #value>
<audio
v-if="hasPreviewableAudio"
v-bind="defaultAttributes"
class="w-full"
:src="field.previewUrl"
controls
controlslist="nodownload"
/>
<span v-if="!hasPreviewableAudio">&mdash;</span>
<p v-if="shouldShowToolbar" class="flex items-center text-sm mt-3">
<a
v-if="field.downloadable"
:dusk="field.attribute + '-download-link'"
@keydown.enter.prevent="download"
@click.prevent="download"
tabindex="0"
class="cursor-pointer text-gray-500 inline-flex items-center"
>
<Icon
class="mr-2"
type="download"
view-box="0 0 24 24"
width="16"
height="16"
/>
<span class="class mt-1">{{ __('Download') }}</span>
</a>
</p>
</template>
</PanelItem>
</template>
<script>
import isNil from 'lodash/isNil'
import { FieldValue } from '@/mixins'
export default {
mixins: [FieldValue],
props: ['index', 'resource', 'resourceName', 'resourceId', 'field'],
methods: {
/**
* Download the linked file
*/
download() {
const { resourceName, resourceId } = this
const attribute = this.field.attribute
let link = document.createElement('a')
link.href = `/nova-api/${resourceName}/${resourceId}/download/${attribute}`
link.download = 'download'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
},
},
computed: {
hasPreviewableAudio() {
return !isNil(this.field.previewUrl)
},
shouldShowToolbar() {
return Boolean(this.field.downloadable && this.fieldHasValue)
},
defaultAttributes() {
return {
src: this.field.previewUrl,
autoplay: this.field.autoplay,
preload: this.field.preload,
}
},
},
}
</script>