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="lib/js/consumeJson.js"></script> |
12 | <script type="module" src="lib/js/submitForm.js"></script> |
13 | <script type="module" src="lib/js/muestraError.js"></script> |
14 | <script type="module" src="lib/js/muestraObjeto.js"></script> |
15 | <script type="module" src="lib/js/muestraImagenSeleccionada.js"></script> |
16 | |
17 | <script> |
18 | |
19 | const params = new URL(location.href).searchParams |
20 | </script> |
21 | |
22 | </head> |
23 | |
24 | <body onload="if (params.size > 0) { |
25 | consumeJson('srv/producto.php?' + params) |
26 | .then(modelo => muestraObjeto(document, modelo.body)) |
27 | .catch(muestraError) |
28 | }"> |
29 | |
30 | <form onsubmit="submitForm('srv/producto-modifica.php', event) |
31 | .then(modelo => location.href = 'index.html') |
32 | .catch(muestraError)"> |
33 | |
34 | <h1>Modificar</h1> |
35 | |
36 | <p><a href="index.html">Cancelar</a></p> |
37 | |
38 | <input type="hidden" name="id"> |
39 | |
40 | <p> |
41 | <label> |
42 | Nombre * |
43 | <input name="nombre" value="Cargando…"> |
44 | </label> |
45 | </p> |
46 | |
47 | <p> |
48 | <label> |
49 | Imagen |
50 | <input name="imagen" type="file" accept="image/*" data-img="preview" |
51 | oninput="muestraImagenSeleccionada(document, this).catch(muestraError)"> |
52 | </label> |
53 | </p> |
54 | |
55 | <p>* Obligatorio</p> |
56 | |
57 | <p> |
58 | |
59 | <button type="submit">Guardar</button> |
60 | |
61 | <button type="button" onclick=" |
62 | if (params.size > 0 && confirm('Confirma la eliminación')) { |
63 | consumeJson('srv/producto-elimina.php?' + params) |
64 | .then(() => location.href = 'index.html') |
65 | .catch(muestraError) |
66 | }"> |
67 | Eliminar |
68 | </button> |
69 | |
70 | </p> |
71 | |
72 | <figure> |
73 | <img id="preview" hidden alt="Imagen del producto" style="max-width: 100%;"> |
74 | </figure> |
75 | |
76 | </form> |
77 | |
78 | </body> |
79 | |
80 | </html> |