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

102 lines
2.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.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"
2024-07-30 17:45:27 +00:00
@click="closeHovers"
2018-02-01 12:17:04 +00:00
: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 { files as api } from "@/api";
import url from "@/utils/url";
2024-07-30 17:45:27 +00:00
import { getters, mutations, state } from "@/store"; // Import your custom store
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,
},
},
2024-07-30 17:45:27 +00:00
data() {
2018-02-01 12:17:04 +00:00
return {
2021-03-21 11:51:58 +00:00
name: "",
};
},
computed: {
2024-07-30 17:45:27 +00:00
isFiles() {
return getters.isFiles();
},
isListing() {
return getters.isListing();
},
2018-02-01 12:17:04 +00:00
},
methods: {
2024-07-30 17:45:27 +00:00
closeHovers() {
return mutations.closeHovers();
},
async submit(event) {
2021-03-21 11:51:58 +00:00
event.preventDefault();
2024-07-30 17:45:27 +00:00
if (this.name === "") 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;
2024-07-30 17:45:27 +00:00
else if (getters.isFiles()) uri = state.route.path + "/";
2024-02-10 00:13:02 +00:00
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
2024-09-16 21:01:16 +00:00
await api.post(uri);
if (this.redirect) {
this.$router.push({ path: uri });
} else if (!this.base) {
const res = await api.fetch(url.removeLastDir(uri) + "/");
mutations.updateRequest(res);
}
2018-02-01 12:17:04 +00:00
2024-07-30 17:45:27 +00:00
mutations.closeHovers();
2021-03-21 11:51:58 +00:00
},
},
};
2018-02-01 12:17:04 +00:00
</script>