fix: give the log panel its own strings refs #5147

The panel's messages came from the global translate object that
views/js/log.js.php defined, which the footer only loads for the Log
view. On any other view Clear Logs threw "translate is not defined" out
of deleteLogs() before it sent anything, and a failed table query would
have thrown the same way.

Carry the five strings on the panel element as data-i18n and read them
in initLogPanel(), so a panel is self-contained wherever it is embedded.
views/js/log.js.php held nothing else, so it goes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Isaac ConnorandClaude Opus 5 committed 2026-09-18 19:04:04 -04:00
1 parent 400464a23b
commit 86952cc0de
3 files changed
+14 -12

No files matched your search

+9 -1
View File
@@ -67,9 +67,17 @@ function getLogPanelHTML($options=array()) {
$levels[$level] = $level;
}
# The panel is loaded on every view, so it cannot rely on a per-view
# views/js/<view>.js.php defining a translate object. Carry its own strings.
$strings = array();
foreach (array('Reason', 'AJAXRequestError', 'ErrorUpdatingLogTable',
'ErrorDeletingRowFromLogTable', 'DeletingRowsFromTable') as $string) {
$strings[$string] = translate($string);
}
ob_start();
?>
<div class="logPanel" id="<?php echo $id ?>Panel" data-components="<?php echo $locked === null ? '' : validHtmlStr(json_encode($locked)) ?>">
<div class="logPanel" id="<?php echo $id ?>Panel" data-components="<?php echo $locked === null ? '' : validHtmlStr(json_encode($locked)) ?>" data-i18n="<?php echo validHtmlStr(json_encode($strings)) ?>">
<div class="logPanel-summary text-center">
<?php echo translate('State') ?>:&nbsp;<span class="logPanel-state"></span>&nbsp;-&nbsp;
<?php echo translate('Total') ?>:&nbsp;<span class="logPanel-total"></span>&nbsp;-&nbsp;
+5 -3
View File
@@ -37,6 +37,8 @@ function initLogPanel(panel) {
// A panel locked to a set of components queries only those and never writes
// the user's Log view selection back to the session.
const lockedComponents = panel.dataset.components ? JSON.parse(panel.dataset.components) : null;
// The panel's own strings; a view's views/js/<view>.js.php is not loaded here.
const i18n = panel.dataset.i18n ? JSON.parse(panel.dataset.i18n) : {};
let ajax = null;
let allowRequest = false; // Allow unscheduled AJAX requests
@@ -179,7 +181,7 @@ function initLogPanel(panel) {
updateRequestStatus("stopped");
} else {
updateRequestStatus("error");
zmAlert(translate["Reason"] + ": " + jqxhr.statusText + "~~" + translate["ErrorUpdatingLogTable"], translate["AJAXRequestError"]);
zmAlert(i18n["Reason"] + ": " + jqxhr.statusText + "~~" + i18n["ErrorUpdatingLogTable"], i18n["AJAXRequestError"]);
}
table.bootstrapTable('hideLoading');
logAjaxFail(jqxhr);
@@ -241,7 +243,7 @@ function initLogPanel(panel) {
deleteProgressBar.appendChild(fill);
idsLength = log_ids.length;
handlerAlert = zmAlert(translate["DeletingRowsFromTable"]);
handlerAlert = zmAlert(i18n["DeletingRowsFromTable"]);
waitUntil(() => (document.querySelector('#' + handlerAlert + ' .modal-body')), 10000).then((result) => {
// We're waiting for the modal information block to appear.
@@ -288,7 +290,7 @@ function initLogPanel(panel) {
table.bootstrapTable('refresh');
updateRequestStatus("error");
if (handlerAlert) closeZmAlert(handlerAlert);
zmAlert(translate["Reason"] + ": " + jqxhr.statusText + "~~" + translate["ErrorDeletingRowFromLogTable"], translate["AJAXRequestError"]);
zmAlert(i18n["Reason"] + ": " + jqxhr.statusText + "~~" + i18n["ErrorDeletingRowFromLogTable"], i18n["AJAXRequestError"]);
}
});
}
-8
View File
@@ -1,8 +0,0 @@
var translate = {
"Reason": "<?php echo translate('Reason') ?>",
"Aborted": "<?php echo translate('Aborted') ?>",
"ErrorUpdatingLogTable": "<?php echo translate('ErrorUpdatingLogTable') ?>",
"ErrorDeletingRowFromLogTable": "<?php echo translate('ErrorDeletingRowFromLogTable') ?>",
"DeletingRowsFromTable": "<?php echo translate('DeletingRowsFromTable') ?>",
"AJAXRequestError": "<?php echo translate('AJAXRequestError') ?>",
};