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

136 lines
3.4 KiB
Vue
Raw Normal View History

2018-02-01 12:17:04 +00:00
<template>
<div class="card floating">
<div class="card-title">
2021-03-21 11:51:58 +00:00
<h2>{{ $t("prompts.move") }}</h2>
2018-02-01 12:17:04 +00:00
</div>
<div class="card-content">
<file-list
ref="fileList"
@update:selected="(val) => (dest = val)"
tabindex="1"
/>
2018-02-01 12:17:04 +00:00
</div>
<div
class="card-action"
2024-02-09 10:05:35 +00:00
style="display: flex; align-items: center; justify-content: space-between"
>
<template v-if="user.perm.create">
<button
class="button button--flat"
@click="$refs.fileList.createDir()"
:aria-label="$t('sidebar.newFolder')"
:title="$t('sidebar.newFolder')"
2024-02-09 10:05:35 +00:00
style="justify-self: left"
>
<span>{{ $t("sidebar.newFolder") }}</span>
</button>
</template>
<div>
<button
class="button button--flat button--grey"
@click="closeHovers"
:aria-label="$t('buttons.cancel')"
:title="$t('buttons.cancel')"
tabindex="3"
>
{{ $t("buttons.cancel") }}
</button>
<button
id="focus-prompt"
class="button button--flat"
@click="move"
:disabled="$route.path === dest"
:aria-label="$t('buttons.move')"
:title="$t('buttons.move')"
tabindex="2"
>
{{ $t("buttons.move") }}
</button>
</div>
2018-02-01 12:17:04 +00:00
</div>
</div>
</template>
<script>
import { mapActions, mapState } from "pinia";
import { useFileStore } from "@/stores/file";
import { useLayoutStore } from "@/stores/layout";
import { useAuthStore } from "@/stores/auth";
import FileList from "./FileList.vue";
2021-03-21 11:51:58 +00:00
import { files as api } from "@/api";
import buttons from "@/utils/buttons";
import * as upload from "@/utils/upload";
2018-02-01 12:17:04 +00:00
export default {
2021-03-21 11:51:58 +00:00
name: "move",
2018-02-01 12:17:04 +00:00
components: { FileList },
data: function () {
return {
current: window.location.pathname,
2021-03-21 11:51:58 +00:00
dest: null,
};
2018-02-01 12:17:04 +00:00
},
inject: ["$showError"],
computed: {
...mapState(useFileStore, ["req", "selected"]),
...mapState(useAuthStore, ["user"]),
},
2018-02-01 12:17:04 +00:00
methods: {
...mapActions(useLayoutStore, ["showHover", "closeHovers"]),
move: async function (event) {
2021-03-21 11:51:58 +00:00
event.preventDefault();
let items = [];
2018-02-01 12:17:04 +00:00
for (let item of this.selected) {
items.push({
from: this.req.items[item].url,
to: this.dest + encodeURIComponent(this.req.items[item].name),
2021-03-21 11:51:58 +00:00
name: this.req.items[item].name,
});
2018-02-01 12:17:04 +00:00
}
2020-07-16 19:30:17 +00:00
let action = async (overwrite, rename) => {
2021-03-21 11:51:58 +00:00
buttons.loading("move");
2021-03-21 11:51:58 +00:00
await api
.move(items, overwrite, rename)
.then(() => {
buttons.success("move");
this.$router.push({ path: this.dest });
})
.catch((e) => {
buttons.done("move");
this.$showError(e);
});
};
2018-02-01 12:17:04 +00:00
2021-03-21 11:51:58 +00:00
let dstItems = (await api.fetch(this.dest)).items;
let conflict = upload.checkConflict(items, dstItems);
2021-03-21 11:51:58 +00:00
let overwrite = false;
let rename = false;
2020-07-16 19:30:17 +00:00
if (conflict) {
this.showHover({
2021-03-21 11:51:58 +00:00
prompt: "replace-rename",
2020-07-16 19:30:17 +00:00
confirm: (event, option) => {
2021-03-21 11:51:58 +00:00
overwrite = option == "overwrite";
rename = option == "rename";
2020-07-16 19:30:17 +00:00
2021-03-21 11:51:58 +00:00
event.preventDefault();
this.closeHovers();
2021-03-21 11:51:58 +00:00
action(overwrite, rename);
},
});
2021-03-21 11:51:58 +00:00
return;
}
2021-03-21 11:51:58 +00:00
action(overwrite, rename);
},
},
};
2018-02-01 12:17:04 +00:00
</script>