2023-09-10 00:24:56 +00:00
|
|
|
<template>
|
2023-09-13 15:20:52 +00:00
|
|
|
<LoginModal v-if="modal_visible" @submit="on_submit" @cancel="on_cancel" />
|
2023-09-10 00:24:56 +00:00
|
|
|
|
|
|
|
<BulmaButton
|
2023-09-20 22:03:32 +00:00
|
|
|
:class="button_class"
|
2023-09-11 23:36:36 +00:00
|
|
|
:icon="'fa-solid fa-toggle-' + (modelValue ? 'on' : 'off')"
|
2023-09-12 22:35:57 +00:00
|
|
|
:busy="is_busy"
|
2023-09-20 22:03:32 +00:00
|
|
|
text="Admin"
|
|
|
|
@click.left="on_click"
|
2023-09-10 00:24:56 +00:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Options, Vue } from "vue-class-component";
|
|
|
|
|
|
|
|
import BulmaButton from "./bulma/Button.vue";
|
|
|
|
import LoginModal from "./LoginModal.vue";
|
|
|
|
|
|
|
|
@Options({
|
|
|
|
components: {
|
|
|
|
BulmaButton,
|
|
|
|
LoginModal,
|
|
|
|
},
|
2023-09-11 23:10:17 +00:00
|
|
|
props: {
|
|
|
|
modelValue: Boolean,
|
2023-09-20 22:03:32 +00:00
|
|
|
button_class: String,
|
2023-09-11 23:10:17 +00:00
|
|
|
},
|
|
|
|
emits: ["update:modelValue"],
|
2023-09-10 00:24:56 +00:00
|
|
|
})
|
|
|
|
export default class extends Vue {
|
2023-09-11 23:10:17 +00:00
|
|
|
// true, iff Benutzer Admin ist
|
|
|
|
public modelValue!: boolean;
|
2023-09-20 22:03:32 +00:00
|
|
|
public button_class!: string;
|
|
|
|
|
2023-09-11 23:36:36 +00:00
|
|
|
public modal_visible = false;
|
2023-09-12 22:35:57 +00:00
|
|
|
public is_busy = false;
|
2023-09-11 23:36:36 +00:00
|
|
|
|
|
|
|
public on_click() {
|
|
|
|
if (this.modelValue) {
|
|
|
|
// logout
|
|
|
|
this.$advent22.clear_api_auth();
|
|
|
|
this.$emit("update:modelValue", false);
|
|
|
|
} else {
|
|
|
|
// show login modal
|
2023-09-12 22:35:57 +00:00
|
|
|
this.is_busy = true;
|
2023-09-11 23:36:36 +00:00
|
|
|
this.modal_visible = true;
|
|
|
|
}
|
|
|
|
}
|
2023-09-11 23:10:17 +00:00
|
|
|
|
2023-09-11 23:36:36 +00:00
|
|
|
public on_submit(username: string, password: string) {
|
|
|
|
this.modal_visible = false;
|
|
|
|
this.$advent22.set_api_auth(username, password);
|
2023-09-11 23:10:17 +00:00
|
|
|
|
2023-09-13 15:24:25 +00:00
|
|
|
this.$advent22
|
|
|
|
.api_get<boolean>("admin/is_admin")
|
|
|
|
.then((is_admin) => {
|
|
|
|
this.$emit("update:modelValue", is_admin);
|
|
|
|
this.is_busy = false;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
alert(this.$advent22.format_user_error(error));
|
|
|
|
this.is_busy = false;
|
|
|
|
});
|
2023-09-11 23:10:17 +00:00
|
|
|
}
|
2023-09-13 15:20:52 +00:00
|
|
|
|
|
|
|
public on_cancel() {
|
|
|
|
this.modal_visible = false;
|
|
|
|
this.is_busy = false;
|
|
|
|
}
|
2023-09-10 00:24:56 +00:00
|
|
|
}
|
|
|
|
</script>
|