MobileApp/www/views/app.html

83 lines
3.6 KiB
HTML
Raw Normal View History

<iframe id="appframe" src="views/appspinner.html" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0px;"></iframe>
2017-06-29 04:01:49 -06:00
<script src="js/material-palette.js"></script>
2017-06-29 04:01:49 -06:00
<script>
/**
* Open an app with native Android UI elements
* @param String id Application ID
* @param String api Path to the mobile API
* @param String url Base URL of the app
* @param String icon URL to the app icon
* @param String title Friendly app name
* @param boolean injectcode (optional, default true) Whether or not to inject UI modification code into the app
* @param boolean shownavbar (optional, default false) Whether or not to show the navbar at the top of the screen.
* @returns {undefined}
*/
function launchapp(id, api, url, icon, title, injectcode, shownavbar) {
if (typeof shownavbar === 'undefined' || shownavbar === false) {
setnavbar(false);
} else {
setnavbar("app", title);
$('#appframe').css('top', '75px');
}
2017-06-29 04:01:49 -06:00
$.post(url + api, {
username: localStorage.getItem("username"),
key: localStorage.getItem("key"),
password: localStorage.getItem("password"),
action: "start_session"
}, function (data) {
if (data.status === 'OK') {
if (typeof injectcode === 'undefined' || injectcode === true) {
$('#appframe').on("load", function () {
$.get("css/sidemenu.css", function (style) {
$('#appframe').contents().find('head').append("<style>" + style + "</style>");
$.get("js/sidemenu.js", function (script) {
script = script.replace("%%USERNAME%%", userinfo.realname);
script = script.replace("%%LOGO%%", icon);
$('#appframe').contents().find('body').append("<script>" + script + "<\/script>");
});
});
});
} else {
// Only inject minimal CSS
$('#appframe').on("load", function () {
$.get("css/inject_mini.css", function (style) {
$('#appframe').contents().find('head').append("<style>" + style + "</style>");
2017-06-29 04:01:49 -06:00
});
});
}
2017-06-29 04:01:49 -06:00
$('#appframe').attr('src', url);
} else {
navigator.notification.alert(data.msg, null, "Error", 'Dismiss');
openscreen("home");
}
}, "json").fail(function () {
navigator.notification.alert("Could not connect to the server. Try again later.", null, "Error", 'Dismiss');
openscreen("home");
});
}
2017-06-30 00:56:47 -06:00
window.addEventListener('message', function (event) {
console.log(event.data);
if (event.data == "quit") {
openscreen("home");
} else if (event.data.startsWith("setcolor ")) {
var color = event.data.split(" ", 2)[1];
if (cordova.platformId == 'android') {
window.plugins.headerColor.tint(color);
for (var swatch in _PALETTE) {
if (color == _PALETTE[swatch]["shade_500"]) {
StatusBar.backgroundColorByHexString(_PALETTE[swatch]["shade_700"]);
return;
}
}
} else {
StatusBar.backgroundColorByHexString(color);
}
2017-06-30 00:56:47 -06:00
}
}, false);
if (userinfo == null) {
getuserinfo();
}
2017-06-29 04:01:49 -06:00
</script>