Skip to content
Snippets Groups Projects
Commit 98a40e35 authored by Botea, R. (Raul, Student B-TCS)'s avatar Botea, R. (Raul, Student B-TCS)
Browse files

Issue 1 solved, Trainers.

parent d1364dc5
Branches issue#1
No related tags found
No related merge requests found
......@@ -86,7 +86,7 @@ function updateTrainerDetails(trainerId) {
function trainersTypeToRow(trainerTypes) {
return `
<tr id="${getRowId(trainerTypes)}" onclick="updateDetails('${trainerTypes?.id?.trim()}')">
<tr id="${getRowId(trainerTypes)}" onclick="updateTrainerDetails('${trainerTypes?.id?.trim()}')">
<th scope="row">${trainerTypes.id}</th>
<td>${trainerTypes.name}</td>
<td>#${trainerTypes.created}</td>
......@@ -117,4 +117,23 @@ function createTrainersTypesTable() {
</tbody>
</table>
`
}
\ No newline at end of file
}
function addNewCharacter(charName, charId) {
fetch(`/pokemon/api/trainers/${charId}`, {
method: "PUT",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ name: charName }) // Assuming you want to send the character name in the request body
})
.then(response => {
if (!response.ok) {
throw new Error("Failed to add new character");
}
// Handle success response here if needed
})
.catch(error => {
console.error("Error:", error);
});
}
......@@ -31,7 +31,7 @@
});
</script>
<h1>Trainers</h1>
<h1>Go to trainers</h1>
<button onclick="window.location.href = 'http://localhost:8080/pokemon/trainers.html'">Go to Pokemon Page</button>
<h1>Pokemon Types</h1>
......
<!DOCTYPE html>
<html lang="en">
<html lang="en"
xmlns:CName="http://www.w3.org/1999/xhtml">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
......@@ -30,7 +31,7 @@
console.error(err);
});
</script>
<h1>Main page</h1>
<h1>Go to main page</h1>
<button onclick="window.location.href = 'http://localhost:8080/pokemon/'">Go to Pokemon Page</button>
<h1>Trainers </h1>
......@@ -42,5 +43,13 @@
</div>
</div>
<h1>Add a new trainer</h1>
<form>
<label for="charName">CName:</label>
<input type="text" id="charName" name="charName"><br><br>
<label for="charId">ID:</label>
<input type="text" id ="charId" name="charId"> <br><br>
<button onclick=addNewCharacter(charName,charId)> Add the new trainer today, at no cost!</button>
</form>
</body>
</html>
\ No newline at end of file
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