mirror of
https://github.com/Soulful-Sailer/Event-Tracker.git
synced 2026-03-29 16:16:46 -05:00
version 1.0.0 commit
This commit is contained in:
29
static/scripts/loadEvents.js
Normal file
29
static/scripts/loadEvents.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Retrieves the list of events from the server and adds them respective to their section
|
||||
*/
|
||||
function loadEvents() {
|
||||
fetchFile("events.json", "json").then((events) => {
|
||||
//if server replies with requested data
|
||||
if (events) {
|
||||
for (let header in events) {
|
||||
events[header].forEach((eventData) => {
|
||||
addEvent(eventData, header);
|
||||
});
|
||||
}
|
||||
}
|
||||
else console.log("Could not retrieve event data");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds event to specified header via creating a new instance of EventItem
|
||||
* @param {Object} eventData - contains required information about the event
|
||||
* @param {string} header - specifies under which section to add the new event item
|
||||
*/
|
||||
function addEvent(eventData, header) {
|
||||
let item = new EventItem(eventData);
|
||||
document.getElementById(header).append(item.elem);
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", loadEvents);
|
||||
Reference in New Issue
Block a user