Es. 8+ fixes
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Creazione Utente</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<a href="../index.html" style="position: absolute; top: 20px; left: 20px; text-decoration: none; color: #555; font-weight: bold; font-size: 14px;">← Dashboard</a>
|
||||
|
||||
<form id="profile-form" class="profile-form">
|
||||
<h1>Crea un utente</h1>
|
||||
<div class="form-group">
|
||||
<label for="nome">Nome Completo:</label>
|
||||
<input type="text" id="nome" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="eta">Età:</label>
|
||||
<input type="number" id="eta" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="bio">Biografia:</label>
|
||||
<textarea id="bio" rows="4" required></textarea>
|
||||
</div>
|
||||
<button id="btn-crea-card">Crea Profilo</button>
|
||||
</form>
|
||||
|
||||
<ul class="all-cards" id="cards-container">
|
||||
<!-- Le card create appariranno qui -->
|
||||
</ul>
|
||||
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
* ESERCIZIO 1: Recupera i valori dagli input
|
||||
* Selezioniamo i seguenti elementi dal DOM: `nome`, `eta`, `bio`, `cards-container` e `btn-crea-card`
|
||||
*/
|
||||
const inputNome = document.querySelector('');
|
||||
const inputEta = document.querySelector('');
|
||||
const inputBio = document.querySelector('');
|
||||
const contenitoreCard = document.querySelector('');
|
||||
const btnCreaCard = document.querySelector('');
|
||||
|
||||
|
||||
/**
|
||||
* FUNZIONE: cancella dati input
|
||||
* Passi:
|
||||
* 1. Imposta il valore di ogni input a stringa vuota
|
||||
*/
|
||||
function cancellaDatiInput() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* FUNZIONE: crea la card profilo
|
||||
* Passi:
|
||||
* 1. Crea un nuovo elemento <li> con document.createElement('li')
|
||||
* 2. Impostane la classe CSS a 'card'
|
||||
* 3. Crea un H3 con il valore nome
|
||||
* 4. Crea un paragrafo con il valore dell'età
|
||||
* 5. Crea un paragrafo con il valore della biografia
|
||||
* 6. Aggiungi tutti gli elementi alla card nell'ordine indicato
|
||||
* 7. Aggiungi la card al cardsContainer
|
||||
*/
|
||||
function creaCardProfilo() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* FUNZIONE: Event Listener sul bottone
|
||||
* Mettiamo tutto quello che abbiamo fatto insieme in un event listener
|
||||
* Passi:
|
||||
* 1. Previeni il comportamento di default dell'evento
|
||||
* 2. Chiama creaCardProfilo() con i dati
|
||||
* 3. Pulisci gli input con cancellaDatiInput()
|
||||
*/
|
||||
btnCreaCard.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
creaCardProfilo();
|
||||
cancellaDatiInput();
|
||||
});
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* Stesso font dashboard */
|
||||
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); /* Stesso sfondo dashboard */
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
form {
|
||||
background: #ecf0f1;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 90%;
|
||||
padding: 8px;
|
||||
border: 1px solid #bdc3c7;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #3498db;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
button:hover {
|
||||
background: #2980b9;
|
||||
}
|
||||
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
||||
width: 190px;
|
||||
text-align: center;
|
||||
transition: transform 0.1s ease-in-out, box-shadow 0.1s ease-in-out;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.card > * {
|
||||
margin: 10px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.card h3 {
|
||||
background: linear-gradient(to right, #667eea, #764ba2);
|
||||
color: white;
|
||||
padding: 30px 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.card p {
|
||||
font-size: 0.9rem;
|
||||
color: #34495e;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Gestione Utenti</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<a href="../index.html" style="position: absolute; top: 20px; left: 20px; text-decoration: none; color: #555; font-weight: bold; font-size: 14px;">← Dashboard</a>
|
||||
|
||||
<div class="container">
|
||||
<form id="profile-form" class="profile-form">
|
||||
<h1>Aggiungi un Utente</h1>
|
||||
<div class="form-group">
|
||||
<label for="nome">Nome Completo:</label>
|
||||
<input type="text" id="nome" placeholder="Es. Marco Rossi" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="eta">Età:</label>
|
||||
<input type="number" id="eta" placeholder="Es. 25" min="1" max="120" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="professione">Professione:</label>
|
||||
<input type="text" id="professione" placeholder="Es. Sviluppatore" required>
|
||||
</div>
|
||||
<button type="button" id="btn-crea-card" class="btn-primary">+ Aggiungi Utente</button>
|
||||
</form>
|
||||
|
||||
<div class="table-wrapper">
|
||||
<h2>Utenti Registrati</h2>
|
||||
<table id="users-table" class="users-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nome</th>
|
||||
<th>Età</th>
|
||||
<th>Professione</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="tbody">
|
||||
<!-- Le righe verranno inserite qui -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
58
javascript/JS_Esercizi 08 - DOM+/02_tabella_utenti/script.js
Normal file
58
javascript/JS_Esercizi 08 - DOM+/02_tabella_utenti/script.js
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* ESERCIZIO 2: Tabella Utenti Interattiva
|
||||
* Selezionare gli elementi principali dal DOM
|
||||
*/
|
||||
const inputNome = document.querySelector('');
|
||||
const inputEta = document.querySelector('');
|
||||
const inputProfessione = document.querySelector('');
|
||||
const btnCreaUtente = document.querySelector('');
|
||||
const tbodyUtenti = document.querySelector('');
|
||||
|
||||
/**
|
||||
* EVENTO: Clic sul pulsante "Aggiungi Utente"
|
||||
*
|
||||
* Completa la funzione: Manca qualcosa?
|
||||
*
|
||||
* Passi:
|
||||
* 1. Prevenire il comportamento di default del form
|
||||
* 2. Leggere i valori dagli input
|
||||
* 3. Se i dati non sono vuoti:
|
||||
* - Chiamare creaRigaUtente(nome, eta, professione), passando i dati letti dagli input
|
||||
* - Chiamare cancellaDatiInput() per pulire i campi
|
||||
*/
|
||||
|
||||
btnCreaUtente.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const nome = inputNome.value;
|
||||
const eta = inputEta.value;
|
||||
const professione = inputProfessione.value;
|
||||
|
||||
creaRigaUtente(nome, eta, professione);
|
||||
cancellaDatiInput();
|
||||
});
|
||||
|
||||
/**
|
||||
* FUNZIONE: Crea una riga della tabella con i dati dell'utente
|
||||
*
|
||||
* Passi:
|
||||
* 1. Creare un elemento <tr> (classe "user-row")
|
||||
* 2. Creare tre elementi <td> per nome, età e professione
|
||||
* 3. Popolare i <td> con i dati passati dai parametri
|
||||
* 4. Aggiungere tutti i <td> al <tr>
|
||||
* 5. Aggiungere il <tr> nel <tbody> della tabella
|
||||
*/
|
||||
function creaRigaUtente(nome, eta, professione) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* FUNZIONE: Cancella i dati dagli input e rimette il focus sul primo campo
|
||||
*
|
||||
* Passi:
|
||||
* 1. Impostare il valore di inputNome a stringa vuota
|
||||
* 2. Impostare il valore di inputEta a stringa vuota
|
||||
* 3. Impostare il valore di inputProfessione a stringa vuota
|
||||
*/
|
||||
function cancellaDatiInput() {
|
||||
}
|
||||
223
javascript/JS_Esercizi 08 - DOM+/02_tabella_utenti/style.css
Normal file
223
javascript/JS_Esercizi 08 - DOM+/02_tabella_utenti/style.css
Normal file
@@ -0,0 +1,223 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 700px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════ */
|
||||
/* FORM STYLES */
|
||||
/* ═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
.profile-form {
|
||||
margin-bottom: 40px;
|
||||
padding-bottom: 30px;
|
||||
border-bottom: 2px solid #ecf0f1;
|
||||
}
|
||||
|
||||
.profile-form h1 {
|
||||
color: #2c3e50;
|
||||
margin-top: 0;
|
||||
margin-bottom: 25px;
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 18px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
color: #34495e;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.form-group input,
|
||||
.form-group textarea {
|
||||
padding: 12px 15px;
|
||||
border: 2px solid #ecf0f1;
|
||||
border-radius: 6px;
|
||||
font-family: inherit;
|
||||
font-size: 1rem;
|
||||
transition: border-color 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
.form-group input:focus,
|
||||
.form-group textarea:focus {
|
||||
outline: none;
|
||||
border-color: #3498db;
|
||||
box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
|
||||
}
|
||||
|
||||
.form-group textarea {
|
||||
resize: vertical;
|
||||
min-height: 80px;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 14px 32px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
font-size: 1rem;
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
align-self: flex-start;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.btn-primary:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════ */
|
||||
/* TABLE STYLES */
|
||||
/* ═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
.table-wrapper h2 {
|
||||
color: #2c3e50;
|
||||
margin: 0 0 20px 0;
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.empty-message {
|
||||
text-align: center;
|
||||
color: #7f8c8d;
|
||||
font-style: italic;
|
||||
padding: 30px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
border-left: 4px solid #3498db;
|
||||
}
|
||||
|
||||
.empty-message.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.users-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.users-table thead {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.users-table thead th {
|
||||
padding: 16px;
|
||||
text-align: left;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.5px;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.users-table tbody tr {
|
||||
border-bottom: 1px solid #ecf0f1;
|
||||
transition: background-color 0.2s ease, transform 0.2s ease;
|
||||
animation: slideIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.users-table tbody tr:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.users-table tbody td {
|
||||
padding: 16px;
|
||||
color: #34495e;
|
||||
word-break: break-word;
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
.users-table tbody td:first-child {
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
.users-table tbody td.azioni {
|
||||
text-align: center;
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════ */
|
||||
/* BUTTON STYLES */
|
||||
/* ═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
.btn-elimina {
|
||||
background: #e74c3c;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 14px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
font-size: 0.85rem;
|
||||
transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
|
||||
.btn-elimina:hover {
|
||||
background: #c0392b;
|
||||
transform: scale(1.1);
|
||||
box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
|
||||
}
|
||||
|
||||
.btn-elimina:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════ */
|
||||
/* RESPONSIVE */
|
||||
/* ═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.users-table tbody th,
|
||||
.users-table tbody td {
|
||||
padding: 12px 8px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.profile-form {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -25,10 +25,15 @@ const divTotale = document.querySelector('');
|
||||
* Questa funzione è il "motore" grafico. Deve:
|
||||
* 1. Pulire la lista attuale nel DOM (per evitare duplicati)
|
||||
* 2. Ciclare l'array 'lista'
|
||||
* 3. Per ogni elemento, chiamare la funzione 'creaElementoLista'
|
||||
* 3. Per ogni elemento, chiamare la funzione 'creaRigaElemento'
|
||||
* 4. Chiamare la funzione 'aggiornaTotale' alla fine per calcolare il conto
|
||||
*/
|
||||
function aggiornaLista() {
|
||||
ulSpesa.innerHTML = '';
|
||||
lista.forEach(elemento => {
|
||||
creaRigaElemento(elemento);
|
||||
});
|
||||
aggiornaTotale();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,9 +48,9 @@ function aggiornaLista() {
|
||||
* - Invertire la proprietà .sbarrato dell'oggetto (true/false)
|
||||
* - Aggiornare la classe CSS 'preso' sull'li (toggle)
|
||||
* - Aggiornare il totale chiamando aggiornaTotale()
|
||||
* 5. Appendere l'li alla ulSpesa (ul)
|
||||
* 5. Aggiungere l'li al <ul> della lista
|
||||
*/
|
||||
function creaElementoLista(elemento) {
|
||||
function creaRigaElemento(elemento) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -194,11 +194,11 @@
|
||||
</div>
|
||||
</a>
|
||||
|
||||
<a href="02_card_profilo/index.html" class="card">
|
||||
<div class="icon">🆕</div>
|
||||
<a href="02_tabella_utenti/index.html" class="card">
|
||||
<div class="icon">📊</div>
|
||||
<div class="info">
|
||||
<h3>Creazione Card Utente <span class="difficulty easy">Facile</span></h3>
|
||||
<p>Form, createElement, appendChild</p>
|
||||
<h3>Tabella Utenti <span class="difficulty easy">Facile</span></h3>
|
||||
<p>Form, append Child, Tabella dinamica</p>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user