Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions web/skins/classic/views/js/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,18 @@ function updateHeaderStats(data) {
function manageClearLogsModalBtns() {
document.getElementById('clearLogsConfirmBtn').addEventListener('click', function onClearLogsConfirmClick(evt) {
evt.preventDefault();
$j('#clearLogsConfirm').modal('hide');
document.getElementById('clearLogsConfirmBtn').disabled = true;
deleteLogs(getIdSelections());
});
$j('#clearLogsConfirm').on('hide.bs.modal', function onClearLogsConfirmHidden(evt) {
const idRelatedTarget = $j(document.activeElement).attr('id');
// When executing deleteLogs(), we always call a table update
// after which manageClearButtonAvailability() is always executed, so there is no need to execute manageClearButtonAvailability() here
if (idRelatedTarget != "clearLogsConfirmBtn") manageClearButtonAvailability();
});
document.getElementById('clearLogsCancelBtn').addEventListener('click', function onClearLogsCancelClick(evt) {
evt.preventDefault();
$j('#clearLogsConfirm').modal('hide');
});
}
Expand All @@ -138,7 +146,6 @@ function deleteLogs(log_ids) {
data: {'ids[]': chunk},
success: function(data) {
if (!log_ids.length) {
$j('#clearLogsConfirm').modal('hide');
table.bootstrapTable('refresh');
} else {
if (ticker.innerHTML.length < 1 || ticker.innerHTML.length > 10) {
Expand All @@ -151,7 +158,6 @@ function deleteLogs(log_ids) {
},
error: function(jqxhr) {
logAjaxFail(jqxhr);
$j('#clearLogsConfirm').modal('hide');
table.bootstrapTable('refresh');
}
});
Expand Down Expand Up @@ -204,6 +210,7 @@ function initPage() {
const clearLogsBtn = document.getElementById('clearLogsBtn');
if (clearLogsBtn) {
clearLogsBtn.addEventListener('click', function onClearLogsClick(evt) {
manageClearButtonAvailability(false);
evt.preventDefault();
if (evt.ctrlKey) {
// Bypass confirmation, but ensure the modal (and its ticker) exists
Expand All @@ -216,6 +223,7 @@ function initPage() {
deleteLogs(getIdSelections());
})
.fail(function(jqXHR) {
manageClearButtonAvailability();
console.log('error getting clearlogsconfirm', jqXHR);
logAjaxFail(jqXHR);
});
Expand All @@ -231,6 +239,7 @@ function initPage() {
$j('#clearLogsConfirm').modal('show');
})
.fail(function(jqXHR) {
manageClearButtonAvailability();
console.log('error getting clearlogsconfirm', jqXHR);
logAjaxFail(jqXHR);
});
Expand All @@ -243,12 +252,10 @@ function initPage() {
}

// Enable or disable clear button based on selection
table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function() {
const selections = table.bootstrapTable('getSelections');
const clearLogsBtn = document.getElementById('clearLogsBtn');
if (clearLogsBtn) {
clearLogsBtn.disabled = !selections.length;
}
table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', manageClearButtonAvailability);

table.on('load-success.bs.table', function() {
manageClearButtonAvailability();
});

$j('#filterStartDateTime, #filterEndDateTime')
Expand All @@ -259,6 +266,18 @@ function initPage() {
.on('change', filterLog);
}

function manageClearButtonAvailability(enable = null) {
const selections = table.bootstrapTable('getSelections');
const clearLogsBtn = document.getElementById('clearLogsBtn');
if (clearLogsBtn) {
if (enable === false || !selections.length) {
clearLogsBtn.disabled = true;
} else if (enable === true || selections.length) {
clearLogsBtn.disabled = false;
}
}
}

$j(document).ready(function() {
initPage();
});
Loading