stato intermedio
This commit is contained in:
@@ -4,7 +4,11 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{.Title}}</title>
|
||||
<script src="/static/vendor/theme.js"></script>
|
||||
<script>
|
||||
window.__TC_IS_AUTHENTICATED = {{if .CurrentUser}}true{{else}}false{{end}};
|
||||
window.__TC_SERVER_THEME = {{printf "%q" .UserTheme}};
|
||||
</script>
|
||||
<script src="/static/vendor/theme.js?v={{.BuildHash}}"></script>
|
||||
<link rel="stylesheet" href="/static/css/app.css?v={{.BuildHash}}">
|
||||
<script src="/static/vendor/htmx.min.js"></script>
|
||||
<script src="/static/vendor/flowbite.js"></script>
|
||||
@@ -30,6 +34,8 @@
|
||||
(function () {
|
||||
var DEFAULT_LANG = 'it';
|
||||
var STORAGE_KEY = 'tc_lang';
|
||||
var SERVER_LANG = {{printf "%q" .UserLang}};
|
||||
var IS_AUTHENTICATED = {{if .CurrentUser}}true{{else}}false{{end}};
|
||||
var dictionaries = {
|
||||
it: {
|
||||
'nav.open_main_menu': 'Apri menu principale', 'nav.open_user_menu': 'Apri menu utente', 'nav.dashboard': 'Dashboard', 'nav.users': 'Users', 'nav.admin': 'Admin', 'nav.login': 'Login', 'nav.signup': 'Signup', 'nav.logout': 'Logout',
|
||||
@@ -96,9 +102,33 @@
|
||||
dictionaries.de_ch = Object.assign({}, dictionaries.de);
|
||||
dictionaries.fr_ch = Object.assign({}, dictionaries.fr);
|
||||
|
||||
function normalizeLang(lang) {
|
||||
if (!lang) return '';
|
||||
return String(lang).trim().toLowerCase().replace('-', '_');
|
||||
}
|
||||
|
||||
function isSupportedLang(lang) {
|
||||
return !!dictionaries[normalizeLang(lang)];
|
||||
}
|
||||
|
||||
function persistLangPreference(lang) {
|
||||
if (!IS_AUTHENTICATED) return;
|
||||
fetch('/preferences/lang', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({ lang: lang })
|
||||
}).catch(function () {});
|
||||
}
|
||||
|
||||
function getLang() {
|
||||
var serverLang = normalizeLang(SERVER_LANG);
|
||||
if (IS_AUTHENTICATED && isSupportedLang(serverLang)) {
|
||||
localStorage.setItem(STORAGE_KEY, serverLang);
|
||||
return serverLang;
|
||||
}
|
||||
var stored = localStorage.getItem(STORAGE_KEY);
|
||||
return dictionaries[stored] ? stored : DEFAULT_LANG;
|
||||
return isSupportedLang(stored) ? normalizeLang(stored) : DEFAULT_LANG;
|
||||
}
|
||||
|
||||
function t(key, lang) {
|
||||
@@ -171,13 +201,8 @@
|
||||
};
|
||||
flag.src = flags[lang] || '/static/vendor/flags/it.svg';
|
||||
flag.alt = labels[lang] || 'Lingua';
|
||||
if (lang === 'de_ch' || lang === 'fr_ch') {
|
||||
flag.style.width = '32px';
|
||||
flag.style.height = '32px';
|
||||
} else {
|
||||
flag.style.width = '48px';
|
||||
flag.style.height = '32px';
|
||||
}
|
||||
flag.style.width = '32px';
|
||||
flag.style.height = '22px';
|
||||
}
|
||||
|
||||
(root || document).querySelectorAll('[data-i18n]').forEach(function (el) {
|
||||
@@ -196,7 +221,9 @@
|
||||
|
||||
document.querySelectorAll('[data-lang-select]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
localStorage.setItem(STORAGE_KEY, btn.getAttribute('data-lang-select'));
|
||||
var selectedLang = normalizeLang(btn.getAttribute('data-lang-select'));
|
||||
localStorage.setItem(STORAGE_KEY, selectedLang);
|
||||
persistLangPreference(selectedLang);
|
||||
applyTranslations(document);
|
||||
var dropdownInstance = window.FlowbiteInstances && window.FlowbiteInstances.getInstance
|
||||
? window.FlowbiteInstances.getInstance('Dropdown', 'lang-dropdown')
|
||||
@@ -212,6 +239,28 @@
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-page-size-option]').forEach(function (btn) {
|
||||
btn.addEventListener('click', function () {
|
||||
var value = btn.getAttribute('data-page-size-option');
|
||||
var input = document.getElementById('users-size-value');
|
||||
var label = document.getElementById('users-size-label');
|
||||
if (input) input.value = value;
|
||||
if (label) label.textContent = value;
|
||||
|
||||
var dropdownInstance = window.FlowbiteInstances && window.FlowbiteInstances.getInstance
|
||||
? window.FlowbiteInstances.getInstance('Dropdown', 'users-size-dropdown')
|
||||
: null;
|
||||
if (dropdownInstance && typeof dropdownInstance.hide === 'function') {
|
||||
dropdownInstance.hide();
|
||||
return;
|
||||
}
|
||||
var button = document.getElementById('users-size-button');
|
||||
var dropdown = document.getElementById('users-size-dropdown');
|
||||
if (dropdown) dropdown.classList.add('hidden');
|
||||
if (button) button.setAttribute('aria-expanded', 'false');
|
||||
});
|
||||
});
|
||||
|
||||
function reinitFlowbiteComponents(target) {
|
||||
if (typeof window.initDropdowns === 'function') window.initDropdowns();
|
||||
if (typeof window.initModals === 'function') {
|
||||
|
||||
Reference in New Issue
Block a user