filebrowser/_assets/src/components/RenamePrompt.vue
Henrique Dias c7e37c09e1 Improvements and more reliability :)
Former-commit-id: 4d5ca1dd46c57e35222860a66c9f98f945fbaad7 [formerly 5a0bea68d0ddec09c95919c1ef45bdff3f602bc6] [formerly b324db325f094e5563f945c41f4f9eeb0b2df086 [formerly 698a08e1a9]]
Former-commit-id: 6c39601f33482edafad63f4b39e10e2720db2813 [formerly 02a9c37289ce3d27eee55f3eb3052391349adc0e]
Former-commit-id: fd29981acff35fa5428af5e1d95fe1d53bba0459
2017-06-30 17:49:05 +01:00

76 lines
1.8 KiB
Vue

<template>
<div class="prompt">
<h3>Rename</h3>
<p>Insert a new name for <code>{{ oldName() }}</code>:</p>
<input autofocus type="text" @keyup.enter="submit" v-model.trim="name">
<div>
<button @click="submit" type="submit">Rename</button>
<button @click="cancel" class="cancel">Cancel</button>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
import page from '../utils/page'
import webdav from '../utils/webdav'
export default {
name: 'rename-prompt',
data: function () {
return {
name: ''
}
},
computed: mapState(['req', 'selected', 'selectedCount']),
methods: {
cancel: function (event) {
this.$store.commit('showRename', false)
},
oldName: function () {
if (this.req.kind !== 'listing') {
return this.req.data.name
}
if (this.selectedCount === 0 || this.selectedCount > 1) {
// This shouldn't happen.
return
}
return this.req.data.items[this.selected[0]].name
},
submit: function (event) {
let oldLink = ''
let newLink = ''
if (this.req.kind !== 'listing') {
oldLink = this.req.data.url
} else {
oldLink = this.req.data.items[this.selected[0]].url
}
newLink = page.removeLastDir(oldLink) + '/' + this.name
// buttons.setLoading('rename')
webdav.move(oldLink, newLink)
.then(() => {
if (this.req.kind !== 'listing') {
page.open(newLink)
return
}
// TODO: keep selected after reload?
page.reload()
// buttons.setDone('rename')
}).catch(error => {
// buttons.setDone('rename', false)
console.log(error)
})
this.$store.commit('showRename', false)
return
}
}
}
</script>