Commit 44a603c9 authored by Håkon Finstad's avatar Håkon Finstad
Browse files

frontend

parent 5fc8f0e6
Pipeline #160872 passed with stages
in 3 minutes and 4 seconds
......@@ -315,6 +315,46 @@ async function retrieveComments(workoutid) {
}
}
function addAthleteRow(event) {
let newBlankRow = event.currentTarget.parentElement.cloneNode(true);
let newInput = newBlankRow.querySelector("input");
newInput.value = "";
let controls = document.querySelector("#controls");
let button = newBlankRow.querySelector("button");
button.addEventListener("click", addAthleteRow);
controls.appendChild(newBlankRow);
event.currentTarget.className = "btn btn-danger btn-remove";
event.currentTarget.querySelector("i").className = "fas fa-minus";
event.currentTarget.removeEventListener("click", addAthleteRow);
event.currentTarget.addEventListener("click", removeAthleteRow);
}
function removeAthleteRow(event) {
event.currentTarget.parentElement.remove();
}
async function displayCurrentRoster() {
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 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");
let emptyButton = emptyDiv.querySelector("button");
emptyButton.addEventListener("click", addAthleteRow);
controls.appendChild(emptyDiv);
}
window.addEventListener("DOMContentLoaded", async () => {
cancelWorkoutButton = document.querySelector("#btn-cancel-workout");
okWorkoutButton = document.querySelector("#btn-ok-workout");
......@@ -331,6 +371,7 @@ window.addEventListener("DOMContentLoaded", async () => {
galleryButton.addEventListener("click", handleGalleryButtonClick);
await displayCurrentRoster();
const urlParams = new URLSearchParams(window.location.search);
let currentUser = await getCurrentUser();
......
......@@ -38,11 +38,15 @@ function createWorkout() {
window.location.replace("workout.html");
}
window.addEventListener("DOMContentLoaded", async () => {
let createButton = document.querySelector("#btn-create-workout");
createButton.addEventListener("click", createWorkout);
let ordering = "-date";
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('ordering')) {
let aSort = null;
......@@ -57,6 +61,7 @@ window.addEventListener("DOMContentLoaded", async () => {
currentSort.innerHTML = (ordering.startsWith("-") ? "Descending" : "Ascending") + " " + ordering.replace("-", "");
let currentUser = await getCurrentUser();
// grab username
if (ordering.includes("owner")) {
ordering += "__username";
......@@ -105,4 +110,5 @@ window.addEventListener("DOMContentLoaded", async () => {
}
});
}
});
\ No newline at end of file
});
......@@ -82,6 +82,17 @@
<div class="col-lg-6"></div>
</form>
<form id="form-roster" class="row">
<div class="col-lg-6">
<label class="form-label" for="controls">Athletes</label>
<div id="controls">
</div>
<input type="button" class="btn btn-primary mt-1 mb-2" id="button-submit-roster" value="Submit">
</div>
<div class="col-lg-6"></div>
</form>
<div class="row bootstrap snippets bootdeys" id="div-comment-row">
<div class="col-md-8 col-sm-12">
<div class="comment-wrapper">
......@@ -126,6 +137,26 @@
<div class="col-lg-6"></div>
</div>
</template>
<template id="template-filled-member">
<div class="entry input-group">
<input class="form-control" name="member" type="text"/>
<button class="btn btn-danger btn-remove" type="button">
<i class="fas fa-minus"></i>
</button>
</span>
</div>
</template>
<template id="template-empty-member">
<div class="entry input-group">
<input class="form-control" name="member" type="text"/>
<button class="btn btn-success btn-add" type="button">
<i class="fas fa-plus"></i>
</button>
</span>
</div>
</template>
<script src="scripts/defaults.js"></script>
<script src="scripts/scripts.js"></script>
......
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