olivetin/webui/main.js

39 lines
1.1 KiB
JavaScript

'use strict'
import { loadContents } from './js/loader.js'
/**
* Design choice; define this as a "global function" (on window) so that it can
* easily be used anywhere without needing to import it, as it's a pretty
* fundemental thing.
*/
window.showBigError = (type, friendlyType, message) => {
console.error("Error " + type + ": ", err)
var err = document.createElement("div")
err.classList.add("error")
err.innerHTML = "<h1>Error " + friendlyType + "</h1><p>" + message + "</p><p><a href = 'http://github.com/jamesread/OliveTin' target = 'blank'/>OliveTin Documentation</a></p>";
document.getElementById('rootGroup').appendChild(err)
}
function onInitialLoad(res) {
window.restBaseUrl = res.Rest;
window.fetch(window.restBaseUrl + "GetButtons").then(res => {
return res.json()
}).then(res => {
loadContents(res)
}).catch(err => {
showBigError("fetch-initial-buttons", "getting initial buttons", err, "blat")
});
}
window.fetch('webUiSettings.json').then(res => {
return res.json()
}).then(res => {
onInitialLoad(res)
}).catch(err => {
showBigError("fetch-webui-settings", "getting webui settings", err);
})