diff --git a/src/main/webapp/js/requests.js b/src/main/webapp/js/requests.js index 7eeb896c2e1c56492e20983bee3a2b05fa5c1e63..a8cb2e7e3c0e054c32fea0ea48556ea683d11b12 100644 --- a/src/main/webapp/js/requests.js +++ b/src/main/webapp/js/requests.js @@ -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); + }); +} diff --git a/src/main/webapp/pokemonTypes.html b/src/main/webapp/pokemonTypes.html index edadf379312e63ca3a916d603990cceeae399a0f..7f1012e25a6f211edf9da4e9e9c88d6b9555cf06 100644 --- a/src/main/webapp/pokemonTypes.html +++ b/src/main/webapp/pokemonTypes.html @@ -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> diff --git a/src/main/webapp/trainers.html b/src/main/webapp/trainers.html index 779939cc3f1241172be33a3e1d6308b00798fbf3..1c87d6797d048faf6e38ec5be3bd01667308799d 100644 --- a/src/main/webapp/trainers.html +++ b/src/main/webapp/trainers.html @@ -1,5 +1,6 @@ <!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