1 | <!DOCTYPE html> |
2 | <html lang="es"> |
3 | |
4 | <head> |
5 | |
6 | <meta charset="UTF-8"> |
7 | <meta name="viewport" content="width=device-width"> |
8 | |
9 | <title>Modificar</title> |
10 | |
11 | <script type="module" src="js/configura.js"></script> |
12 | <script type="module" src="lib/js/muestraError.js"></script> |
13 | <script type="module" src="lib/js/muestraObjeto.js"></script> |
14 | <script type="module" src="js/bd/pasatiempoBusca.js"></script> |
15 | <script type="module" src="js/bd/pasatiempoElimina.js"></script> |
16 | <script type="module" src="js/bd/pasatiempoModifica.js"></script> |
17 | |
18 | <script> |
19 | |
20 | |
21 | const parametros = new URL(location.href).searchParams |
22 | |
23 | const paramId = parametros.get("id") |
24 | |
25 | </script> |
26 | |
27 | </head> |
28 | |
29 | <body onload="if (paramId !== null) { |
30 | pasatiempoBusca(paramId) |
31 | .then(pasatiempo => { |
32 | if (pasatiempo === undefined) throw new Error('Pasatiempo no encontrado.') |
33 | muestraObjeto(forma, { nombre: { value: pasatiempo.PAS_NOMBRE } }) |
34 | }) |
35 | .catch(muestraError) |
36 | }"> |
37 | |
38 | <form id="forma" onsubmit=" |
39 | event.preventDefault() |
40 | if (paramId !== null) { |
41 | const PAS_ID = paramId |
42 | // Lee el nombre, quitándole los espacios al inicio y al final. |
43 | const PAS_NOMBRE = forma.nombre.value.trim() |
44 | const modelo = { PAS_ID, PAS_NOMBRE } |
45 | pasatiempoModifica(modelo) |
46 | .then(json => location.href = 'index.html') |
47 | .catch(muestraError) |
48 | }"> |
49 | |
50 | <h1>Modificar</h1> |
51 | |
52 | <p><a href="index.html">Cancelar</a></p> |
53 | |
54 | <p> |
55 | <label> |
56 | Nombre * |
57 | <input name="nombre" value="Cargando…"> |
58 | </label> |
59 | </p> |
60 | |
61 | <p>* Obligatorio</p> |
62 | |
63 | <p> |
64 | |
65 | <button type="submit">Guardar</button> |
66 | |
67 | <button type="button" onclick=" |
68 | if (paramId !== null && confirm('Confirma la eliminación')) { |
69 | pasatiempoElimina(paramId) |
70 | .then(() => location.href = 'index.html') |
71 | .catch(muestraError) |
72 | }"> |
73 | Eliminar |
74 | </button> |
75 | |
76 | </p> |
77 | |
78 | </form> |
79 | |
80 | </body> |
81 | |
82 | </html> |