Commit 87ce3a61 authored by Håkon Finstad's avatar Håkon Finstad
Browse files

added stuff to workout js

parent 44a603c9
......@@ -335,18 +335,22 @@ function removeAthleteRow(event) {
event.currentTarget.parentElement.remove();
}
async function displayCurrentRoster() {
async function displayCurrentRoster(currentUser, workoutid) {
let templateFilledAthlete = document.querySelector("#template-filled-member");
let templateEmptyAthlete = document.querySelector("#template-empty-member");
let controls = document.querySelector("#controls");
/*let currentUser = await getCurrentUser();
for (let athleteUrl of currentUser.athletes) {
let body = {workout: `${HOST}/api/workouts/${workoutid}/`};
console.log(body);
console.log(workout);
for (let member of workout.members) {
let response = await sendRequest("GET", athleteUrl);
let athlete = await response.json();
createFilledRow(templateFilledAthlete, athlete.username, controls, false);
}*/
}
let emptyClone = templateEmptyAthlete.content.cloneNode(true);
let emptyDiv = emptyClone.querySelector("div");
......@@ -371,7 +375,6 @@ window.addEventListener("DOMContentLoaded", async () => {
galleryButton.addEventListener("click", handleGalleryButtonClick);
await displayCurrentRoster();
const urlParams = new URLSearchParams(window.location.search);
let currentUser = await getCurrentUser();
......@@ -381,13 +384,15 @@ window.addEventListener("DOMContentLoaded", async () => {
let workoutData = await retrieveWorkout(id);
await retrieveComments(id);
if (workoutData["owner"] == currentUser.url) {
if (workoutData["owner"] == currentUser.url || workoutData["members"].includes(currentUser.url)) {
editWorkoutButton.classList.remove("hide");
editWorkoutButton.addEventListener("click", handleEditWorkoutButtonClick);
deleteWorkoutButton.addEventListener("click", (async (id) => await deleteWorkout(id)).bind(undefined, id));
okWorkoutButton.addEventListener("click", (async (id) => await updateWorkout(id)).bind(undefined, id));
postCommentButton.addEventListener("click", (async (id) => await createComment(id)).bind(undefined, id));
divCommentRow.className = divCommentRow.className.replace(" hide", "");
await displayCurrentRoster(currentUser, id);
}
} else {
await createBlankExercise();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment