devices deletion and fix bugs
This commit is contained in:
parent
2a227043eb
commit
c6b92f06e0
27
server.js
27
server.js
@ -2592,6 +2592,33 @@ app.post("/deletedriver", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/deletedevice", async (req, res) => {
|
||||
if (req.session.userId === undefined) {
|
||||
return res.redirect("/signin");
|
||||
}
|
||||
const id = req.body.id;
|
||||
|
||||
const pool = new Pool({
|
||||
user: DB_User,
|
||||
host: DB_Host,
|
||||
database: DB_Name,
|
||||
password: DB_Password,
|
||||
port: DB_Port,
|
||||
});
|
||||
const client = await pool.connect();
|
||||
|
||||
try {
|
||||
// Выполняем запрос и получаем результат
|
||||
const query = "DELETE FROM registrars WHERE id = $1;";
|
||||
const devicedata = await client.query(query, [id]);
|
||||
|
||||
// Формирование и отправка ответа
|
||||
res.send("Data deleted successfully");
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/deleteuser", async (req, res) => {
|
||||
if (req.session.userId === undefined) {
|
||||
return res.redirect("/signin");
|
||||
|
@ -83,6 +83,7 @@ const createTable = () => {
|
||||
trashButton.setAttribute("class", "trash");
|
||||
trashButton.value = `delete-device-${device.id}`;
|
||||
trashButton.id = `delete-device-${device.id}`;
|
||||
trashButton.setAttribute("onclick", `deleteDevice(${device.id})`);
|
||||
trashCell.appendChild(trashButton);
|
||||
}
|
||||
if (EditTransport) {
|
||||
|
@ -684,6 +684,7 @@ header img {
|
||||
border: 2px solid rgba(245, 245, 250, 1);
|
||||
border-radius: 30px;
|
||||
overflow: hidden;
|
||||
overflow-x: auto;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@
|
||||
<h1>Удаление водителя </h1> <br>
|
||||
<span>Вы уверены что хотите удалить <span id="driverDeleteInfo"></span>?</span>
|
||||
<div class="buttons">
|
||||
<button id="deleteCancel" onclick="closeDeletion();" style="display: inline-block; background-color: white; color: rgba(0, 0, 0, 0.7); margin-right: 5px;" type="button" onclick="deleteDriver()">Отменить</button>
|
||||
<button id="deleteCancel" onclick="closeDeletion();" style="display: inline-block; background-color: white; color: rgba(0, 0, 0, 0.7); margin-right: 5px;" type="button">Отменить</button>
|
||||
<button id="deleteDriver" style="display: inline-block;" type="button">Подтвердить</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -126,7 +126,7 @@
|
||||
<th>Номер телефона</th>
|
||||
<th>Почта</th>
|
||||
<th>Карта водителя</th>
|
||||
<th><button id="delete-device-all" value="delete-device-all" class="trash"></button></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -130,9 +130,7 @@
|
||||
<th>Статус</th>
|
||||
<th>Номер SIM-карты</th>
|
||||
<th>IP-адрес</th>
|
||||
<th>{{#if DeleteTransport}}
|
||||
<button id="delete-device-all" value="delete-device-all" class="trash"></button>
|
||||
{{/if}}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -657,6 +655,18 @@
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section style="display: none;" class="dberror" id="deleteConfirmation">
|
||||
<div class="erorr-container">
|
||||
<img src="../img/warning.svg"> <br>
|
||||
<h1>Удаление устройства </h1> <br>
|
||||
<span>Вы уверены что хотите удалить <span id="deviceDeleteInfo"></span>?</span>
|
||||
<div class="buttons">
|
||||
<button id="deleteCancel" onclick="closeDeletion();" style="display: inline-block; background-color: white; color: rgba(0, 0, 0, 0.7); margin-right: 5px;" type="button">Отменить</button>
|
||||
<button id="deleteDevice" style="display: inline-block;" type="button" onclick="deleteDevice()">Подтвердить</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
const devices = [
|
||||
{{#each Registrars}}
|
||||
@ -1054,6 +1064,56 @@
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
function deleteDevice(id) {
|
||||
|
||||
var deleteConfirmation = $("#deleteConfirmation");
|
||||
|
||||
$.ajax({
|
||||
url: "/devicedata",
|
||||
method: "POST",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify({ id: id }),
|
||||
success: function(response) {
|
||||
// Установка значений полей формы
|
||||
$("#deviceDeleteInfo").html(response.serial);
|
||||
document.getElementById('deleteDevice').setAttribute("onclick", `confirmDelete(${response.id})`);
|
||||
|
||||
|
||||
document.getElementById('deleteConfirmation').style.display = "flex";
|
||||
|
||||
$("body").css("overflow", "hidden");
|
||||
},
|
||||
error: function() {
|
||||
// Обработка ошибки при запросе к серверу
|
||||
alert("Произошла ошибка при запросе к серверу.");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function closeDeletion() {
|
||||
document.getElementById('deleteConfirmation').style.display = "none";
|
||||
}
|
||||
|
||||
function confirmDelete(id) {
|
||||
$.ajax({
|
||||
url: "/deletedevice",
|
||||
method: "POST",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify({ id: id }),
|
||||
success: function(response) {
|
||||
location.reload();
|
||||
},
|
||||
error: function() {
|
||||
// Обработка ошибки при запросе к серверу
|
||||
alert("Произошла ошибка при запросе к серверу.");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// Скрытие/Показ дополнительных меню аккаунта
|
||||
const accountMain = document.getElementById('account-main');
|
||||
|
@ -122,7 +122,7 @@
|
||||
<th>Серийный номер</th>
|
||||
<th>Время</th>
|
||||
<th>Местоположение</th>
|
||||
<th><button id="share-device-all" value="share-device-all" class="share" onclick="location.href = '/reports/346';"></button></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
Loading…
Reference in New Issue
Block a user