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
|
2020-09-24 21:25:39 +08:00
|
|
|
"filter":
|
|
|
|
{
|
|
|
|
"message":"some advanced search text"
|
|
|
|
"level":"some more advanced search text"
|
|
|
|
}
|
2020-09-24 02:09:19 +08:00
|
|
|
},
|
|
|
|
"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)
|
2020-09-25 00:05:34 +08:00
|
|
|
.done(function(data) {
|
|
|
|
//console.log('Ajax parameters: ' + JSON.stringify(params));
|
2020-09-24 02:09:19 +08:00
|
|
|
// rearrange the result into what bootstrap-table expects
|
2020-09-25 00:05:34 +08:00
|
|
|
params.success({total: data.total, totalNotFiltered: data.totalNotFiltered, rows: data.rows});
|
|
|
|
updateHeaderStats(data);
|
2020-09-24 02:09:19 +08:00
|
|
|
})
|
|
|
|
.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');
|
|
|
|
|
|
|
|
// 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' )) {
|
2020-09-25 20:21:14 +08:00
|
|
|
row.addClass('log-fat');
|
2020-09-24 02:09:19 +08:00
|
|
|
} else if ( level == 'ERR' ) {
|
2020-09-25 20:21:14 +08:00
|
|
|
row.addClass('log-err');
|
2020-09-24 02:09:19 +08:00
|
|
|
} else if ( level == 'WAR' ) {
|
2020-09-25 20:21:14 +08:00
|
|
|
row.addClass('log-war');
|
2020-09-24 02:09:19 +08:00
|
|
|
} else if ( level == 'DBG' ) {
|
2020-09-25 20:21:14 +08:00
|
|
|
row.addClass('log-dbg');
|
2020-09-24 02:09:19 +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);
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
});
|