-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
migrate.php
93 lines (92 loc) · 3.42 KB
/
migrate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Criador de classes</title>
<link href="css/stylecriador.css" rel="stylesheet">
<link rel="stylesheet" href="css/sweetalert2.min.css">
</head>
<body>
<div id="app">
<div class="form-card">
<h1>Criador de classe</h1>
<form id="classForm">
<label for="className">Nome da Classe:</label>
<input type="text" id="className" name="className" required placeholder="Usuario"><br><br>
<label for="propertyCount">Quantidade de propriedades:</label>
<input type="number" id="propertyCount" name="propertyCount" min="1" required placeholder="3"><br><br>
<div class="toggle-container">
<label class="toggle-label">
Criar SPA:
<input type="checkbox" id="isSPA" name="isSPA" class="toggle-checkbox" checked >
<div class="toggle-switch"></div>
</label>
</div>
<div id="properties"></div>
<input type="submit" value="Criar Classe">
</form>
</div>
</div>
<script src="js/sweetalert2.all.min.js"></script>
<script>
document.getElementById('propertyCount').addEventListener('input', function(e) {
const count = e.target.value;
const propertiesDiv = document.getElementById('properties');
propertiesDiv.innerHTML = '';
propertiesDiv.innerHTML += `
<div class="property">
<label for="propName0">Nome da Propriedade:</label>
<input type="text" id="propName0" name="propName0" value="id" readonly>
<label for="propType0">Tipo:</label>
<select name="propType0" required>
<option value="int" readonly selected>int</option>
</select>
</div>
<br><br>
`;
for(let i = 1; i < count; i++) {
propertiesDiv.innerHTML += `
<div class="property">
<label for="propName${i}">Nome da Propriedade:</label>
<input type="text" id="propName${i}" name="propName${i}" required>
<label for="propType${i}">Tipo:</label>
<select name="propType${i}" required>
<option value="string">string</option>
<option value="int">int</option>
<option value="float">float</option>
<option value="datetime">datetime</option>
<option value="bool">bool</option>
</select>
</div>
<br><br>
`;
}
});
document.getElementById('classForm').addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(e.target);
formData.append('spa', document.getElementById('isSPA').checked);
formData.append('tipo',location.hash);
fetch('createClass.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
Swal.fire(
'Tudo criado com sucesso!',
'',
'success'
);
location.href = 'index.html'
})
.catch((error) => {
console.error('Error:', error);
alert('Erro ao criar classe!');
});
});
</script>
</body>
</html>