let dateOptions = {month: 'short', year: 'numeric'}; document.addEventListener('DOMContentLoaded', () => { // check if the user is logged in, if not redirect to log in fetch('/api/user/isLoggedIn').then(res => { if (!res.ok) { window.location.href = './'; } }); document.querySelector("#dateFromE").max = new Date().toISOString().split("T")[0]; document.querySelector("#dateFromW").max = new Date().toISOString().split("T")[0]; fetch("/api/timelineData/edu").then(res => { res.json().then(json => { if (res.ok) { for (let i = 0; i < json.length; i++) { addEduData(json[i].ID, json[i].startPeriod, json[i].endPeriod, json[i].grade, json[i].course); } return; } document.querySelector("#edu").innerHTML = "No education data found"; }) }); fetch("/api/timelineData/work").then(res => { res.json().then(json => { if (res.ok) { for (let i = 0; i < json.length; i++) { let endPeriod = json[i].endPeriod === null ? "Present" : json[i].endPeriod; addWorkData(json[i].ID, json[i].startPeriod, endPeriod, json[i].companyName, json[i].area, json[i].title); } return; } document.querySelector("#edu").innerHTML = "No education data found"; }) }); fetch("/api/projectData").then(res => { res.json().then(json => { if (res.ok) { json.forEach(item => { addProject(item["information"], item["projectLink"], item["gitLink"]); }) return; } document.querySelector("#projects").innerHTML = "No project data found"; }) }) }) document.querySelector("#navOpen").addEventListener("click", e => { document.querySelector("nav.sideNav").style.removeProperty("width"); document.querySelector("main.editor").style.removeProperty("margin-left"); e.target.style.removeProperty("visibility"); }); document.querySelector("#navClose").addEventListener("click", () => { document.querySelector("nav.sideNav").style.width = "0"; document.querySelector("main.editor").style.marginLeft = "0"; document.querySelector("#navOpen").style.visibility = "visible"; }); document.querySelector("#addEdu").addEventListener("submit", e => { e.preventDefault(); let data = new FormData(); data.append("dateFrom", document.querySelector("#dateFromE").value); data.append("dateTo", document.querySelector("#dateToE").value); data.append("grade", document.querySelector("#grade").value); data.append("course", document.querySelector("#courseTitle").value); fetch("/api/timelineData/edu", { method: "POST", body: data, headers: { "Authentication": localStorage.getItem("token") } }).then(res => res.json().then(json => { if (res.ok) { addEduData(json.ID, data.get("dateFrom"), data.get("dateTo"), data.get("grade"), data.get("course"), true); document.querySelector("#addEdu").reset(); return; } if (res.status === 401) { window.location.href = "./"; return; } document.querySelector("#eduError").classList.remove("hidden"); document.querySelector("#eduError div").innerHTML = json.error; })); }); document.querySelector("#addWork").addEventListener("submit", e => { e.preventDefault(); let data = new FormData(); data.append("dateFrom", document.querySelector("#dateFromW").value); data.append("dateTo", document.querySelector("#dateToW").value); data.append("companyName", document.querySelector("#company").value); data.append("area", document.querySelector("#area").value); data.append("title", document.querySelector("#jobTitle").value); fetch("/api/timelineData/work", { method: "POST", body: data, headers: { "Authentication": localStorage.getItem("token") } }).then(res => res.json().then(json => { if (res.ok) { let endPeriod = data.get("dateTo") === null ? "Present" : data.get("dateTo "); addWorkData(json.ID, data.get("dateFrom"), endPeriod, data.get("companyName"), data.get("area"), data.get("title"), true); document.querySelector("#addEdu").reset(); return; } if (res.status === 401) { window.location.href = "./"; return; } document.querySelector("#eduError").classList.remove("hidden"); document.querySelector("#eduError div").innerHTML = json.error; })); }); document.querySelector("#goToCV").addEventListener("click", () => { document.querySelector("#curriculumVitae").style.display = "block"; document.querySelector("#goToCV").classList.toggle("active"); document.querySelector("#projects").style.display = "none"; document.querySelector("#goToProjects").classList.toggle("active"); }); document.querySelector("#goToProjects").addEventListener("click", () => { document.querySelector("#curriculumVitae").style.display = "none"; document.querySelector("#goToCV").classList.toggle("active"); document.querySelector("#projects").style.display = "block"; document.querySelector("#goToProjects").classList.toggle("active"); }); document.querySelector("#logout").addEventListener("click", () => { document.cookie = "PHPSESSID=;Path=/cv;expires=Thu, 01 Jan 1970 00:00:01 GMT;"; window.location.reload(); }); /** * Switches the timeline item between edit and view mode * @param id the id of the timeline item */ function edit(id) { document.querySelector("#timelineItem" + id).classList.toggle("editing"); if (id.includes("e")) { document.querySelector("#grade" + id).toggleAttribute("disabled"); document.querySelector("#course" + id).toggleAttribute("disabled"); return; } document.querySelector("#companyName" + id).toggleAttribute("disabled"); document.querySelector("#area" + id).toggleAttribute("disabled"); document.querySelector("#jobTitle" + id).toggleAttribute("disabled"); } /** * Updates the education timeline item with the given id * @param ID - the id of the course timeline item * @param startPeriod - the start date of the course * @param endPeriod - the end date of the course * @param grade - the grade of the course * @param course - the name of the course * @param prepend - whether to prepend the timeline item to the timeline */ function addEduData(ID, startPeriod, endPeriod, grade, course, prepend=false) { let id = ID + "e"; let timelineItem = document.createElement("form") timelineItem.id = "timelineItem" + id; timelineItem.classList.add("timelineItem"); timelineItem.onsubmit = e => updateEduItem(ID, e); timelineItem.innerHTML = `