diff --git a/src/main/webapp/js/requests.js b/src/main/webapp/js/requests.js index 1e5b0ca9c3315edd61a07211f5b7f027af22f9c0..1ec5dc2ab3f276e6ff1566fac4a85468413e7aa5 100644 --- a/src/main/webapp/js/requests.js +++ b/src/main/webapp/js/requests.js @@ -146,3 +146,40 @@ function deletePokemonType() { }); } +function updatePokemonType() { + let idPokemon = document.getElementById("idUpdate").value; + let nameUpdate = document.getElementById("nameUpdate").value; + let imgUrlUpdate = document.getElementById("url").value; + let pokedexNumberUpdate = document.getElementById("pokedex").value; + let primaryTypeUpdate = document.getElementById("primary").value; + let secondaryTypeUpdate = document.getElementById("secondary").value; + + const data = { + id: idPokemon, + name: nameUpdate, + imgUrl: imgUrlUpdate, + pokedexNumber: pokedexNumberUpdate, + primaryType: primaryTypeUpdate, + secondaryType: secondaryTypeUpdate + // Add other fields as needed + }; + + fetch(`/pokemon/api/pokemonTypes/${idPokemon}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(data) + }).then(response => { + if(response.ok) { + updatePokemonTypesTable(); + updateDetails(idPokemon); + } else { + console.error('Failed to update Pokemon type:', response.status); + } + }).catch(error => { + console.error('Error updating Pokemon type:', error); + }); +} + + diff --git a/src/main/webapp/pokemonTypes.html b/src/main/webapp/pokemonTypes.html index 7e5cd0fcbc4468eac87b2548a49e9fe3d3b68bca..2e4b8bf31cebeea23907a6577d820b153c2f6495 100644 --- a/src/main/webapp/pokemonTypes.html +++ b/src/main/webapp/pokemonTypes.html @@ -133,6 +133,39 @@ <br> <br> + <h4>Update Pokemon type</h4> + + <form id = "updatePokemonType" onsubmit = "updatePokemonType()"> + <div class = "form-group"> + <label for = "idUpdate">Pokemon ID</label> + <input type = "text" class = "form-control" id = "idUpdate"> + </div> + <div class = "form-group"> + <label for = "nameUpdate">Name</label> + <input type = "text" class = "form-control" id = "nameUpdate"> + </div> + <div class = "form-group"> + <label for = "url">Url</label> + <input type = "text" class = "form-control" id = "url"> + </div> + <div class = "form-group"> + <label for = "pokedex">Pokedex Number</label> + <input type = "text" class = "form-control" id = "pokedex"> + </div> + <div class = "form-group"> + <label for = "primary">Primary type</label> + <input type = "text" class = "form-control" id = "primary"> + </div> + <div class = "form-group"> + <label for = "secondary">Secondary type</label> + <input type = "text" class = "form-control" id = "secondary"> + </div> + <button type = "submit" class = "btn btn-primary">Update Pokemon type</button> + </form> + + <br> + <br> + <div class="container"> <div class="row"> <div id="tableDiv" class="col-8">No data</div>