owntone-server/web-src/src/components/ModalDialogAddUrlStream.vue

120 lines
2.6 KiB
Vue
Raw Normal View History

<template>
2025-02-09 17:52:45 +01:00
<modal-dialog
:actions="actions"
:show="show"
:title="$t('dialog.add.stream.title')"
@close="$emit('close')"
>
2025-02-09 08:05:03 +01:00
<template #content>
<form @submit.prevent="play">
<div class="field">
<p class="control has-icons-left">
<input
ref="url_field"
v-model="url"
class="input"
type="url"
pattern="http[s]?://.+"
required
:placeholder="$t('dialog.add.stream.placeholder')"
:disabled="loading"
@input="check_url"
/>
<mdicon class="icon is-left" name="web" size="16" />
</p>
</div>
</form>
</template>
2025-02-08 14:35:25 +01:00
</modal-dialog>
</template>
<script>
2025-02-08 14:35:25 +01:00
import ModalDialog from '@/components/ModalDialog.vue'
import webapi from '@/webapi'
export default {
name: 'ModalDialogAddUrlStream',
2025-02-08 14:35:25 +01:00
components: { ModalDialog },
2024-02-27 17:18:58 +01:00
props: { show: Boolean },
2022-02-19 07:05:59 +01:00
emits: ['close'],
data() {
return {
2024-03-28 15:45:39 +01:00
disabled: true,
2024-03-26 15:00:17 +01:00
loading: false,
url: ''
}
},
computed: {
actions() {
if (this.loading) {
return [{ label: this.$t('dialog.add.stream.processing'), icon: 'web' }]
}
return [
{
label: this.$t('dialog.add.stream.cancel'),
2025-02-09 08:05:03 +01:00
handler: this.cancel,
icon: 'cancel'
},
{
label: this.$t('dialog.add.stream.add'),
disabled: this.disabled,
2025-02-09 08:05:03 +01:00
handler: this.add,
icon: 'playlist-plus'
},
{
label: this.$t('dialog.add.stream.play'),
disabled: this.disabled,
2025-02-09 08:05:03 +01:00
handler: this.play,
icon: 'play'
}
]
}
},
watch: {
show() {
if (this.show) {
this.loading = false
// Delay setting the focus on the input field until it is part of the DOM and visible
setTimeout(() => {
this.$refs.url_field.focus()
}, 10)
}
}
},
methods: {
add() {
this.loading = true
webapi
.queue_add(this.url)
.then(() => {
this.$emit('close')
this.url = ''
})
.catch(() => {
this.loading = false
})
},
2025-02-09 08:05:03 +01:00
cancel() {
this.$emit('close')
},
2024-03-28 15:45:39 +01:00
check_url(event) {
const { validity } = event.target
this.disabled = validity.patternMismatch || validity.valueMissing
},
2025-02-09 08:05:03 +01:00
play() {
this.loading = true
webapi
.player_play_uri(this.url, false)
.then(() => {
this.$emit('close')
this.url = ''
})
.catch(() => {
this.loading = false
})
}
}
}
</script>