zoneminder/web/skins/classic/views/js/log.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

116 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-10-03 02:26:35 +08:00
var table = $j('#logTable');
/*
This is the format of the json object sent by bootstrap-table
var params =
{
"type":"get",
"data":
{
"search":"some search text",
"sort":"DateTime",
"order":"asc",
"offset":0,
"limit":25
"filter":
{
"message":"some advanced search text"
"level":"some more advanced search text"
}
},
"cache":true,
"contentType":"application/json",
"dataType":"json"
};
2020-10-03 02:26:35 +08:00
*/
// Called by bootstrap-table to retrieve zm log data
function ajaxRequest(params) {
2020-10-18 20:20:59 +08:00
$j.getJSON(thisUrl + '?view=request&request=log&task=query', params.data)
2020-10-03 02:26:35 +08:00
.done(function(data) {
//console.log('Ajax parameters: ' + JSON.stringify(params));
// rearrange the result into what bootstrap-table expects
2021-02-02 22:09:53 +08:00
params.success({
total: data.total,
totalNotFiltered: data.totalNotFiltered,
rows: processRows(data.rows)
});
2020-10-03 02:26:35 +08:00
updateHeaderStats(data);
})
.fail(logAjaxFail);
}
2021-02-02 22:09:53 +08:00
function processRows(rows) {
$j.each(rows, function(ndx, row) {
row.Message = decodeURIComponent(row.Message);
2021-02-02 22:09:53 +08:00
});
return rows;
}
2020-10-03 02:26:35 +08:00
function updateHeaderStats(data) {
var pageNum = table.bootstrapTable('getOptions').pageNumber;
var pageSize = table.bootstrapTable('getOptions').pageSize;
var startRow = ( (pageNum - 1 ) * pageSize ) + 1;
var stopRow = pageNum * pageSize;
var newClass = (data.logstate == 'ok') ? 'text-success' : (data.logstate == 'alert' ? 'text-warning' : ((data.logstate == 'alarm' ? 'text-danger' : '')));
$j('#logState').text(data.logstate);
$j('#logState').removeClass('text-success');
$j('#logState').removeClass('text-warning');
$j('#logState').removeClass('text-danger');
$j('#logState').addClass(newClass);
$j('#totalLogs').text(data.total);
$j('#availLogs').text(data.totalNotFiltered);
$j('#lastUpdate').text(data.updated);
$j('#displayLogs').text(startRow + ' to ' + stopRow);
}
2020-10-03 02:26:35 +08:00
function initPage() {
var backBtn = $j('#backBtn');
// Init the bootstrap-table with custom icons
table.bootstrapTable({icons: icons});
// Assign inf, err, fat, dbg color classes to the rows in the table
table.on('post-body.bs.table', function(data) {
var lvl_ndx = $j('#logTable tr th').filter(function() {
return $j(this).text().trim() == 'Level';
}).index();
$j('#logTable tr').each(function(ndx, row) {
var row = $j(row);
var level = row.find('td').eq(lvl_ndx).text().trim();
if (( level == 'FAT' ) || ( level == 'PNC' )) {
row.addClass('log-fat');
} else if ( level == 'ERR' ) {
row.addClass('log-err');
} else if ( level == 'WAR' ) {
row.addClass('log-war');
} else if ( level == 'DBG' ) {
row.addClass('log-dbg');
2017-05-19 01:50:56 +08:00
}
2020-09-22 01:01:58 +08:00
});
2020-10-03 02:26:35 +08:00
});
2020-10-03 02:26:35 +08:00
// Don't enable the back button if there is no previous zm page to go back to
backBtn.prop('disabled', !document.referrer.length);
2020-10-03 02:26:35 +08:00
// Manage the BACK button
document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) {
evt.preventDefault();
window.history.back();
});
2020-10-03 02:26:35 +08:00
// Manage the REFRESH Button
document.getElementById("refreshBtn").addEventListener("click", function onRefreshClick(evt) {
evt.preventDefault();
window.location.reload(true);
});
}
2020-10-03 02:26:35 +08:00
$j(document).ready(function() {
initPage();
});