Skip to content

Commit 5056e58

Browse files
committed
JS create new Employee implemented
1 parent 5758048 commit 5056e58

File tree

8 files changed

+60
-25
lines changed

8 files changed

+60
-25
lines changed

src/main/java/com/itacademy/CrudEmpleats/controller/ControllerEmployees.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ void start(HttpServletResponse reponse) throws IOException {
3131
// Crear nou empleat
3232
@PostMapping( "/EmpleatList")
3333
@ResponseStatus(HttpStatus.CREATED) // 201
34-
public Employee addEmployee(@RequestBody Employee employee) {
34+
public void addEmployee(@RequestBody Employee employee) {
3535
repositori.addEmployee(employee);
36-
return employee;
36+
3737
}
3838

3939
// Retorna una llista JSon d'empleats

src/main/java/com/itacademy/CrudEmpleats/controller/ControllerWeb.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ public class ControllerWeb {
99
* Controlador d'accés html
1010
*/
1111

12+
1213
@GetMapping("/index")
1314
public String goIndex() {
1415
return "index";
1516
}
16-
17-
@GetMapping("/BodyHeader")
17+
18+
@GetMapping("/ModificarEmpleat")
1819
public String bodyHeader() {
19-
return "BodyHeader";
20+
return "ModificarEmpleat";
2021
}
2122

2223
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
2-
spring.mvc.static-path-pattern=/content/**

src/main/resources/static/index.css

Whitespace-only changes.

src/main/resources/static/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
$(document).ready(function () {
3+
$('#newEmployee').submit(function (evento) {
4+
$.ajax({
5+
url: '/EmpleatList',
6+
type: 'POST',
7+
data: JSON.stringify({
8+
"name": $('#name').val(),
9+
"job": $('#job').val()
10+
}),
11+
processData: false,
12+
contentType: "application/json"
13+
})
14+
evento.preventDefault();
15+
});
16+
});

src/main/resources/templates/Jquery.html

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main/resources/templates/ModificarEmpleat.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
<div>
1010
<H4>Modificar empleat</H4>
1111
</div>
12-
<div>
1312
<div class="container">
14-
<div th:insert="Fragments/BodyHeader :: div"></div>
1513
<form action="/" method="post">
1614
#: <input type="text" name=id>
1715
Nom: <input type=text name=name>

src/main/resources/templates/index.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
<!DOCTYPE html>
22
<html>
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>Spring - Crud Empleats</title>
7+
8+
<!--Libreria Jquery carcada des de CDN-->
9+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
10+
611
</head>
12+
713
<body>
814
<div class="container"></div>
915
<div>
@@ -34,5 +40,37 @@ <H4>Empleats</H4><button type="submit">Nou Empleat</button>
3440
</table>
3541
</div>
3642
</div>
43+
<div class="container"></div>
44+
<div>
45+
<H4>Crear Empleat</H4>
46+
</div>
47+
<div>
48+
<div class="container">
49+
<div></div>
50+
<form id="newEmployee" action="#" method="post">
51+
<div>
52+
Nom: <input type=text name=name id="name">
53+
</div>
54+
<div>
55+
Càrreg:
56+
<select name="job" id="job">
57+
<option value="Default">Escull un càrreg</option>
58+
<option value="Director_Projectes">Director de projectes</option>
59+
<option value="Programador_Senior">Programador Senior</option>
60+
<option value="Programador_Mid">Programador Mid-Level</option>
61+
<option value="Programador_Junior">Programador Junior</option>
62+
<option value="Administrativa">Administrativa</option>
63+
</select>
64+
</div>
65+
<div>
66+
<br><br>
67+
<input type=submit name="submit" value="Afegir">
68+
<input type=reset value="Cancellar">
69+
</div>
70+
</form>
71+
</div>
72+
</div>
73+
<script type="text/javascript" src="index.js"></script>
3774
</body>
75+
3876
</html>

0 commit comments

Comments
 (0)