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

177 lines
6.4 KiB
JavaScript
Raw Normal View History

2019-02-07 02:31:34 +08:00
function thumbnail_onmouseover(event) {
var img = event.target;
img.src = '';
2019-02-07 02:31:34 +08:00
img.src = img.getAttribute('stream_src');
}
2020-08-16 04:27:58 +08:00
2019-02-07 02:31:34 +08:00
function thumbnail_onmouseout(event) {
var img = event.target;
img.src = '';
2019-02-07 02:31:34 +08:00
img.src = img.getAttribute('still_src');
}
2020-08-17 00:34:37 +08:00
// Returns the event id's of the selected rows
2020-08-16 04:27:58 +08:00
function getIdSelections() {
var table = $j('#eventTable');
2020-08-16 04:54:58 +08:00
return $j.map(table.bootstrapTable('getSelections'), function(row) {
return row.Id.replace(/(<([^>]+)>)/gi, ""); // strip the html from the element before sending
});
2020-08-16 04:27:58 +08:00
}
2020-08-17 00:34:37 +08:00
// Returns a boolen to indicate at least one selected row is archived
2020-08-16 04:27:58 +08:00
function getArchivedSelections() {
2020-08-16 04:54:58 +08:00
var table = $j('#eventTable');
var selection = $j.map(table.bootstrapTable('getSelections'), function(row) {
return row.Archived;
});
return selection.includes("Yes");
2020-08-16 04:27:58 +08:00
}
function initPage() {
2020-08-17 00:34:37 +08:00
var viewBtn = $j('#viewBtn');
var archiveBtn = $j('#archiveBtn');
var unarchiveBtn = $j('#unarchiveBtn');
var editBtn = $j('#editBtn');
var exportBtn = $j('#exportBtn');
var downloadBtn = $j('#downloadBtn');
var deleteBtn = $j('#deleteBtn');
var table = $j('#eventTable');
2020-08-18 05:18:18 +08:00
// 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',
refresh: 'fa-sync',
toggleOff: 'fa-toggle-off',
toggleOn: 'fa-toggle-on',
columns: 'fa-th-list',
fullscreen: 'fa-arrows-alt',
detailOpen: 'fa-plus',
detailClose: 'fa-minus'
}
2020-08-17 05:02:43 +08:00
// Init the bootstrap-table
2020-08-18 05:18:18 +08:00
$j('#eventTable').bootstrapTable('destroy').bootstrapTable({ icons: icons });
2020-08-17 05:02:43 +08:00
// Hide these columns on first run when no cookie is saved
if ( !getCookie("zmEventsTable.bs.table.columns") ) {
table.bootstrapTable('hideColumn', 'Archived');
table.bootstrapTable('hideColumn', 'Emailed');
}
2020-08-17 05:30:35 +08:00
2020-08-17 05:02:43 +08:00
// enable or disable buttons based on current selection and user rights
2020-08-17 00:34:37 +08:00
table.on('check.bs.table uncheck.bs.table ' +
'check-all.bs.table uncheck-all.bs.table',
function() {
viewBtn.prop('disabled', !(table.bootstrapTable('getSelections').length && canViewEvents));
archiveBtn.prop('disabled', !(table.bootstrapTable('getSelections').length && canEditEvents));
unarchiveBtn.prop('disabled', !(getArchivedSelections()) && canEditEvents);
editBtn.prop('disabled', !(table.bootstrapTable('getSelections').length && canEditEvents));
exportBtn.prop('disabled', !(table.bootstrapTable('getSelections').length && canViewEvents));
downloadBtn.prop('disabled', !(table.bootstrapTable('getSelections').length && canViewEvents));
deleteBtn.prop('disabled', !(table.bootstrapTable('getSelections').length && canEditEvents));
});
2019-02-07 02:31:34 +08:00
if ( window.history.length == 1 ) {
2017-12-14 01:34:31 +08:00
$j('#controls').children().eq(0).html('');
}
2019-02-09 02:48:38 +08:00
$j('.colThumbnail img').each(function() {
this.addEventListener('mouseover', thumbnail_onmouseover, false);
this.addEventListener('mouseout', thumbnail_onmouseout, false);
2019-02-07 02:31:34 +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);
});
// Manage the TIMELINE Button
document.getElementById("tlineBtn").addEventListener("click", function onTlineClick(evt) {
evt.preventDefault();
window.location.assign('?view=timeline'+filterQuery);
2019-02-07 02:31:34 +08:00
});
2020-08-16 04:27:58 +08:00
// Manage the VIEW button
document.getElementById("viewBtn").addEventListener("click", function onViewClick(evt) {
var selections = getIdSelections();
2020-08-16 04:54:58 +08:00
2020-08-16 04:27:58 +08:00
evt.preventDefault();
var filter = '&filter[Query][terms][0][attr]=Id&filter[Query][terms][0][op]=%3D%5B%5D&filter[Query][terms][0][val]='+selections.join('%2C');
window.location.href = thisUrl+'?view=event&eid='+selections[0]+filter+sortQuery+'&page=1&play=1';
});
// Manage the ARCHIVE button
document.getElementById("archiveBtn").addEventListener("click", function onArchiveClick(evt) {
var selections = getIdSelections();
2020-08-16 04:54:58 +08:00
2020-08-16 04:27:58 +08:00
evt.preventDefault();
$j.getJSON(thisUrl + '?view=events&action=archive&eids[]='+selections.join('&eids[]='));
2020-08-16 04:27:58 +08:00
window.location.reload(true);
2020-08-16 04:54:58 +08:00
});
2020-08-16 04:27:58 +08:00
// Manage the UNARCHIVE button
document.getElementById("unarchiveBtn").addEventListener("click", function onUnarchiveClick(evt) {
if ( ! canEditEvents ) {
alert("You do not have permission to Unarchive events.");
return;
}
var selections = getIdSelections();
2020-08-16 04:54:58 +08:00
2020-08-16 04:27:58 +08:00
evt.preventDefault();
$j.getJSON(thisUrl + '?view=events&action=unarchive&eids[]='+selections.join('&eids[]='));
2020-08-16 04:54:58 +08:00
2020-08-16 04:27:58 +08:00
if ( openFilterWindow ) {
//opener.location.reload(true);
createPopup( '?view=filter&page='+thisPage+filterQuery, 'zmFilter', 'filter' );
location.replace( '?view='+currentView+'&page='+thisPage+filterQuery );
} else {
window.location.reload(true);
}
});
// Manage the EDIT button
document.getElementById("editBtn").addEventListener("click", function onEditClick(evt) {
if ( ! canEditEvents ) {
alert("You do not have permission to edit events.");
return;
}
2020-08-16 04:54:58 +08:00
2020-08-16 04:27:58 +08:00
var selections = getIdSelections();
2020-08-16 04:54:58 +08:00
2020-08-16 04:27:58 +08:00
evt.preventDefault();
createPopup('?view=eventdetail&eids[]='+selections.join('&eids[]='), 'zmEventDetail', 'eventdetail');
});
// Manage the EXPORT button
document.getElementById("exportBtn").addEventListener("click", function onExportClick(evt) {
var selections = getIdSelections();
2020-08-16 04:54:58 +08:00
2020-08-16 04:27:58 +08:00
evt.preventDefault();
window.location.assign('?view=export&eids[]='+selections.join('&eids[]='));
});
// Manage the DOWNLOAD VIDEO button
document.getElementById("downloadBtn").addEventListener("click", function onDownloadClick(evt) {
var selections = getIdSelections();
2020-08-16 04:54:58 +08:00
2020-08-16 04:27:58 +08:00
evt.preventDefault();
createPopup('?view=download&eids[]='+selections.join('&eids[]='), 'zmDownload', 'download');
});
// Manage the DELETE button
document.getElementById("deleteBtn").addEventListener("click", function onDeleteClick(evt) {
if ( ! canEditEvents ) {
alert("You do not have permission to delete events.");
return;
}
var selections = getIdSelections();
2020-08-16 04:54:58 +08:00
2020-08-16 04:27:58 +08:00
evt.preventDefault();
$j.getJSON(thisUrl + '?view=events&action=delete&eids[]='+selections.join('&eids[]='));
window.location.reload(true);
});
}
2020-08-16 04:27:58 +08:00
$j(document).ready(function() {
initPage();
});