diff --git a/frontend/www/scripts/workout.js b/frontend/www/scripts/workout.js index 61dbe5b84226a4a79a237c6142106015167fec53..8d49ca259fc5115a2be99545074aa1109fbb568d 100644 --- a/frontend/www/scripts/workout.js +++ b/frontend/www/scripts/workout.js @@ -134,6 +134,22 @@ function athleteChecked() { myself.style.display = "block"; } } +async function athletesInDropdown() { + let ath = document.getElementById("athletes"); + let currentUser = await getCurrentUser(); + console.log("hei"); + console.log(currentUser.username); + console.log(currentUser.athletes); + for (let athleteUrl of currentUser.athletes) { + let newElement = document.createElement("option"); + let response = await sendRequest("GET", athleteUrl); + let athlete = await response.json(); + console.log(athlete); + newElement.text = athlete.username; + ath.add(newElement); + } + click = true; +} function handleEditWorkoutButtonClick() { let addExerciseButton = document.querySelector("#btn-add-exercise"); @@ -192,6 +208,9 @@ async function updateWorkout(id) { location.reload(); } } +function getOwnerID(username) { + return username.url; +} function generateWorkoutForm() { let form = document.querySelector("#form-workout"); @@ -380,6 +399,7 @@ window.addEventListener("DOMContentLoaded", async () => { const id = urlParams.get("id"); let workoutData = await retrieveWorkout(id); await retrieveComments(id); + console.log(currentUser.url); if (workoutData["owner"] == currentUser.url) { editWorkoutButton.classList.remove("hide"); @@ -400,8 +420,17 @@ window.addEventListener("DOMContentLoaded", async () => { } } else { await createBlankExercise(); - let ownerInput = document.querySelector("#inputOwner"); + + coach = false; //sjekke om den er huket av + let query = "#inputOwner"; + let ownerInput = document.querySelector(query); ownerInput.value = currentUser.username; + if (coach) { + query = "#athletes"; + ownerInput = document.querySelector(query); + ownerInput.value = "athlete1"; + } + console.log(ownerInput.value); setReadOnly(false, "#form-workout"); ownerInput.readOnly = !ownerInput.readOnly; diff --git a/frontend/www/workout.html b/frontend/www/workout.html index 4e3f43d3e3845c2a479ae72e7b2d79d6f986e180..9be50088c6c29fe878290be404eb368938529662 100644 --- a/frontend/www/workout.html +++ b/frontend/www/workout.html @@ -69,12 +69,10 @@ <select id="athletes" class="form-select" - name="athletes" + name="owner_username" style="display:none" + onclick="athletesInDropdown(); this.onclick=null;" > - <option value="1">athlete 1</option> - <option value="2">athlete 2</option> - <option value="3">athlete 3</option> </select> <input