settings rewrite to JS
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
var timerRefreshData = ''
|
||||
var modalCallbackFunction = '';
|
||||
var emptyArr = ['undefined', "", undefined, null, 'null'];
|
||||
UI_LANG = "English";
|
||||
|
||||
|
||||
// urlParams = new Proxy(new URLSearchParams(window.location.search), {
|
||||
// get: (searchParams, prop) => searchParams.get(prop.toString()),
|
||||
@@ -100,38 +102,92 @@ function deleteAllCookies() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Get settings from the .json file generated by the python backend
|
||||
// -----------------------------------------------------------------------------
|
||||
function cacheSettings()
|
||||
{
|
||||
|
||||
$.get('api/table_settings.json', function(res) {
|
||||
|
||||
data = res["data"];
|
||||
|
||||
data.forEach((set) => {
|
||||
setCache(`pia_set_${set.Code_Name}`, set.Value)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function getSetting (key) {
|
||||
|
||||
result = getCache(`pia_set_${key}`, true);
|
||||
|
||||
if (result == "")
|
||||
{
|
||||
console.log(`Setting with key "${key}" not found`)
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Get language string
|
||||
// -----------------------------------------------------------------------------
|
||||
function cacheStrings()
|
||||
{
|
||||
|
||||
// handle core strings and translations
|
||||
var allLanguages = ["en_us","es_es","de_de"]; // needs to be same as in lang.php
|
||||
|
||||
allLanguages.forEach(function (language_code) {
|
||||
|
||||
$.get(`php/templates/language/${language_code}.json`, function(res) {
|
||||
|
||||
Object.entries(res).forEach(([language, translations]) => {
|
||||
|
||||
Object.entries(translations).forEach(([key, value]) => {
|
||||
|
||||
setCache(`pia_lang_${key}_${language}`, value)
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
// handle strings and translations from plugins
|
||||
$.get('api/table_language_strings.json', function(res) {
|
||||
|
||||
data = res["data"];
|
||||
|
||||
data.forEach((langString) => {
|
||||
// console.log(langString)
|
||||
setCache(`pia_lang_${langString.String_Key}`, langString.String_Value)
|
||||
});
|
||||
|
||||
data.forEach((langString) => {
|
||||
setCache(`pia_lang_${langString.String_Key}_${langString.Language_Code}`, langString.String_Value)
|
||||
});
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function getString (key) {
|
||||
// todo
|
||||
// php/server/utilDB.php?key=Gen_Okay
|
||||
// need to initilaize session storage
|
||||
|
||||
result = getCache(`pia_lang_${key}`, true);
|
||||
|
||||
UI_LANG = getSetting("UI_LANG");
|
||||
|
||||
if (result == "")
|
||||
lang_code = 'en_us';
|
||||
|
||||
switch(UI_LANG)
|
||||
{
|
||||
getCache(`pia_lang_${key}`, true)
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is async can't do that
|
||||
case 'English':
|
||||
lang_code = 'en_us';
|
||||
break;
|
||||
case 'Spanish':
|
||||
lang_code = 'es_es';
|
||||
break;
|
||||
case 'German':
|
||||
lang_code = 'de_de';
|
||||
break;
|
||||
}
|
||||
result = getCache(`pia_lang_${key}_${lang_code}`, true);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -410,8 +466,10 @@ function navigateToDeviceWithIp (ip) {
|
||||
}
|
||||
|
||||
// initialize
|
||||
cacheSettings()
|
||||
cacheStrings()
|
||||
|
||||
|
||||
console.log("init pialert_common.js")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user