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

117 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-09-24 02:09:19 +08:00
var table = $j('#logTable');
2020-09-24 02:56:41 +08:00
2020-09-24 02:09:19 +08:00
/*
This is the format of the json object sent by bootstrap-table
2020-09-24 02:56:41 +08:00
var params =
2020-09-24 02:09:19 +08:00
{
"type":"get",
"data":
{
"search":"some search text",
"sort":"DateTime",
"order":"asc",
"offset":0,
"limit":25
},
"cache":true,
"contentType":"application/json",
"dataType":"json"
};
*/
// Called by bootstrap-table to retrieve zm log data
function ajaxRequest(params) {
$j.getJSON(thisUrl + '?view=request&request=newlog&task=query', params.data)
.done(function(res) {
//console.log('total: ' + res.total);
//console.log('totalNotFiltered: ' + res.totalNotFiltered);
console.log(JSON.stringify(params));
// rearrange the result into what bootstrap-table expects
var data = {total: res.total, totalNotFiltered: res.totalNotFiltered, rows: res.rows};
params.success(data);
updateHeaderStats(res);
})
.fail(logAjaxFail);
}
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' : '')));
2020-09-24 02:56:41 +08:00
2020-09-24 02:09:19 +08:00
$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);
}
function initPage() {
var backBtn = $j('#backBtn');
// Define the icons used in the bootstrap-table top-right toolbar
var icons = {
paginationSwitchDown: 'fa-caret-square-o-down',
paginationSwitchUp: 'fa-caret-square-o-up',
export: 'fa-download',
refresh: 'fa-refresh',
autoRefresh: 'fa-clock-o',
advancedSearchIcon: 'fa-chevron-down',
toggleOff: 'fa-toggle-off',
toggleOn: 'fa-toggle-on',
columns: 'fa-th-list',
fullscreen: 'fa-arrows-alt',
detailOpen: 'fa-plus',
detailClose: 'fa-minus'
};
// 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) {
$j('#logTable tr').each(function(ndx, row) {
2020-09-24 02:56:41 +08:00
var row = $j(row);
2020-09-24 02:09:19 +08:00
var level = row.find('td:eq(4)').text();
if (( level == 'FAT' ) || ( level == 'PNC' )) {
row.addClass('bg-danger');
row.addClass('font-weight-bold');
} else if ( level == 'ERR' ) {
row.addClass('bg-danger');
} else if ( level == 'WAR' ) {
2020-09-24 02:56:41 +08:00
row.addClass('bg-warning');
2020-09-24 02:09:19 +08:00
} else if ( level == 'DBG' ) {
row.addClass('bg-info');
}
});
});
// Don't enable the back button if there is no previous zm page to go back to
backBtn.prop('disabled', !document.referrer.length);
// Manage the BACK button
document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) {
evt.preventDefault();
window.history.back();
});
// Manage the REFRESH Button
document.getElementById("refreshBtn").addEventListener("click", function onRefreshClick(evt) {
evt.preventDefault();
window.location.reload(true);
});
}
$j(document).ready(function() {
initPage();
});