mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-10-31 23:40:11 +00:00
add language selector to admin
This commit is contained in:
parent
a3351f4da8
commit
4679c6f355
7
api.go
7
api.go
@ -1237,10 +1237,17 @@ func (app *appContext) Logout(gc *gin.Context) {
|
|||||||
// @Router /lang [get]
|
// @Router /lang [get]
|
||||||
// @tags Other
|
// @tags Other
|
||||||
func (app *appContext) GetLanguages(gc *gin.Context) {
|
func (app *appContext) GetLanguages(gc *gin.Context) {
|
||||||
|
page := gc.Param("page")
|
||||||
resp := langDTO{}
|
resp := langDTO{}
|
||||||
|
if page == "form" {
|
||||||
for key, lang := range app.storage.lang.Form {
|
for key, lang := range app.storage.lang.Form {
|
||||||
resp[key] = lang["meta"].(map[string]interface{})["name"].(string)
|
resp[key] = lang["meta"].(map[string]interface{})["name"].(string)
|
||||||
}
|
}
|
||||||
|
} else if page == "admin" {
|
||||||
|
for key, lang := range app.storage.lang.Admin {
|
||||||
|
resp[key] = lang["meta"].(map[string]interface{})["name"].(string)
|
||||||
|
}
|
||||||
|
}
|
||||||
if len(resp) == 0 {
|
if len(resp) == 0 {
|
||||||
respond(500, "Couldn't get languages", gc)
|
respond(500, "Couldn't get languages", gc)
|
||||||
return
|
return
|
||||||
|
@ -167,6 +167,16 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div id="notification-box"></div>
|
<div id="notification-box"></div>
|
||||||
|
<span class="dropdown" tabindex="0" id="lang-dropdown">
|
||||||
|
<span class="button ~urge dropdown-button">
|
||||||
|
<i class="ri-global-line"></i>
|
||||||
|
<span class="ml-1 chev"></span>
|
||||||
|
</span>
|
||||||
|
<div class="dropdown-display">
|
||||||
|
<div class="card ~neutral !low" id="lang-list">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
<div class="page-container">
|
<div class="page-container">
|
||||||
<div class="mb-1">
|
<div class="mb-1">
|
||||||
<header class="flex flex-wrap items-center justify-between">
|
<header class="flex flex-wrap items-center justify-between">
|
||||||
|
2
main.go
2
main.go
@ -577,7 +577,7 @@ func start(asDaemon, firstCall bool) {
|
|||||||
router.GET("/accounts", app.AdminPage)
|
router.GET("/accounts", app.AdminPage)
|
||||||
router.GET("/settings", app.AdminPage)
|
router.GET("/settings", app.AdminPage)
|
||||||
|
|
||||||
router.GET("/lang", app.GetLanguages)
|
router.GET("/lang/:page", app.GetLanguages)
|
||||||
router.GET("/token/login", app.getTokenLogin)
|
router.GET("/token/login", app.getTokenLogin)
|
||||||
router.GET("/token/refresh", app.getTokenRefresh)
|
router.GET("/token/refresh", app.getTokenRefresh)
|
||||||
router.POST("/newUser", app.NewUser)
|
router.POST("/newUser", app.NewUser)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { toggleTheme, loadTheme } from "./modules/theme.js";
|
import { toggleTheme, loadTheme } from "./modules/theme.js";
|
||||||
import { lang, LangFile } from "./modules/lang.js";
|
import { lang, LangFile, loadLangSelector } from "./modules/lang.js";
|
||||||
import { Modal } from "./modules/modal.js";
|
import { Modal } from "./modules/modal.js";
|
||||||
import { Tabs } from "./modules/tabs.js";
|
import { Tabs } from "./modules/tabs.js";
|
||||||
import { inviteList, createInvite } from "./modules/invites.js";
|
import { inviteList, createInvite } from "./modules/invites.js";
|
||||||
@ -11,9 +11,8 @@ import { _get, _post, notificationBox, whichAnimationEvent, toggleLoader } from
|
|||||||
loadTheme();
|
loadTheme();
|
||||||
(document.getElementById('button-theme') as HTMLSpanElement).onclick = toggleTheme;
|
(document.getElementById('button-theme') as HTMLSpanElement).onclick = toggleTheme;
|
||||||
|
|
||||||
var langLoaded = false;
|
|
||||||
|
|
||||||
window.lang = new lang(window.langFile as LangFile);
|
window.lang = new lang(window.langFile as LangFile);
|
||||||
|
loadLangSelector("admin");
|
||||||
// _get(`/lang/admin/${window.language}.json`, null, (req: XMLHttpRequest) => {
|
// _get(`/lang/admin/${window.language}.json`, null, (req: XMLHttpRequest) => {
|
||||||
// if (req.readyState == 4 && req.status == 200) {
|
// if (req.readyState == 4 && req.status == 200) {
|
||||||
// langLoaded = true;
|
// langLoaded = true;
|
||||||
|
19
ts/form.ts
19
ts/form.ts
@ -1,5 +1,6 @@
|
|||||||
import { Modal } from "./modules/modal.js";
|
import { Modal } from "./modules/modal.js";
|
||||||
import { _get, _post, toggleLoader } from "./modules/common.js";
|
import { _get, _post, toggleLoader } from "./modules/common.js";
|
||||||
|
import { loadLangSelector } from "./modules/lang.js";
|
||||||
|
|
||||||
interface formWindow extends Window {
|
interface formWindow extends Window {
|
||||||
validationStrings: pwValStrings;
|
validationStrings: pwValStrings;
|
||||||
@ -22,23 +23,7 @@ interface pwValStrings {
|
|||||||
[ type: string ]: pwValString;
|
[ type: string ]: pwValString;
|
||||||
}
|
}
|
||||||
|
|
||||||
_get("/lang", null, (req: XMLHttpRequest) => {
|
loadLangSelector("form");
|
||||||
if (req.readyState == 4) {
|
|
||||||
if (req.status != 200) {
|
|
||||||
document.getElementById("lang-dropdown").remove();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const list = document.getElementById("lang-list") as HTMLDivElement;
|
|
||||||
let innerHTML = '';
|
|
||||||
for (let code in req.response) {
|
|
||||||
innerHTML += `<a href="?lang=${code}" class="button input ~neutral field mb-half">${req.response[code]}</a>`;
|
|
||||||
}
|
|
||||||
list.innerHTML = innerHTML;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window.modal = new Modal(document.getElementById("modal-success"));
|
window.modal = new Modal(document.getElementById("modal-success"));
|
||||||
declare var window: formWindow;
|
declare var window: formWindow;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { _get } from "../modules/common.js";
|
||||||
|
|
||||||
interface Meta {
|
interface Meta {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
@ -45,7 +47,20 @@ export class lang implements Lang {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const loadLangSelector = (page: string) => _get("/lang/" + page, null, (req: XMLHttpRequest) => {
|
||||||
|
if (req.readyState == 4) {
|
||||||
|
if (req.status != 200) {
|
||||||
|
document.getElementById("lang-dropdown").remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const list = document.getElementById("lang-list") as HTMLDivElement;
|
||||||
|
let innerHTML = '';
|
||||||
|
for (let code in req.response) {
|
||||||
|
innerHTML += `<a href="?lang=${code}" class="button input ~neutral field mb-half">${req.response[code]}</a>`;
|
||||||
|
}
|
||||||
|
list.innerHTML = innerHTML;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user