mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-05-08 11:22:10 +00:00

Former-commit-id: ac9399efef37f13706590384e29295c6234acb7c [formerly f62dcb89aa49125769405c502688f3f8d4348da3] [formerly 4b9f0fd696f449c30da2d2f7a11cf5d6c7054c54 [formerly 64e70e39dcf6759e04315bc97ec6a0fed927c737]] Former-commit-id: 422165231c785b121b1f6725909d3ce7c8dcdfee [formerly 2b26582a03f674d40abb39e27b2cc880d2bd3ebb] Former-commit-id: ee743808a3c012514c9b7d57a34c79e408a8a78b
72 lines
1.7 KiB
Vue
72 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 () {
|
|
// Get the current name of the file we are editing.
|
|
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([{ from: oldLink, to: newLink }])
|
|
.then(() => {
|
|
if (this.req.kind !== 'listing') {
|
|
this.$router.push({ path: newLink })
|
|
return
|
|
}
|
|
this.$store.commit('setReload', true)
|
|
}).catch(error => {
|
|
this.$store.commit('showError', error)
|
|
})
|
|
|
|
this.$store.commit('closeHovers')
|
|
}
|
|
}
|
|
}
|
|
</script>
|