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

107 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-11-15 04:19:28 +08:00
var backBtn = $j('#backBtn');
var table = $j('#framesTable');
// Called by bootstrap-table to retrieve zm frame data
function ajaxRequest(params) {
if ( params.data && params.data.filter ) {
params.data.advsearch = params.data.filter;
delete params.data.filter;
}
$j.getJSON(thisUrl + '?view=request&request=frames&task=query&eid='+eid, params.data)
.done(function(data) {
var rows = processRows(data.rows);
// rearrange the result into what bootstrap-table expects
2020-11-15 04:19:28 +08:00
console.log('Total: '+data.total);
console.log('TotalnotFiltered: '+data.totalNotFiltered);
params.success({total: data.total, totalNotFiltered: data.totalNotFiltered, rows: rows});
})
.fail(logAjaxFail);
}
function processRows(rows) {
$j.each(rows, function(ndx, row) {
// WIP: process each row here
2020-11-15 04:19:28 +08:00
// VERIFY: Might not need to do anything here for the frames table
});
return rows;
}
2020-08-20 22:13:11 +08:00
function processClicks(event, field, value, row, $element) {
if ( field == 'Score' ) {
2020-09-10 23:10:19 +08:00
window.location.assign('?view=stats&eid='+row.EventId+'&fid='+row.FrameId);
2020-08-20 22:13:11 +08:00
} else {
2020-09-10 23:10:19 +08:00
window.location.assign('?view=frame&eid='+row.EventId+'&fid='+row.FrameId);
2020-08-20 22:13:11 +08:00
}
2020-08-20 06:54:39 +08:00
}
2020-09-13 20:32:49 +08:00
// This function handles when the user clicks a "+" link to retrieve stats for a frame
function detailFormatter(index, row, $detail) {
$detail.html('Please wait. Loading from ajax request...');
$j.get(thisUrl + '?request=stats&eid=' + row.EventId + '&fid=' + row.FrameId + '&row=' + index)
2020-09-13 21:33:47 +08:00
.done(function(data) {
2020-09-13 21:52:52 +08:00
$detail.html(data.html);
2020-09-13 21:33:47 +08:00
})
.fail(logAjaxFail);
2020-08-23 01:45:19 +08:00
}
2020-11-15 04:19:28 +08:00
2020-08-20 01:04:08 +08:00
function initPage() {
2020-11-15 04:19:28 +08:00
// Remove the thumbnail column from the DOM if thumbnails are off globally
if ( !WEB_LIST_THUMBS ) $j('th[data-field="Thumbnail"]').remove();
2020-08-20 01:04:08 +08:00
// Init the bootstrap-table
2020-09-24 03:32:40 +08:00
table.bootstrapTable({icons: icons});
2020-08-20 01:04:08 +08:00
2020-08-20 06:54:39 +08:00
// Hide these columns on first run when no cookie is saved
if ( !getCookie("zmFramesTable.bs.table.columns") ) {
2020-09-10 23:04:18 +08:00
table.bootstrapTable('hideColumn', 'EventId');
2020-08-20 06:54:39 +08:00
}
2020-08-23 01:45:19 +08:00
// Hide the stats tables on init
$j(".contentStatsTable").hide();
2020-08-20 04:42:35 +08:00
// Disable the back button if there is nothing to go back to
2020-08-20 01:04:08 +08:00
backBtn.prop('disabled', !document.referrer.length);
2020-08-20 03:07:00 +08:00
2020-08-20 04:42:35 +08:00
// Setup the thumbnail animation
initThumbAnimation();
2020-08-20 04:42:35 +08:00
2020-08-20 05:16:27 +08:00
// Some toolbar events break the thumbnail animation, so re-init eventlistener
table.on('all.bs.table', initThumbAnimation);
2020-08-20 06:54:39 +08:00
// Load the associated frame image when the user clicks on a row
2020-08-20 22:13:11 +08:00
table.on('click-cell.bs.table', processClicks);
2020-08-20 06:54:39 +08:00
2020-08-20 01:04:08 +08:00
// 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);
});
2020-11-15 04:19:28 +08:00
// Update table links each time after new data is loaded
table.on('post-body.bs.table', function(data) {
var type_ndx = $j('#framesTable tr th').filter(function() {
return $j(this).text().trim() == 'Type';
}).index();
$j('#framesTable tr').each(function(ndx, row) {
var row = $j(row);
var type = row.find('td').eq(type_ndx).text().trim();
row.addClass(type.toLowerCase());
});
var thumb_ndx = $j('#framesTable tr th').filter(function() {
return $j(this).text().trim() == 'Thumbnail';
}).index();
2020-12-10 08:19:10 +08:00
table.find("tr td:nth-child(" + (thumb_ndx+1) + ")").addClass('colThumbnail');
2020-11-15 04:19:28 +08:00
});
2020-08-20 01:04:08 +08:00
}
$j(document).ready(function() {
initPage();
});