You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
Former-commit-id: e97af869293632e19a6af1c5834f6d00609a2405 [formerly 912200dce77db373ccce68ed4bf1bf16ca4e66e8] [formerly 4e222647913369d96d518e4078018e12c8dee8f9 [formerly 1871981fea]]
Former-commit-id: 8442a168025179ea117265bc56cd79d85a43a6d5 [formerly c07adbeb5c51b5ded79e9829a6e9eedef57cadd1]
Former-commit-id: 692840e184784622a971f5f52007691da52137bb
77 lines
1.8 KiB
Vue
77 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
|
|
}
|
|
|
|
this.name = encodeURIComponent(this.name)
|
|
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>
|