Skip to content
Snippets Groups Projects
Verified Commit 05f2ca53 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fix #814: Added copy-to-clipboard button with Subsonic password input

parent 353ac081
No related branches found
No related tags found
No related merge requests found
Added copy-to-clipboard button with Subsonic password input (#814)
...@@ -24,7 +24,12 @@ ...@@ -24,7 +24,12 @@
</div> </div>
<template v-if="subsonicEnabled"> <template v-if="subsonicEnabled">
<div v-if="token" class="field"> <div v-if="token" class="field">
<password-input v-model="token" /> <password-input
ref="passwordInput"
v-model="token"
:key="token"
:copy-button="true"
:default-show="showToken"/>
</div> </div>
<dangerous-button <dangerous-button
v-if="token" v-if="token"
...@@ -69,7 +74,8 @@ export default { ...@@ -69,7 +74,8 @@ export default {
errors: [], errors: [],
success: false, success: false,
isLoading: false, isLoading: false,
successMessage: '' successMessage: '',
showToken: false
} }
}, },
created () { created () {
...@@ -98,6 +104,7 @@ export default { ...@@ -98,6 +104,7 @@ export default {
let self = this let self = this
let url = `users/users/${this.$store.state.auth.username}/subsonic-token/` let url = `users/users/${this.$store.state.auth.username}/subsonic-token/`
return axios.post(url, {}).then(response => { return axios.post(url, {}).then(response => {
self.showToken = true
self.token = response.data['subsonic_api_token'] self.token = response.data['subsonic_api_token']
self.isLoading = false self.isLoading = false
self.success = true self.success = true
......
...@@ -10,20 +10,37 @@ ...@@ -10,20 +10,37 @@
<span @click="showPassword = !showPassword" :title="labels.title" class="ui icon button"> <span @click="showPassword = !showPassword" :title="labels.title" class="ui icon button">
<i class="eye icon"></i> <i class="eye icon"></i>
</span> </span>
<button v-if="copyButton" @click.prevent="copy" class="ui icon button" :title="labels.copy">
<i class="copy icon"></i>
</button>
</div> </div>
</template> </template>
<script> <script>
function copyStringToClipboard (str) {
// cf https://techoverflow.net/2018/03/30/copying-strings-to-the-clipboard-using-pure-javascript/
let el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style = {position: 'absolute', left: '-9999px'};
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
export default { export default {
props: ['value', 'index'], props: ['value', 'index', 'defaultShow', 'copyButton'],
data () { data () {
return { return {
showPassword: false showPassword: this.defaultShow || false,
} }
}, },
computed: { computed: {
labels () { labels () {
return { return {
title: this.$pgettext('Content/Settings/Button.Tooltip/Verb', 'Show/hide password') title: this.$pgettext('Content/Settings/Button.Tooltip/Verb', 'Show/hide password'),
copy: this.$pgettext('*/*/Button.Label/Short, Verb', 'Copy')
} }
}, },
passwordInputType () { passwordInputType () {
...@@ -32,6 +49,11 @@ export default { ...@@ -32,6 +49,11 @@ export default {
} }
return 'password' return 'password'
} }
},
methods: {
copy () {
copyStringToClipboard(this.value)
}
} }
} }
</script> </script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment