-
Notifications
You must be signed in to change notification settings - Fork 43
/
cadastroAlunos.html
213 lines (208 loc) · 6.85 KB
/
cadastroAlunos.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Sistema de Cadastros - Fatec Franca</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<style>
.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: table;
transition: opacity 0.3s ease;
}
.modal-wrapper {
display: table-cell;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="container" id="crudApp">
<br />
<h3 align="center">
<img src="https://site.fatecfranca.edu.br/images/logo-fatec-franca-15-anos.png" width=50% height=50%
alt="logo fatec"><br /><br />
<strong>Cadastro de Alunos</strong>
</h3>
<br />
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-md-6">
<h3 class="panel-title">Alunos</h3>
</div>
<div class="col-md-6" align="right">
<input type="button" class="btn btn-success btn-xs" @click="openModel" value="Add" />
</div>
</div>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-bordered table-striped">
<tr>
<th>Nome</th>
<th>Sobrenome</th>
<th>Editar</th>
<th>Deletar</th>
</tr>
<tr v-for="row in allData">
<td>{{ row.first_name }}</td>
<td>{{ row.last_name }}</td>
<td>
<button type="button" name="edit" class="btn btn-primary btn-xs edit" @click="fetchData(row.id)">
Editar
</button>
</td>
<td>
<button type="button" name="delete" class="btn btn-danger btn-xs delete" @click="deleteData(row.id)">
Deletar
</button>
</td>
</tr>
</table>
</div>
</div>
</div>
<div v-if="myModel">
<transition name="model">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" @click="myModel=false">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">{{ dynamicTitle }}</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label>Nome</label>
<input type="text" class="form-control" v-model="first_name" />
</div>
<div class="form-group">
<label>Sobrenome</label>
<input type="text" class="form-control" v-model="last_name" />
</div>
<br />
<div align="center">
<input type="hidden" v-model="hiddenId" />
<input type="button" class="btn btn-success btn-xs" v-model="actionButton" @click="submitData" />
</div>
</div>
</div>
</div>
</div>
</div>
</transition>
</div>
</div>
</body>
</html>
<script>
var application = new Vue({
el: "#crudApp",
data: {
allData: "",
myModel: false,
actionButton: "Insert",
dynamicTitle: "Adicionar Aluno",
},
methods: {
fetchAllData: function () {
axios
.post("cadastro.php", {
action: "fetchall",
})
.then(function (response) {
application.allData = response.data;
});
},
openModel: function () {
application.first_name = "";
application.last_name = "";
application.actionButton = "Insert";
application.dynamicTitle = "Adicionar Aluno";
application.myModel = true;
},
submitData: function () {
if (application.first_name != "" && application.last_name != "") {
if (application.actionButton == "Insert") {
axios
.post("cadastro.php", {
action: "insert",
firstName: application.first_name,
lastName: application.last_name,
})
.then(function (response) {
application.myModel = false;
application.fetchAllData();
application.first_name = "";
application.last_name = "";
alert(response.data.message);
});
}
if (application.actionButton == "Update") {
axios
.post("cadastro.php", {
action: "update",
firstName: application.first_name,
lastName: application.last_name,
hiddenId: application.hiddenId,
})
.then(function (response) {
application.myModel = false;
application.fetchAllData();
application.first_name = "";
application.last_name = "";
application.hiddenId = "";
alert(response.data.message);
});
}
} else {
alert("Complete todos os dados!!!");
}
},
fetchData: function (id) {
axios
.post("cadastro.php", {
action: "fetchSingle",
id: id,
})
.then(function (response) {
application.first_name = response.data.first_name;
application.last_name = response.data.last_name;
application.hiddenId = response.data.id;
application.myModel = true;
application.actionButton = "Update";
application.dynamicTitle = "Edit Data";
});
},
deleteData: function (id) {
if (confirm("Você tem certeza que deseja deletar esse aluno?")) {
axios
.post("cadastro.php", {
action: "delete",
id: id,
})
.then(function (response) {
application.fetchAllData();
alert(response.data.message);
});
}
},
},
created: function () {
this.fetchAllData();
},
});
</script>