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

130 lines
3.2 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">
2024-02-10 00:13:02 +00:00
<file-list ref="fileList" @update:selected="(val) => (dest = val)"> </file-list>
2018-02-01 12:17:04 +00:00
</div>
2024-02-10 00:13:02 +00:00
<div
class="card-action"
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')"
style="justify-self: left"
>
<span>{{ $t("sidebar.newFolder") }}</span>
</button>
</template>
<div>
<button
class="button button--flat button--grey"
2024-07-30 17:45:27 +00:00
@click="closeHovers"
2024-02-10 00:13:02 +00:00
:aria-label="$t('buttons.cancel')"
:title="$t('buttons.cancel')"
>
{{ $t("buttons.cancel") }}
</button>
<button
class="button button--flat"
@click="move"
:disabled="$route.path === dest"
:aria-label="$t('buttons.move')"
:title="$t('buttons.move')"
>
{{ $t("buttons.move") }}
</button>
</div>
2018-02-01 12:17:04 +00:00
</div>
</div>
</template>
<script>
2024-07-30 17:45:27 +00:00
import { mutations, state } from "@/store";
2024-02-10 00:13:02 +00:00
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";
2024-07-30 17:45:27 +00:00
import { showError } from "@/notify";
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
},
2024-07-30 17:45:27 +00:00
computed: {
user() {
return state.user;
},
closeHovers() {
return mutations.closeHovers()
},
},
2018-02-01 12:17:04 +00:00
methods: {
move: async function (event) {
2021-03-21 11:51:58 +00:00
event.preventDefault();
let items = [];
2018-02-01 12:17:04 +00:00
2024-07-30 17:45:27 +00:00
for (let item of state.selected) {
2018-02-01 12:17:04 +00:00
items.push({
2024-07-30 17:45:27 +00:00
from: state.req.items[item].url,
to: this.dest + encodeURIComponent(state.req.items[item].name),
name: state.req.items[item].name,
2021-03-21 11:51:58 +00:00
});
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");
await api
.move(items, overwrite, rename)
.then(() => {
buttons.success("move");
this.$router.push({ path: this.dest });
2024-07-30 17:45:27 +00:00
mutations.setReload(true)
2021-03-21 11:51:58 +00:00
})
.catch((e) => {
buttons.done("move");
2024-07-30 17:45:27 +00:00
showError(e);
2021-03-21 11:51:58 +00:00
});
};
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) {
2024-07-30 17:45:27 +00:00
mutations.showHover({
name: "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();
2024-07-30 17:45:27 +00:00
mutations.closeHovers();
2021-03-21 11:51:58 +00:00
action(overwrite, rename);
2024-07-30 17:45:27 +00:00
mutations.setReload(true)
2021-03-21 11:51:58 +00:00
},
});
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>