Rename functions for clarity

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2023-10-26 00:11:15 +02:00
parent 7595ceb17f
commit b84683e1a9

View File

@@ -61,7 +61,7 @@ $(function () {
},
],
drawCallback: function () {
$('button[id^="deleteSession_"]').on("click", deleteSession);
$('button[id^="deleteSession_"]').on("click", deleteThisSession);
// Hide buttons if all messages were deleted
var hasRows = this.api().rows({ filter: "applied" }).data().length > 0;
@@ -149,7 +149,7 @@ $(function () {
ids.push(parseInt($(this).attr("data-id"), 10));
});
// Delete all selected rows at once
delSessions(ids);
deleteMultipleSessions(ids);
},
},
],
@@ -187,13 +187,18 @@ $(function () {
});
});
function deleteSession() {
// Passes the button data-del-id attribute as ID
var ids = [$(this).attr("data-del-id")];
delSessions(ids);
function deleteThisSession() {
// This function is called when a red trash button is clicked
// We get the ID of the current item from the data-del-id attribute
const thisID = parseInt(this.attr("data-del-id"), 10);
deleted = 0;
deleteOneSession(thisID, 1, false);
}
function delSessions(ids) {
function deleteMultipleSessions(ids) {
// This function is called when multiple sessions are selected and the gray
// trash button is clicked
// Check input validity
if (!Array.isArray(ids)) return;
@@ -223,11 +228,16 @@ function delSessions(ids) {
// Loop through IDs and delete them
deleted = 0;
for (const id of ids) {
delSession(id, ids.length, ownSessionDelete);
deleteOneSession(id, ids.length, ownSessionDelete);
}
}
function delSession(id, len, ownSessionDelete) {
function deleteOneSession(id, len, ownSessionDelete) {
// This function is called to delete a single session
// If we are batch deleting, we ensure that we do not delete our own session
// before having successfully deleted all other sessions, the deletion of
// our own session is then triggered by the last successful deletion of
// another session (ownSessionDelete == true, len == global deleted)
$.ajax({
url: "/api/auth/session/" + id,
method: "DELETE",
@@ -237,7 +247,7 @@ function delSession(id, len, ownSessionDelete) {
if (++deleted < len) return;
// All other sessions have been deleted, now delete own session
if (ownSessionDelete) delSession(ownSessionID, 1, false);
if (ownSessionDelete) deleteOneSession(ownSessionID, 1, false);
if (id !== ownSessionID) {
// Reload table to remove session