diff options
author | Noah Loomans <noahloomans@gmail.com> | 2017-09-13 21:29:15 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2017-09-13 21:29:15 +0200 |
commit | e87bf34e06f8bec3c6622102528c2d685b3cbb5b (patch) | |
tree | eadfe43844faf52293f293ab37d9d621b6821329 /src/client/javascript/schedule.js | |
parent | 3fb86482404e11942cd83c3500a297a3991db0e4 (diff) |
Add some basic elm
Diffstat (limited to 'src/client/javascript/schedule.js')
-rw-r--r-- | src/client/javascript/schedule.js | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/src/client/javascript/schedule.js b/src/client/javascript/schedule.js deleted file mode 100644 index 38ad66d..0000000 --- a/src/client/javascript/schedule.js +++ /dev/null @@ -1,78 +0,0 @@ -/* global VALID_WEEK_NUMBERS */ - -const EventEmitter = require('events') -const search = require('./search') - -const self = new EventEmitter() - -self._nodes = { - schedule: document.querySelector('#schedule') -} - -self._parseMeetingpointHTML = function (htmlStr) { - const html = document.createElement('html') - html.innerHTML = htmlStr - const centerNode = html.querySelector('center') - return centerNode -} - -self._handleLoad = function (event) { - const request = event.target - if (request.status < 200 || request.status >= 400) { - self._handleError(event) - return - } - const document = self._parseMeetingpointHTML(request.response) - self._removeChilds() - self._nodes.schedule.appendChild(document) - self._nodes.schedule.classList.remove('error') - self.emit('load') -} - -self._handleError = function (event) { - const request = event.target - let error - if (request.status === 404) { - error = 'Sorry, er is (nog) geen rooster voor deze week.' - } else { - error = 'Sorry, er is iets mis gegaan tijdens het laden van deze week.' - } - self._removeChilds() - self._nodes.schedule.textContent = error - self._nodes.schedule.classList.add('error') - self.emit('load') -} - -self._getURLOfUser = function (week, user) { - return `/get/${user.type}/${user.value}?week=${week}` -} - -self._removeChilds = function () { - while (self._nodes.schedule.firstChild) { - self._nodes.schedule.removeChild(self._nodes.schedule.firstChild) - } -} - -self.viewItem = function (week, selectedUser) { - if (selectedUser == null) { - self._removeChilds() - search.updateDom(selectedUser) - } else if (VALID_WEEK_NUMBERS.indexOf(week) === -1) { - self._handleError({ target: { status: 404 } }); - return - } else { - const url = self._getURLOfUser(week, selectedUser) - - self._removeChilds() - - const request = new window.XMLHttpRequest() - request.addEventListener('load', self._handleLoad) - request.addEventListener('error', self._handleError) - request.open('GET', url, true) - request.send() - - search.updateDom(selectedUser) - } -} - -module.exports = self |