2017-06-29 08:11:46 +00:00
|
|
|
<template>
|
2017-08-01 19:49:56 +00:00
|
|
|
<button @click="download" :aria-label="$t('buttons.download')" :title="$t('buttons.download')" id="download-button" class="action">
|
2017-06-30 15:04:01 +00:00
|
|
|
<i class="material-icons">file_download</i>
|
2017-08-01 19:49:56 +00:00
|
|
|
<span>{{ $t('buttons.download') }}</span>
|
2017-06-30 15:04:01 +00:00
|
|
|
<span v-if="selectedCount > 0" class="counter">{{ selectedCount }}</span>
|
|
|
|
</button>
|
2017-06-29 08:11:46 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2017-06-30 15:04:01 +00:00
|
|
|
import {mapGetters, mapState} from 'vuex'
|
2017-08-11 08:33:47 +00:00
|
|
|
import * as api from '@/utils/api'
|
2017-06-29 08:11:46 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'download-button',
|
2017-06-30 15:04:01 +00:00
|
|
|
computed: {
|
2017-07-03 20:33:21 +00:00
|
|
|
...mapState(['req', 'selected']),
|
2017-06-30 15:04:01 +00:00
|
|
|
...mapGetters(['selectedCount'])
|
|
|
|
},
|
2017-06-29 08:11:46 +00:00
|
|
|
methods: {
|
|
|
|
download: function (event) {
|
2017-07-08 10:15:23 +00:00
|
|
|
// If we are not on a listing, download the current file.
|
2017-06-30 15:04:01 +00:00
|
|
|
if (this.req.kind !== 'listing') {
|
2017-07-03 20:33:21 +00:00
|
|
|
api.download(null, this.$route.path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-07-08 10:15:23 +00:00
|
|
|
// If we are on a listing and there is one element selected,
|
|
|
|
// download it.
|
2017-07-19 07:30:08 +00:00
|
|
|
if (this.selectedCount === 1 && !this.req.items[this.selected[0]].isDir) {
|
2017-07-03 20:33:21 +00:00
|
|
|
api.download(null, this.req.items[this.selected[0]].url)
|
2017-06-29 08:11:46 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-07-08 10:15:23 +00:00
|
|
|
// Otherwise show the prompt to choose the formt of the download.
|
2017-07-04 16:15:38 +00:00
|
|
|
this.$store.commit('showHover', 'download')
|
2017-06-29 08:11:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|