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

99 lines
2.1 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.newDir") }}</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.newDirMessage") }}</p>
<input
class="input input--block"
type="text"
@keyup.enter="submit"
v-model.trim="name"
v-focus
/>
2018-02-01 12:17:04 +00:00
</div>
<div class="card-action">
<button
class="button button--flat button--grey"
2018-02-01 12:17:04 +00:00
@click="$store.commit('closeHovers')"
:aria-label="$t('buttons.cancel')"
:title="$t('buttons.cancel')"
2021-03-21 11:51:58 +00:00
>
{{ $t("buttons.cancel") }}
</button>
<button
class="button button--flat"
2018-02-01 12:17:04 +00:00
:aria-label="$t('buttons.create')"
:title="$t('buttons.create')"
@click="submit"
2021-03-21 11:51:58 +00:00
>
{{ $t("buttons.create") }}
</button>
2018-02-01 12:17:04 +00:00
</div>
</div>
</template>
<script>
2021-03-21 11:51:58 +00:00
import { mapGetters } from "vuex";
import { files as api } from "@/api";
import url from "@/utils/url";
2018-02-01 12:17:04 +00:00
export default {
2021-03-21 11:51:58 +00:00
name: "new-dir",
2024-02-10 00:13:02 +00:00
props: {
redirect: {
type: Boolean,
default: true,
},
base: {
type: [String, null],
default: null,
},
},
2021-03-21 11:51:58 +00:00
data: function () {
2018-02-01 12:17:04 +00:00
return {
2021-03-21 11:51:58 +00:00
name: "",
};
},
computed: {
2021-03-21 11:51:58 +00:00
...mapGetters(["isFiles", "isListing"]),
2018-02-01 12:17:04 +00:00
},
methods: {
2021-03-21 11:51:58 +00:00
submit: async function (event) {
event.preventDefault();
if (this.new === "") return;
2018-02-01 12:17:04 +00:00
// Build the path of the new directory.
2024-02-10 00:13:02 +00:00
let uri;
if (this.base) uri = this.base;
else if (this.isFiles) uri = this.$route.path + "/";
else uri = "/";
if (!this.isListing) {
2021-03-21 11:51:58 +00:00
uri = url.removeLastDir(uri) + "/";
2018-02-01 12:17:04 +00:00
}
2021-03-21 11:51:58 +00:00
uri += encodeURIComponent(this.name) + "/";
uri = uri.replace("//", "/");
2018-02-01 12:17:04 +00:00
try {
2021-03-21 11:51:58 +00:00
await api.post(uri);
2024-02-10 00:13:02 +00:00
if (this.redirect) {
this.$router.push({ path: uri });
} else if (!this.base) {
const res = await api.fetch(url.removeLastDir(uri) + "/");
this.$store.commit("updateRequest", res);
}
} catch (e) {
2021-03-21 11:51:58 +00:00
this.$showError(e);
}
2018-02-01 12:17:04 +00:00
2021-03-21 11:51:58 +00:00
this.$store.commit("closeHovers");
},
},
};
2018-02-01 12:17:04 +00:00
</script>