filebrowser/frontend/src/components/prompts/Delete.vue

94 lines
2.3 KiB
Vue
Raw Normal View History

2018-02-01 12:17:04 +00:00
<template>
<div class="card floating">
<div class="card-content">
<p v-if="!this.isListing || selectedCount === 1">
2021-03-21 11:51:58 +00:00
{{ $t("prompts.deleteMessageSingle") }}
</p>
<p v-else>
{{ $t("prompts.deleteMessageMultiple", { count: selectedCount }) }}
</p>
2018-02-01 12:17:04 +00:00
</div>
<div class="card-action">
2021-03-21 11:51:58 +00:00
<button
@click="closeHovers"
class="button button--flat button--grey"
2018-02-01 12:17:04 +00:00
:aria-label="$t('buttons.cancel')"
2021-03-21 11:51:58 +00:00
:title="$t('buttons.cancel')"
tabindex="2"
2021-03-21 11:51:58 +00:00
>
{{ $t("buttons.cancel") }}
</button>
<button
id="focus-prompt"
2021-03-21 11:51:58 +00:00
@click="submit"
class="button button--flat button--red"
2018-02-01 12:17:04 +00:00
:aria-label="$t('buttons.delete')"
2021-03-21 11:51:58 +00:00
:title="$t('buttons.delete')"
tabindex="1"
2021-03-21 11:51:58 +00:00
>
{{ $t("buttons.delete") }}
</button>
2018-02-01 12:17:04 +00:00
</div>
</div>
</template>
<script>
import { mapActions, mapState, mapWritableState } from "pinia";
2021-03-21 11:51:58 +00:00
import { files as api } from "@/api";
import buttons from "@/utils/buttons";
import { useFileStore } from "@/stores/file";
import { useLayoutStore } from "@/stores/layout";
2018-02-01 12:17:04 +00:00
export default {
2021-03-21 11:51:58 +00:00
name: "delete",
inject: ["$showError"],
2018-02-01 12:17:04 +00:00
computed: {
...mapState(useFileStore, [
"isListing",
"selectedCount",
"req",
"selected",
"currentPrompt",
]),
...mapWritableState(useFileStore, ["reload"]),
2018-02-01 12:17:04 +00:00
},
methods: {
...mapActions(useLayoutStore, ["closeHovers"]),
submit: async function () {
2021-03-21 11:51:58 +00:00
buttons.loading("delete");
2018-02-01 12:17:04 +00:00
window.sessionStorage.setItem("modified", "true");
try {
if (!this.isListing) {
2021-03-21 11:51:58 +00:00
await api.remove(this.$route.path);
buttons.success("delete");
this.currentPrompt?.confirm();
2021-03-21 11:51:58 +00:00
this.closeHovers();
return;
}
2018-02-01 12:17:04 +00:00
2021-03-21 11:51:58 +00:00
this.closeHovers();
if (this.selectedCount === 0) {
2021-03-21 11:51:58 +00:00
return;
}
2018-02-01 12:17:04 +00:00
2021-03-21 11:51:58 +00:00
let promises = [];
for (let index of this.selected) {
2021-03-21 11:51:58 +00:00
promises.push(api.remove(this.req.items[index].url));
}
2018-02-01 12:17:04 +00:00
2021-03-21 11:51:58 +00:00
await Promise.all(promises);
buttons.success("delete");
this.reload = true;
} catch (e) {
2021-03-21 11:51:58 +00:00
buttons.done("delete");
this.$showError(e);
if (this.isListing) this.reload = true;
2018-02-01 12:17:04 +00:00
}
2021-03-21 11:51:58 +00:00
},
},
};
2018-02-01 12:17:04 +00:00
</script>