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

120 lines
2.8 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.copy") }}</h2>
2018-02-01 12:17:04 +00:00
</div>
<div class="card-content">
2021-03-21 11:51:58 +00:00
<p>{{ $t("prompts.copyMessage") }}</p>
<file-list @update:selected="(val) => (dest = val)"></file-list>
2018-02-01 12:17:04 +00:00
</div>
<div class="card-action">
2021-03-21 11:51:58 +00:00
<button
class="button button--flat button--grey"
2018-02-01 12:17:04 +00:00
@click="$store.commit('closeHovers')"
:aria-label="$t('buttons.cancel')"
2021-03-21 11:51:58 +00:00
:title="$t('buttons.cancel')"
>
{{ $t("buttons.cancel") }}
</button>
<button
class="button button--flat"
2018-02-01 12:17:04 +00:00
@click="copy"
:aria-label="$t('buttons.copy')"
2021-03-21 11:51:58 +00:00
:title="$t('buttons.copy')"
>
{{ $t("buttons.copy") }}
</button>
2018-02-01 12:17:04 +00:00
</div>
</div>
</template>
<script>
2021-03-21 11:51:58 +00:00
import { mapState } from "vuex";
import FileList from "./FileList";
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: "copy",
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
},
2021-03-21 11:51:58 +00:00
computed: mapState(["req", "selected"]),
2018-02-01 12:17:04 +00:00
methods: {
copy: async function (event) {
2021-03-21 11:51:58 +00:00
event.preventDefault();
let items = [];
2018-02-01 12:17:04 +00:00
// Create a new promise for each file.
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("copy");
2021-03-21 11:51:58 +00:00
await api
.copy(items, overwrite, rename)
.then(() => {
buttons.success("copy");
2021-03-21 11:51:58 +00:00
if (this.$route.path === this.dest) {
this.$store.commit("setReload", true);
2021-03-21 11:51:58 +00:00
return;
}
2021-03-21 11:51:58 +00:00
this.$router.push({ path: this.dest });
})
.catch((e) => {
buttons.done("copy");
this.$showError(e);
});
};
if (this.$route.path === this.dest) {
2021-03-21 11:51:58 +00:00
this.$store.commit("closeHovers");
action(false, true);
2021-03-21 11:51:58 +00:00
return;
}
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) {
2021-03-21 11:51:58 +00:00
this.$store.commit("showHover", {
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.$store.commit("closeHovers");
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>