151 lines
4.3 KiB
Vue
151 lines
4.3 KiB
Vue
<script setup>
|
|
import { onMounted, ref } from 'vue';
|
|
|
|
import WindowHandle from './partials/WindowHandle.vue';
|
|
import Tabs from '../layouts/Tabs.vue';
|
|
import Dropdown from '../layouts/Dropdown.vue';
|
|
import { GetUser, GetUserSetting, SetUserSetting } from '@/services/User';
|
|
import { SetupHandle, SetSize, ResetPosition, Top, ClearWindow, CreateWindow, SetMinSize, SetResizable } from '@/services/Windows';
|
|
import { locales } from '~~/i18n/locales';
|
|
|
|
const handle = ref(null);
|
|
const wrapper = ref(null);
|
|
|
|
const props = defineProps(['data']);
|
|
const data = props.data;
|
|
|
|
const { locale } = useI18n();
|
|
|
|
const id = data.id;
|
|
|
|
const rows = ref([{id: "account-settings", value: "settings.tabs.account-settings"}]);
|
|
|
|
/* TODO
|
|
const languageOptions = ref(["English", "Spanish", "Catalan"])
|
|
const langSelector = ref(null);
|
|
*/
|
|
function getLocaleFromCode(code){
|
|
for(let i = 0; i < locales.length; i++){
|
|
if(locales[i].code == code) return locales[i];
|
|
}
|
|
}
|
|
|
|
// The language to show in the dropdown: always one Dragonroll offers, because a
|
|
// user that never picked one has none stored.
|
|
function localeToShow(code){
|
|
return getLocaleFromCode(code) || locales[0];
|
|
}
|
|
|
|
// vue-i18n answers every translation with `SyntaxError: cannot support locale type`
|
|
// once it is given a locale it has no messages for, and the locale is global: putting
|
|
// a language that is not stored (the server answers `settings: undefined` for a user
|
|
// that never picked one) or one no longer offered took the settings window and the
|
|
// main menu behind it down (issue #47). Only known codes go into `locale`.
|
|
function applyLanguage(code){
|
|
const stored = getLocaleFromCode(code);
|
|
if(!stored) return false;
|
|
locale.value = stored.code;
|
|
selectedLocale.value = stored;
|
|
return true;
|
|
}
|
|
|
|
const selectedLocale = ref(localeToShow(locale.value));
|
|
|
|
const changeLocale = (lang) => {
|
|
if(!applyLanguage(lang?.code)) return;
|
|
SetUserSetting('lang', lang.code);
|
|
}
|
|
|
|
onBeforeMount(() => {
|
|
// Set selected in dropdown. Without settings to read from the server the language
|
|
// Dragonroll is already showing stays the one on screen.
|
|
GetUserSetting('lang')
|
|
.then((value) => applyLanguage(value))
|
|
.catch(() => {});
|
|
|
|
if(GetUser()?.admin) rows.value.push({
|
|
id: "site-administration",
|
|
value: "settings.tabs.site-administration"
|
|
});
|
|
});
|
|
|
|
onMounted(() => {
|
|
Top(wrapper);
|
|
SetupHandle(id, handle);
|
|
SetSize(id, {width: 600, height: 480});
|
|
ResetPosition(id, "center");
|
|
|
|
SetResizable(id, true);
|
|
SetMinSize(id, {width: 450, height: 280});
|
|
});
|
|
|
|
function OpenManageAccounts(){
|
|
ClearWindow({ type: 'settings' });
|
|
CreateWindow('account_management', {
|
|
// Back returns to the settings tab this button sits on; CreateWindow leaves
|
|
// a window that is already open alone.
|
|
back: () => {
|
|
ClearWindow({ type: 'account_management' });
|
|
CreateWindow('settings');
|
|
}
|
|
});
|
|
}
|
|
|
|
const getLocaleName = (locale) => {
|
|
return locale ? locale.name : "";
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
|
|
<WindowHandle :window="id" ref="handle"></WindowHandle>
|
|
|
|
<!-- Body -->
|
|
<Tabs :rows="rows">
|
|
<template #account-settings>
|
|
<div class="form-container">
|
|
<div class="form-element">
|
|
<label>{{ $t('settings.account-settings.language') }}</label>
|
|
<Dropdown :options="locales" :keyFunc="getLocaleName" :onselect="changeLocale" :selected="selectedLocale"></Dropdown>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
<template #site-administration>
|
|
<div class="form-element centered">
|
|
<button v-on:click.prevent="OpenManageAccounts">{{ $t('settings.site-administration.manage-accounts') }}</button>
|
|
</div>
|
|
</template>
|
|
</Tabs>
|
|
</div>
|
|
</template>
|
|
|
|
|
|
<style scoped>
|
|
.window-wrapper {
|
|
width: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.splash-image {
|
|
width: 600px;
|
|
height: 250px;
|
|
}
|
|
|
|
.form-field {
|
|
padding: 10px;
|
|
display: flex;
|
|
align-items: left;
|
|
flex-direction: column;
|
|
justify-content: left;
|
|
width: 600px;
|
|
}
|
|
|
|
label {
|
|
text-align: left;
|
|
}
|
|
|
|
</style>
|