`;
if (prepend)
{
document.querySelector("#edu").prepend(timelineItem);
return;
}
document.getElementById("edu").appendChild(timelineItem);
}
/**
* Adds a new work timeline item to the page
* @param ID - the id of the work timeline item
* @param startPeriod - the start date of the job
* @param endPeriod - the end date of the job
* @param companyName - the name of the company
* @param area - the area of the company
* @param jobTitle - the job title
* @param prepend - whether to prepend the timeline item to the timeline
*/
function addWorkData(ID, startPeriod, endPeriod, companyName, area, jobTitle, prepend=false)
{
let id = ID + "w";
let timelineItem = document.createElement("form")
timelineItem.id = "timelineItem" + id;
timelineItem.classList.add("timelineItem");
timelineItem.onsubmit = e => updateWorkItem(ID, e);
timelineItem.innerHTML = `
`;
if (prepend)
{
document.querySelector("#work").prepend(timelineItem);
return;
}
document.getElementById("work").appendChild(timelineItem);
}
/**
* Updates the edu timeline item with the given id
* @param id the id of the edu timeline item
* @param e the event that triggered the function
*/
function updateEduItem(id, e)
{
e.preventDefault();
let data = {}
data["dateFrom"] = document.querySelector(`#dateFrom${id}e`).value;
data["dateTo"] = document.querySelector(`#dateTo${id}e`).value;
data["grade"] = document.querySelector(`#grade${id}e`).value;
data["course"] = document.querySelector(`#course${id}e`).value;
fetch("/api/timelineData/edu/" + id, {
method: "PATCH",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + localStorage.getItem("token")
}
}).then(res =>
{
if (res.ok)
{
document.querySelector(`#timelineHeader${id}e`).innerHTML = new Date(document.querySelector(`#dateFrom${id}e`).value).toLocaleString('en-gb', dateOptions) + " - " + new Date(document.querySelector(`#dateTo${id}e`).value).toLocaleString('en-gb', dateOptions);
document.querySelector(`#timelineItem${id}e`).classList.toggle("editing");
document.querySelector(`#grade${id}e`).setAttribute("disabled", "");
document.querySelector(`#course${id}e`).setAttribute("disabled", "");
return;
}
if (res.status === 401)
{
window.location.href = "./";
return;
}
res.json().then(json =>
{
document.querySelector(`#eduError${id}e`).classList.remove("hidden");
document.querySelector(`#eduError${id}e div`).innerHTML = json.error;
});
})
}
/**
* Updates the work timeline item with the given id
* @param id the id of the work timeline item
* @param e the event that triggered the function
*/
function updateWorkItem(id, e)
{
e.preventDefault();
let data = {}
data["dateFrom"] = document.querySelector(`#dateFrom${id}w`).value;
data["dateTo"] = document.querySelector(`#dateTo${id}w`).value;
data["companyName"] = document.querySelector(`#companyName${id}w`).value;
data["area"] = document.querySelector(`#area${id}w`).value;
data["title"] = document.querySelector(`#jobTitle${id}w`).value;
fetch("/api/timelineData/work/" + id, {
method: "PATCH",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + localStorage.getItem("token")
}
}).then(res =>
{
if(res.ok)
{
document.querySelector(`#timelineHeader${id}w`).innerHTML = new Date(document.querySelector(`#dateFrom${id}w`).value).toLocaleString('en-gb', dateOptions) + " - " + new Date(document.querySelector(`#dateTo${id}w`).value).toLocaleString('en-gb', dateOptions);
document.querySelector(`#timelineItem${id}w`).classList.toggle("editing");
document.querySelector(`#companyName${id}w`).setAttribute("disabled", "");
document.querySelector(`#area${id}w`).setAttribute("disabled", "");
document.querySelector(`#jobTitle${id}w`).setAttribute("disabled", "");
return;
}
if (res.status === 401)
{
window.location.href = "./";
return;
}
res.json().then(json =>
{
document.querySelector(`#workError${id}w`).classList.remove("hidden");
document.querySelector(`#workError${id}w div`).innerHTML = json.error;
});
});
}
/**
* Deletes the timeline item with the given id
* @param id the id of the timeline item
*/
function deleteEduItem(id)
{
fetch("/api/timelineData/edu/" + id, {
method: "DELETE",
headers: {
"Authorization": "Bearer " + localStorage.getItem("token")
}
}).then(res =>
{
if (res.ok)
{
document.querySelector(`#timelineItem${id}e`).remove();
return;
}
if (res.status === 401)
{
window.location.href = "./";
return;
}
res.json().then(json => alert(json.error));
});
}
/**
* Updates the timeline item with the given id
* @param id the id of the timeline item
*/
function deleteWorkItem(id)
{
fetch("/api/timelineData/work/" + id, {
method: "DELETE",
headers: {
"Authorization": "Bearer " + localStorage.getItem("token")
}
}).then(res =>
{
if (res.ok)
{
document.querySelector(`#timelineItem${id}w`).remove();
return;
}
if (res.status === 401)
{
window.location.href = "./";
return;
}
res.json().then(json => alert(json.error));
});
}