Former-commit-id: e483df4402733b102d11b10436ff74aad11dfa7c [formerly 6d761c2ee838a9766f755b6c54cdc2ca388b5934] [formerly 1365e9e067af021ad0c680bae3af963dc4a90b28 [formerly 889871ec0a1fac26dee1b3152d0f87e2a7af2c65]] Former-commit-id: ba443a90fded4501c0a6872eb293c14b2923c627 [formerly d21c6b9ab41869d2b10aa99853bc5b6931b63d96] Former-commit-id: 7c19b231861797c62dc35c1e8a28f4ceeb8761c7
79 lines
2 KiB
Vue
79 lines
2 KiB
Vue
<template>
|
|
<div class="prompt">
|
|
<h3>{{ $t('prompts.rename') }}</h3>
|
|
<p>{{ $t('prompts.renameMessage') }} <code>{{ oldName() }}</code>:</p>
|
|
|
|
<input autofocus type="text" @keyup.enter="submit" v-model.trim="name">
|
|
<div>
|
|
<button @click="submit"
|
|
type="submit"
|
|
:aria-label="$t('buttons.rename')"
|
|
:title="$t('buttons.rename')">{{ $t('buttons.rename') }}</button>
|
|
<button class="cancel"
|
|
@click="$store.commit('closeHovers')"
|
|
:aria-label="$t('buttons.cancel')"
|
|
:title="$t('buttons.cancel')">{{ $t('buttons.cancel') }}</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>
|