Henrique Dias 4e5b309bf9 buttons animations
Former-commit-id: 7c32637982be8af78d41c5610405694689c8df55 [formerly 461b2f1d4556df9ef36ebac39e0a269aad57cce1] [formerly 071f6ef97283c1e5c0ebac49fda747fa77f6a539 [formerly f9699f174d9601b645a67c00771aea24f4a656cb]]
Former-commit-id: a052df2da3d1dc23311e69ffd8d058567fa9bd3b [formerly ebdbc05a6bd049a2479b850b23c7e2ffa7a5ba5f]
Former-commit-id: 56066e9d06059f6dbfc87e28a7bd8406bff06a5d
2017-07-04 18:04:00 +01:00

74 lines
1.7 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 url from '@/utils/url'
import api from '@/utils/api'
export default {
name: 'rename',
data: function () {
return {
name: ''
}
},
computed: mapState(['req', 'selected', 'selectedCount']),
methods: {
cancel: function (event) {
this.$store.commit('closeHovers')
},
oldName: function () {
if (this.req.kind !== 'listing') {
return this.req.name
}
if (this.selectedCount === 0 || this.selectedCount > 1) {
// This shouldn't happen.
return
}
return this.req.items[this.selected[0]].name
},
submit: function (event) {
let oldLink = ''
let newLink = ''
if (this.req.kind !== 'listing') {
oldLink = this.req.url
} else {
oldLink = this.req.items[this.selected[0]].url
}
this.name = encodeURIComponent(this.name)
newLink = url.removeLastDir(oldLink) + '/' + this.name
api.move(oldLink, newLink)
.then(() => {
if (this.req.kind !== 'listing') {
this.$router.push({ path: newLink })
return
}
// TODO: keep selected after reload?
this.$store.commit('setReload', true)
}).catch(error => {
// TODO: show error message
console.log(error)
})
this.$store.commit('closeHovers')
return
}
}
}
</script>