mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-05-11 12:43:00 +00:00

Former-commit-id: 0d8742754bb756ad3a83599850dae5f477282430 [formerly 5cb7d75b695d8400fc2af87edd551d6450e7365f] [formerly a6a814c40a5ff4f195c4ab470d4fccc92bd8c1c8 [formerly 99c8c92c6c6d1225380dbbfc5b61d4263a129156]] Former-commit-id: 45eba5ff05f8e64fbf33d9d670e19a0cf4880656 [formerly 88dc856045b9d51596f36ce387b1c4f3e85a7d3c] Former-commit-id: 1eadaef460060da8ae71df3c66f242c844992725
85 lines
2.2 KiB
Vue
85 lines
2.2 KiB
Vue
<template>
|
|
<div class="card floating">
|
|
<div class="card-title">
|
|
<h2>{{ $t('prompts.rename') }}</h2>
|
|
</div>
|
|
|
|
<div class="card-content">
|
|
<p>{{ $t('prompts.renameMessage') }} <code>{{ oldName() }}</code>:</p>
|
|
<input autofocus type="text" @keyup.enter="submit" v-model.trim="name">
|
|
</div>
|
|
|
|
<div class="card-action">
|
|
<button class="cancel flat"
|
|
@click="$store.commit('closeHovers')"
|
|
:aria-label="$t('buttons.cancel')"
|
|
:title="$t('buttons.cancel')">{{ $t('buttons.cancel') }}</button>
|
|
<button @click="submit"
|
|
class="flat"
|
|
type="submit"
|
|
:aria-label="$t('buttons.rename')"
|
|
:title="$t('buttons.rename')">{{ $t('buttons.rename') }}</button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapState } from 'vuex'
|
|
import url from '@/utils/url'
|
|
import * as 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.$showError(error)
|
|
})
|
|
|
|
this.$store.commit('closeHovers')
|
|
}
|
|
}
|
|
}
|
|
</script>
|