main.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict'
  2. import { marshalActionButtonsJsonToHtml } from './js/marshaller.js'
  3. function showBigError (type, friendlyType, message) {
  4. console.error('Error ' + type + ': ', message)
  5. const domErr = document.createElement('div')
  6. domErr.classList.add('error')
  7. domErr.innerHTML = '<h1>Error ' + friendlyType + '</h1><p>' + message + "</p><p><a href = 'http://github.com/jamesread/OliveTin' target = 'blank'/>OliveTin Documentation</a></p>"
  8. document.getElementById('rootGroup').appendChild(domErr)
  9. }
  10. function onInitialLoad (res) {
  11. window.restBaseUrl = res.Rest
  12. window.fetch(window.restBaseUrl + 'GetButtons', {
  13. cors: 'cors'
  14. // No fetch options
  15. }).then(res => {
  16. return res.json()
  17. }).then(res => {
  18. marshalActionButtonsJsonToHtml(res)
  19. }).catch(err => {
  20. showBigError('fetch-initial-buttons', 'getting initial buttons', err, 'blat')
  21. })
  22. }
  23. window.fetch('webUiSettings.json').then(res => {
  24. return res.json()
  25. }).then(res => {
  26. onInitialLoad(res)
  27. }).catch(err => {
  28. showBigError('fetch-webui-settings', 'getting webui settings', err)
  29. })