mirror of
https://github.com/owntone/owntone-server.git
synced 2025-03-03 23:30:09 -05:00
[web] Refactor input field for URLs
This commit is contained in:
parent
b5c7dfaf59
commit
b460be8873
50
web-src/src/components/ControlUrlField.vue
Normal file
50
web-src/src/components/ControlUrlField.vue
Normal file
@ -0,0 +1,50 @@
|
||||
<template>
|
||||
<div class="field">
|
||||
<p class="control has-icons-left">
|
||||
<input
|
||||
ref="input"
|
||||
v-model="url"
|
||||
class="input"
|
||||
type="url"
|
||||
pattern="http[s]?://.+"
|
||||
required
|
||||
:placeholder="placeholder"
|
||||
:disabled="loading"
|
||||
@input="validate"
|
||||
/>
|
||||
<mdicon class="icon is-left" :name="icon" size="16" />
|
||||
</p>
|
||||
<p v-if="help" class="help" v-text="help" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'ControlUrlField',
|
||||
props: {
|
||||
placeholder: { type: String, required: true },
|
||||
icon: { type: String, required: true },
|
||||
help: { type: String, default: '' },
|
||||
loading: { type: Boolean, default: false }
|
||||
},
|
||||
emits: ['url-changed'],
|
||||
data() {
|
||||
return {
|
||||
url: '',
|
||||
disabled: true
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
setTimeout(() => {
|
||||
this.$refs.input.focus()
|
||||
}, 10)
|
||||
},
|
||||
methods: {
|
||||
validate(event) {
|
||||
const { validity } = event.target
|
||||
this.disabled = validity.patternMismatch || validity.valueMissing
|
||||
this.$emit('url-changed', this.url, this.disabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
@ -6,40 +6,31 @@
|
||||
@close="$emit('close')"
|
||||
>
|
||||
<template #content>
|
||||
<div class="field">
|
||||
<p class="control has-icons-left">
|
||||
<input
|
||||
ref="url_field"
|
||||
v-model="url"
|
||||
class="input"
|
||||
type="url"
|
||||
pattern="http[s]?://.+"
|
||||
required
|
||||
<control-url-field
|
||||
icon="rss"
|
||||
:help="$t('dialog.add.rss.help')"
|
||||
:loading="loading"
|
||||
:placeholder="$t('dialog.add.rss.placeholder')"
|
||||
:disabled="loading"
|
||||
@input="check_url"
|
||||
@url-changed="onUrlChanged"
|
||||
/>
|
||||
<mdicon class="icon is-left" name="rss" size="16" />
|
||||
</p>
|
||||
<p class="help" v-text="$t('dialog.add.rss.help')" />
|
||||
</div>
|
||||
</template>
|
||||
</modal-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ControlUrlField from '@/components/ControlUrlField.vue'
|
||||
import ModalDialog from '@/components/ModalDialog.vue'
|
||||
import webapi from '@/webapi'
|
||||
|
||||
export default {
|
||||
name: 'ModalDialogAddRss',
|
||||
components: { ModalDialog },
|
||||
components: { ControlUrlField, ModalDialog },
|
||||
props: { show: Boolean },
|
||||
emits: ['close', 'podcast-added'],
|
||||
data() {
|
||||
return {
|
||||
disabled: true,
|
||||
loading: false,
|
||||
disabled: true,
|
||||
url: ''
|
||||
}
|
||||
},
|
||||
@ -63,18 +54,11 @@ export default {
|
||||
]
|
||||
}
|
||||
},
|
||||
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: {
|
||||
onUrlChanged(url, disabled) {
|
||||
this.url = url
|
||||
this.disabled = disabled
|
||||
},
|
||||
add() {
|
||||
this.loading = true
|
||||
webapi
|
||||
@ -90,10 +74,6 @@ export default {
|
||||
},
|
||||
cancel() {
|
||||
this.$emit('close')
|
||||
},
|
||||
check_url(event) {
|
||||
const { validity } = event.target
|
||||
this.disabled = validity.patternMismatch || validity.valueMissing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,40 +7,31 @@
|
||||
>
|
||||
<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
|
||||
<control-url-field
|
||||
icon="web"
|
||||
:loading="loading"
|
||||
:placeholder="$t('dialog.add.stream.placeholder')"
|
||||
:disabled="loading"
|
||||
@input="check_url"
|
||||
@url-changed="onUrlChanged"
|
||||
/>
|
||||
<mdicon class="icon is-left" name="web" size="16" />
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
</modal-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import ControlUrlField from '@/components/ControlUrlField.vue'
|
||||
import ModalDialog from '@/components/ModalDialog.vue'
|
||||
import webapi from '@/webapi'
|
||||
|
||||
export default {
|
||||
name: 'ModalDialogAddStream',
|
||||
components: { ModalDialog },
|
||||
components: { ControlUrlField, ModalDialog },
|
||||
props: { show: Boolean },
|
||||
emits: ['close'],
|
||||
data() {
|
||||
return {
|
||||
disabled: true,
|
||||
loading: false,
|
||||
disabled: true,
|
||||
url: ''
|
||||
}
|
||||
},
|
||||
@ -70,18 +61,11 @@ export default {
|
||||
]
|
||||
}
|
||||
},
|
||||
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: {
|
||||
onUrlChanged(url, disabled) {
|
||||
this.url = url
|
||||
this.disabled = disabled
|
||||
},
|
||||
add() {
|
||||
this.loading = true
|
||||
webapi
|
||||
@ -97,11 +81,6 @@ export default {
|
||||
cancel() {
|
||||
this.$emit('close')
|
||||
},
|
||||
check_url(event) {
|
||||
const { validity } = event.target
|
||||
this.disabled = validity.patternMismatch || validity.valueMissing
|
||||
},
|
||||
|
||||
play() {
|
||||
this.loading = true
|
||||
webapi
|
||||
|
Loading…
x
Reference in New Issue
Block a user