Added localization override to mobile app

This commit is contained in:
Ylian Saint-Hilaire 2019-07-26 14:52:59 -07:00
parent 1694e52294
commit 0d3c2fdfe3
2 changed files with 29 additions and 16 deletions

View File

@ -590,6 +590,13 @@
<iframe name="fileUploadFrame" style=display:none></iframe> <iframe name="fileUploadFrame" style=display:none></iframe>
<script> <script>
'use strict'; 'use strict';
// Process server-side web state
var webState = "{{{webstate}}}";
if (webState != "") { webState = JSON.parse(decodeURIComponent(webState)); }
for (var i in webState) { localStorage.setItem(i, webState[i]); }
if (!webState.loctag) { delete localStorage.removeItem('loctag'); }
var args = parseUriArgs(); var args = parseUriArgs();
var debugLevel = parseInt('{{{debuglevel}}}'); var debugLevel = parseInt('{{{debuglevel}}}');
var features = parseInt('{{{features}}}'); var features = parseInt('{{{features}}}');
@ -624,6 +631,8 @@
if (top != self && (loc == null || top.active == false)) { top.location = self.location; return; } if (top != self && (loc == null || top.active == false)) { top.location = self.location; return; }
} }
if (!args.locale) { var x = getstore('loctag', 0); if ((x != null) && (x != '*')) { args.locale = x; } }
window.onresize = center; window.onresize = center;
center(); center();
QV('changeEmailId', (features & 0x200000) == 0); QV('changeEmailId', (features & 0x200000) == 0);
@ -826,6 +835,21 @@
*/ */
if (message.event.noact) break; // Take no action on this event if (message.event.noact) break; // Take no action on this event
switch (message.event.action) { switch (message.event.action) {
case 'userWebState': {
// New user web state, update the web page as needed
if (localStorage != null) {
var webstate = JSON.parse(message.event.state);
for (var i in webstate) { localStorage.setItem(i, webstate[i]); }
// Update the web page
if ((webstate.loctag != null) && (webstate.loctag != oldLoctag)) {
if (webstate.loctag != null) { args.locale = webstate.loctag; } else { delete args.locale; }
updateDevices();
updateMeshes();
}
}
break;
}
case 'accountchange': { case 'accountchange': {
// An account was created or changed // An account was created or changed
if (userinfo.name == message.event.account.name) { if (userinfo.name == message.event.account.name) {
@ -932,7 +956,7 @@
} }
nodes.splice(index, 1); nodes.splice(index, 1);
updateDevices(); updateDevices();
updateMapMarkers(); //updateMapMarkers();
} }
break; break;
} }
@ -3257,6 +3281,8 @@
if (((b & 8) || x) && f) f(x, t); if (((b & 8) || x) && f) f(x, t);
} }
function putstore(name, val) { try { if ((typeof (localStorage) === 'undefined') || (localStorage.getItem(name) == val)) return; if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); } } catch (e) { } if (name[0] != '_') { var s = {}; for (var i = 0, len = localStorage.length; i < len; ++i) { var k = localStorage.key(i); if (k[0] != '_') { s[k] = localStorage.getItem(k); } } meshserver.send({ action: 'userWebState', state: JSON.stringify(s) }); } }
function getstore(name, val) { try { if (typeof (localStorage) === 'undefined') return val; var v = localStorage.getItem(name); if ((v == null) || (v == null)) return val; return v; } catch (e) { return val; } }
function center() { QS('dialog').left = ((((getDocWidth() - 300) / 2)) + "px"); deskAdjust(); deskAdjust(); /*drawDeviceTimeline();*/ } function center() { QS('dialog').left = ((((getDocWidth() - 300) / 2)) + "px"); deskAdjust(); deskAdjust(); /*drawDeviceTimeline();*/ }
function messagebox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t, 1); } function messagebox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t, 1); }
function statusbox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t); } function statusbox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t); }

View File

@ -901,7 +901,7 @@
var webState = "{{{webstate}}}"; var webState = "{{{webstate}}}";
if (webState != "") { webState = JSON.parse(decodeURIComponent(webState)); } if (webState != "") { webState = JSON.parse(decodeURIComponent(webState)); }
for (var i in webState) { localStorage.setItem(i, webState[i]); } for (var i in webState) { localStorage.setItem(i, webState[i]); }
//localStorage.clear(); if (!webState.loctag) { delete localStorage.removeItem('loctag'); }
var args; var args;
var autoReconnect = true; var autoReconnect = true;
@ -8439,20 +8439,7 @@
// Generic methods // Generic methods
function joinPaths() { var x = []; for (var i in arguments) { var w = arguments[i]; if ((w != null) && (w != '')) { while (w.endsWith('/') || w.endsWith('\\')) { w = w.substring(0, w.length - 1); } while (w.startsWith('/') || w.startsWith('\\')) { w = w.substring(1); } x.push(w); } } return x.join('/'); } function joinPaths() { var x = []; for (var i in arguments) { var w = arguments[i]; if ((w != null) && (w != '')) { while (w.endsWith('/') || w.endsWith('\\')) { w = w.substring(0, w.length - 1); } while (w.startsWith('/') || w.startsWith('\\')) { w = w.substring(1); } x.push(w); } } return x.join('/'); }
function putstore(name, val) { function putstore(name, val) { try { if ((typeof (localStorage) === 'undefined') || (localStorage.getItem(name) == val)) return; if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); } } catch (e) { } if (name[0] != '_') { var s = {}; for (var i = 0, len = localStorage.length; i < len; ++i) { var k = localStorage.key(i); if (k[0] != '_') { s[k] = localStorage.getItem(k); } } meshserver.send({ action: 'userWebState', state: JSON.stringify(s) }); } }
try {
if ((typeof (localStorage) === 'undefined') || (localStorage.getItem(name) == val)) return;
if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); }
} catch (e) { }
if (name[0] != '_') {
var s = {};
for (var i = 0, len = localStorage.length; i < len; ++i) {
var k = localStorage.key(i);
if (k[0] != '_') { s[k] = localStorage.getItem(k); }
}
meshserver.send({ action: 'userWebState', state: JSON.stringify(s) });
}
}
function getstore(name, val) { try { if (typeof (localStorage) === 'undefined') return val; var v = localStorage.getItem(name); if ((v == null) || (v == null)) return val; return v; } catch (e) { return val; } } function getstore(name, val) { try { if (typeof (localStorage) === 'undefined') return val; var v = localStorage.getItem(name); if ((v == null) || (v == null)) return val; return v; } catch (e) { return val; } }
//function addLink(x, f) { return "<a style=cursor:pointer;color:darkblue;text-decoration:none onclick='" + f + "'>&diams; " + x + "</a>"; } //function addLink(x, f) { return "<a style=cursor:pointer;color:darkblue;text-decoration:none onclick='" + f + "'>&diams; " + x + "</a>"; }
function addLink(x, f) { return "<span tabindex=0 style=cursor:pointer;text-decoration:none onclick='" + f + "' onkeypress=\"if (event.key=='Enter') {" + f + "} \">" + x + " <img class=hoverButton src=images/link5.png></span>"; } function addLink(x, f) { return "<span tabindex=0 style=cursor:pointer;text-decoration:none onclick='" + f + "' onkeypress=\"if (event.key=='Enter') {" + f + "} \">" + x + " <img class=hoverButton src=images/link5.png></span>"; }