filebrowser/assets/src/components/prompts/Delete.vue
Henrique Dias e6efec5682 Comments and bugfixes
Former-commit-id: 3683a8730ff5d068f3c1c79bb93c3636c00d48f6 [formerly fe04704b2248be7e313fa879746cacd335fed043] [formerly ebfa6675e34ee278af94af56aa8f43d4566d6f5f [formerly 5eab62e0aa]]
Former-commit-id: 9ce059f75dc890570f9a992bf514c416ebf8e2f6 [formerly 02c89f89f211c95f8879cc4559efa3f4de7e8fca]
Former-commit-id: fb88da21590be01e95a963d453b6c3c880244281
2017-07-08 11:30:22 +01:00

74 lines
1.9 KiB
Vue

<template>
<div class="prompt">
<h3>Delete files</h3>
<p v-show="req.kind !== 'listing'">Are you sure you want to delete this file/folder?</p>
<p v-show="req.kind === 'listing'">Are you sure you want to delete {{ selectedCount }} file(s)?</p>
<div>
<button @click="submit" autofocus>Delete</button>
<button @click="closeHovers" class="cancel">Cancel</button>
</div>
</div>
</template>
<script>
import {mapGetters, mapMutations, mapState} from 'vuex'
import api from '@/utils/api'
import url from '@/utils/url'
import buttons from '@/utils/buttons'
export default {
name: 'delete',
computed: {
...mapGetters(['selectedCount']),
...mapState(['req', 'selected'])
},
methods: {
...mapMutations(['closeHovers']),
submit: function (event) {
this.closeHovers()
buttons.loading('delete')
// If we are not on a listing, delete the current
// opened file.
if (this.req.kind !== 'listing') {
api.delete(this.$route.path)
.then(() => {
buttons.done('delete')
this.$router.push({ path: url.removeLastDir(this.$route.path) + '/' })
})
.catch(error => {
buttons.done('delete')
this.$store.commit('showError', error)
})
return
}
if (this.selectedCount === 0) {
// This shouldn't happen...
return
}
// Create the promises array and fill it with
// the delete request for every selected file.
let promises = []
for (let index of this.selected) {
promises.push(api.delete(this.req.items[index].url))
}
Promise.all(promises)
.then(() => {
buttons.done('delete')
this.$store.commit('setReload', true)
})
.catch(error => {
buttons.done('delete')
this.$store.commit('setReload', true)
this.$store.commit('showError', error)
})
}
}
}
</script>