main.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict'
  2. import { marshalActionButtonsJsonToHtml } from './js/marshaller.js'
  3. /**
  4. * Design choice; define this as a "global function" (on window) so that it can
  5. * easily be used anywhere without needing to import it, as it's a pretty
  6. * fundemental thing.
  7. */
  8. window.showBigError = (type, friendlyType, message) => {
  9. console.error("Error " + type + ": ", err)
  10. var err = document.createElement("div")
  11. err.classList.add("error")
  12. err.innerHTML = "<h1>Error " + friendlyType + "</h1><p>" + message + "</p><p><a href = 'http://github.com/jamesread/OliveTin' target = 'blank'/>OliveTin Documentation</a></p>";
  13. document.getElementById('rootGroup').appendChild(err)
  14. }
  15. function onInitialLoad(res) {
  16. window.restBaseUrl = res.Rest;
  17. window.fetch(window.restBaseUrl + "GetButtons", {
  18. cors: 'cors',
  19. // No fetch options
  20. }).then(res => {
  21. return res.json()
  22. }).then(res => {
  23. marshalActionButtonsJsonToHtml(res)
  24. }).catch(err => {
  25. showBigError("fetch-initial-buttons", "getting initial buttons", err, "blat")
  26. });
  27. }
  28. window.fetch('webUiSettings.json').then(res => {
  29. return res.json()
  30. }).then(res => {
  31. onInitialLoad(res)
  32. }).catch(err => {
  33. showBigError("fetch-webui-settings", "getting webui settings", err);
  34. })