diff options
author | Noah Loomans <noahloomans@gmail.com> | 2016-12-14 12:57:59 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2016-12-14 12:57:59 +0100 |
commit | 7c4d1ca2d771ee527201ccd6447e70da97ad33be (patch) | |
tree | e151354bb2182d9788c0e2e8e85d560ccb862f3f /public/javascripts/schedule.js | |
parent | a016343e0a88e1bb46a2deed0b27dda7b6bc7e44 (diff) | |
parent | b7027583efff12e1bd5acdbb4077ab36c5226839 (diff) |
Merge branch 'refactor' into beta
Diffstat (limited to 'public/javascripts/schedule.js')
-rw-r--r-- | public/javascripts/schedule.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/public/javascripts/schedule.js b/public/javascripts/schedule.js new file mode 100644 index 0000000..e3944f8 --- /dev/null +++ b/public/javascripts/schedule.js @@ -0,0 +1,55 @@ +const leftPad = require('left-pad') +const autocomplete = require('./autocomplete') +const search = require('./search') + +const self = {} + +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._nodes.schedule.appendChild(document) +} + +self._handleError = function (event) { + const request = event.target + console.error(request) +} + +self._getURLOfUsers = function (week, type, index) { + const id = index + 1 + return `//${window.location.host}/meetingpointProxy/Roosters-AL%2Fdoc%2Fdagroosters%2F` + + `${(week)}%2F${type}%2F${type}${leftPad(id, 5, '0')}.htm` +} + +self.viewItem = function (week, selectedUser) { + const url = self._getURLOfUsers(week, selectedUser.type, selectedUser.index) + + while (self._nodes.schedule.firstChild) { + self._nodes.schedule.removeChild(self._nodes.schedule.firstChild) + } + + 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 |