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

81 lines
1.7 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",
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.
2021-03-21 11:51:58 +00:00
let uri = this.isFiles ? this.$route.path + "/" : "/";
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);
this.$router.push({ path: uri });
} 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>