Skip to content
Snippets Groups Projects
Commit 355e9d97 authored by Irina Kera Gundersen's avatar Irina Kera Gundersen
Browse files

Add everything except backend

parent 9bd5e066
No related branches found
No related tags found
1 merge request!6Uc 1
Pipeline #113682 passed
......@@ -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;
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment