Added localization override to mobile app

Ylian Saint-Hilaire committed Jul 26, 2019 at 14:52 UTC 45fa3d61e611b4e78d0ef33c05d0fc1e4d5e9d6d
2 files changed +29 -16
views/default-mobile.handlebars
+27 -1
@@ -590,6 +590,13 @@
590 <iframe name="fileUploadFrame" style=display:none></iframe>
591 <script>
592 'use strict';
593 +
594 + // Process server-side web state
595 + var webState = "{{{webstate}}}";
596 + if (webState != "") { webState = JSON.parse(decodeURIComponent(webState)); }
597 + for (var i in webState) { localStorage.setItem(i, webState[i]); }
598 + if (!webState.loctag) { delete localStorage.removeItem('loctag'); }
599 +
600 var args = parseUriArgs();
601 var debugLevel = parseInt('{{{debuglevel}}}');
602 var features = parseInt('{{{features}}}');
@@ -624,6 +631,8 @@
631 if (top != self && (loc == null || top.active == false)) { top.location = self.location; return; }
632 }
633
634 + if (!args.locale) { var x = getstore('loctag', 0); if ((x != null) && (x != '*')) { args.locale = x; } }
635 +
636 window.onresize = center;
637 center();
638 QV('changeEmailId', (features & 0x200000) == 0);
@@ -826,6 +835,21 @@
835 */
836 if (message.event.noact) break; // Take no action on this event
837 switch (message.event.action) {
838 + case 'userWebState': {
839 + // New user web state, update the web page as needed
840 + if (localStorage != null) {
841 + var webstate = JSON.parse(message.event.state);
842 + for (var i in webstate) { localStorage.setItem(i, webstate[i]); }
843 +
844 + // Update the web page
845 + if ((webstate.loctag != null) && (webstate.loctag != oldLoctag)) {
846 + if (webstate.loctag != null) { args.locale = webstate.loctag; } else { delete args.locale; }
847 + updateDevices();
848 + updateMeshes();
849 + }
850 + }
851 + break;
852 + }
853 case 'accountchange': {
854 // An account was created or changed
855 if (userinfo.name == message.event.account.name) {
@@ -932,7 +956,7 @@
956 }
957 nodes.splice(index, 1);
958 updateDevices();
935 - updateMapMarkers();
959 + //updateMapMarkers();
960 }
961 break;
962 }
@@ -3257,6 +3281,8 @@
3281 if (((b & 8) || x) && f) f(x, t);
3282 }
3283
3284 + 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) }); } }
3285 + 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; } }
3286 function center() { QS('dialog').left = ((((getDocWidth() - 300) / 2)) + "px"); deskAdjust(); deskAdjust(); /*drawDeviceTimeline();*/ }
3287 function messagebox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t, 1); }
3288 function statusbox(t, m) { QH('id_dialogMessage', m); setDialogMode(1, t); }
views/default.handlebars
+2 -15
@@ -901,7 +901,7 @@
901 var webState = "{{{webstate}}}";
902 if (webState != "") { webState = JSON.parse(decodeURIComponent(webState)); }
903 for (var i in webState) { localStorage.setItem(i, webState[i]); }
904 - //localStorage.clear();
904 + if (!webState.loctag) { delete localStorage.removeItem('loctag'); }
905
906 var args;
907 var autoReconnect = true;
@@ -8439,20 +8439,7 @@
8439
8440 // Generic methods
8441 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('/'); }
8442 - function putstore(name, val) {
8443 - try {
8444 - if ((typeof (localStorage) === 'undefined') || (localStorage.getItem(name) == val)) return;
8445 - if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); }
8446 - } catch (e) { }
8447 - if (name[0] != '_') {
8448 - var s = {};
8449 - for (var i = 0, len = localStorage.length; i < len; ++i) {
8450 - var k = localStorage.key(i);
8451 - if (k[0] != '_') { s[k] = localStorage.getItem(k); }
8452 - }
8453 - meshserver.send({ action: 'userWebState', state: JSON.stringify(s) });
8454 - }
8455 - }
8442 + 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) }); } }
8443 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; } }
8444 //function addLink(x, f) { return "<a style=cursor:pointer;color:darkblue;text-decoration:none onclick='" + f + "'>&diams; " + x + "</a>"; }
8445 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>"; }