-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
118 lines (91 loc) · 3.59 KB
/
main.js
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
var item_musica = function (id, nome, datalancamento, duracao, cantor, genero, imagem) {
var html = `<div id='musica_${id}' class='col-md-3'>`;
html += " <div class='card' style='width: 18rem;'>";
html += ` <img src="./cd_cover.png" class="card-img-top" alt="...">`;
html += ` <div class="card-body">`;
html += ` <h5 class="card-title">${nome}</h5>`;
html += ` <p class="card-text">Cantor: ${cantor}</p>`;
html += ` <p class="card-text">Gênero: ${genero}</p>`;
html += ` <p class="card-text">Data Lançamento: ${datalancamento}</p>`;
html += ` <p class="card-text">Duração: ${duracao} segundos</p>`;
html += ` <button type="button" onclick="delete_musica(${id})" class="btn btn-danger">Apagar</button>`;
html += ` </div>`;
html += ` </div>`;
html += ` </div>`;
return html;
}
var item_genero = function (id, nome) {
var html = `<tr id="genero_${id}">`;
html += ` <th scope='row'>${id}</th>`;
html += ` <td>${nome}</td>`;
html += ` <td><button type="button" onclick="delete_genero(${id})" class="btn btn-danger">Apagar</button></td>`;
html += ` </tr>`;
return html;
}
var item_cantor = function (id, nome) {
var html = `<tr id="cantor_${id}">`;
html += ` <th scope='row'>${id}</th>`;
html += ` <td>${nome}</td>`;
html += ` <td><button type="button" onclick="delete_cantor(${id})" class="btn btn-danger">Apagar</button></td>`;
html += ` </tr>`;
return html;
}
function delete_musica(id) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var dado = JSON.parse(xhr.responseText);
if (dado == 1) {
document.getElementById('musica_' + id).remove();
}
else {
alert('erro ao deletar item');
}
}
};
xhr.open('GET', 'musica.php?acao=excluir_musicas&id=' + id);
xhr.send();
}
function delete_genero(id) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var dado = JSON.parse(xhr.responseText);
if (dado == 1) {
document.getElementById('genero_' + id).remove();
}
else {
alert('erro ao deletar item');
}
}
};
xhr.open('GET', 'genero.php?acao=excluir_generos&id=' + id);
xhr.send();
}
function delete_cantor(id) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var dado = JSON.parse(xhr.responseText);
if (dado == 1) {
document.getElementById('cantor_' + id).remove();
}
else {
alert('erro ao deletar item');
}
}
};
xhr.open('GET', 'cantor.php?acao=excluir_cantor&id=' + id);
xhr.send();
}
function EnviarProduto() {
const nome = $('#nome')[0].value;
const imagem = $('#imagem')[0].value;
const descricao = $('#descricao')[0].value;
const preco = $('#preco')[0].value;
if (nome === '' || imagem === '' || descricao === '' || preco === '') {
alert('favor preencher todos os campos!!');
return;
}
xhr.open('GET', 'service.php?acao=inserir_produtos&id=' + id);
}