2020-10-19 20:50:11 +08:00
|
|
|
var backBtn = $j('#backBtn');
|
|
|
|
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-10-19 22:29:39 +08:00
|
|
|
/*
|
|
|
|
This is the format of the json object sent by bootstrap-table
|
|
|
|
|
|
|
|
var params =
|
|
|
|
{
|
|
|
|
"type":"get",
|
|
|
|
"data":
|
|
|
|
{
|
|
|
|
"search":"some search text",
|
|
|
|
"sort":"StartTime",
|
|
|
|
"order":"asc",
|
|
|
|
"offset":0,
|
|
|
|
"limit":25
|
|
|
|
"filter":
|
|
|
|
{
|
|
|
|
"Name":"some advanced search text"
|
|
|
|
"StartTime":"some more advanced search text"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"cache":true,
|
|
|
|
"contentType":"application/json",
|
|
|
|
"dataType":"json"
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Called by bootstrap-table to retrieve zm event data
|
|
|
|
function ajaxRequest(params) {
|
|
|
|
$j.getJSON(thisUrl + '?view=request&request=events&task=query', params.data)
|
|
|
|
.done(function(data) {
|
|
|
|
var rows = processRows(data.rows);
|
2020-10-21 01:59:30 +08:00
|
|
|
// rearrange the result into what bootstrap-table expects
|
2020-10-19 22:29:39 +08:00
|
|
|
params.success({total: data.total, totalNotFiltered: data.totalNotFiltered, rows: rows});
|
|
|
|
})
|
|
|
|
.fail(logAjaxFail);
|
|
|
|
}
|
|
|
|
|
|
|
|
function processRows(rows) {
|
2020-10-20 03:18:21 +08:00
|
|
|
$j.each(rows, function(ndx, row) {
|
|
|
|
var eid = row.Id;
|
|
|
|
var mid = row.MonitorId;
|
|
|
|
var archived = row.Archived == yesString ? archivedString : '';
|
|
|
|
var emailed = row.Emailed == yesString ? emailedString : '';
|
|
|
|
|
|
|
|
row.Id = '<a href="?view=event&eid=' + eid + filterQuery + sortQuery + '&page=1">' + eid + '</a>';
|
|
|
|
row.Name = '<a href="?view=event&eid=' + eid + filterQuery + sortQuery + '&page=1">' + row.Name + '</a>'
|
|
|
|
+ '<br/><div class="small text-nowrap text-muted">' + archived + emailed + '</div>';
|
2020-10-21 01:59:30 +08:00
|
|
|
if ( canEditMonitors ) row.Monitor = '<a href="?view=monitor&mid=' + mid + '">' + row.Monitor + '</a>';
|
|
|
|
if ( canEditEvents ) row.Cause = '<a href="#" title="' + row.Notes + '" class="eDetailLink" data-eid="' + eid + '">' + row.Cause + '</a>';
|
2020-10-20 21:10:43 +08:00
|
|
|
if ( row.Notes.indexOf('detected:') >= 0 ) {
|
|
|
|
row.Cause = row.Cause + '<a href="#?view=image&eid=' + eid + '&fid=objdetect"><div class="small text-nowrap text-muted"><u>' + row.Notes + '</u></div></a>';
|
|
|
|
} else if ( row.Notes != 'Forced Web: ' ) {
|
|
|
|
row.Cause = row.Cause + '<br/><div class="small text-nowrap text-muted">' + row.Notes + '</div>';
|
|
|
|
}
|
|
|
|
row.Frames = '<a href="?view=frames&eid=' + eid + '">' + row.Frames + '</a>';
|
|
|
|
row.AlarmFrames = '<a href="?view=frames&eid=' + eid + '">' + row.AlarmFrames + '</a>';
|
|
|
|
row.MaxScore = '<a href="?view=frame&eid=' + eid + '&fid=0">' + row.MaxScore + '</a>';
|
2020-10-21 01:13:12 +08:00
|
|
|
row.Thumbnail = '<a href="?view=event&eid=' + eid + filterQuery + sortQuery + '&page=1">' + row.imgHtml + '</a>';
|
2020-10-20 03:18:21 +08:00
|
|
|
});
|
2020-10-19 22:29:39 +08:00
|
|
|
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
|
2019-02-07 02:31:34 +08:00
|
|
|
function thumbnail_onmouseover(event) {
|
|
|
|
var img = event.target;
|
2019-12-14 06:48:22 +08:00
|
|
|
img.src = '';
|
2019-02-07 02:31:34 +08:00
|
|
|
img.src = img.getAttribute('stream_src');
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2019-02-07 02:31:34 +08:00
|
|
|
function thumbnail_onmouseout(event) {
|
|
|
|
var img = event.target;
|
2019-12-14 06:48:22 +08:00
|
|
|
img.src = '';
|
2019-02-07 02:31:34 +08:00
|
|
|
img.src = img.getAttribute('still_src');
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2020-08-19 01:00:20 +08:00
|
|
|
function initThumbAnimation() {
|
|
|
|
$j('.colThumbnail img').each(function() {
|
|
|
|
this.addEventListener('mouseover', thumbnail_onmouseover, false);
|
|
|
|
this.addEventListener('mouseout', thumbnail_onmouseout, false);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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');
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2020-08-16 04:54:58 +08:00
|
|
|
return $j.map(table.bootstrapTable('getSelections'), function(row) {
|
2020-08-18 00:56:20 +08:00
|
|
|
return row.Id.replace(/(<([^>]+)>)/gi, ''); // strip the html from the element before sending
|
2020-08-16 04:54:58 +08:00
|
|
|
});
|
2017-12-04 03:04:33 +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");
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2020-09-13 23:39:51 +08:00
|
|
|
// Load the Delete Confirmation Modal HTML via Ajax call
|
|
|
|
function getDelConfirmModal() {
|
|
|
|
$j.getJSON(thisUrl + '?request=modal&modal=delconfirm')
|
|
|
|
.done(function(data) {
|
2020-10-15 04:58:39 +08:00
|
|
|
insertModalHtml('deleteConfirm', data.html);
|
2020-09-13 23:39:51 +08:00
|
|
|
manageDelConfirmModalBtns();
|
|
|
|
})
|
2020-09-20 21:41:16 +08:00
|
|
|
.fail(logAjaxFail);
|
2020-09-13 23:39:51 +08:00
|
|
|
}
|
|
|
|
|
2020-09-17 07:22:37 +08:00
|
|
|
// Manage the DELETE CONFIRMATION modal button
|
2020-09-13 23:39:51 +08:00
|
|
|
function manageDelConfirmModalBtns() {
|
|
|
|
document.getElementById("delConfirmBtn").addEventListener("click", function onDelConfirmClick(evt) {
|
|
|
|
if ( ! canEditEvents ) {
|
2020-09-14 00:09:15 +08:00
|
|
|
enoperm();
|
2020-09-13 23:39:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var selections = getIdSelections();
|
|
|
|
|
|
|
|
evt.preventDefault();
|
2020-10-19 20:50:11 +08:00
|
|
|
$j.getJSON(thisUrl + '?request=events&task=delete&eids[]='+selections.join('&eids[]='))
|
2020-09-14 00:25:31 +08:00
|
|
|
.done( function(data) {
|
|
|
|
$j('#eventTable').bootstrapTable('refresh');
|
2020-09-17 07:22:37 +08:00
|
|
|
window.location.reload(true);
|
2020-09-14 00:25:31 +08:00
|
|
|
})
|
2020-09-20 21:41:16 +08:00
|
|
|
.fail(logAjaxFail);
|
2020-09-13 23:39:51 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Manage the CANCEL modal button
|
|
|
|
document.getElementById("delCancelBtn").addEventListener("click", function onDelCancelClick(evt) {
|
|
|
|
$j('#deleteConfirm').modal('hide');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-15 22:49:03 +08:00
|
|
|
function getEventDetailModal(eid) {
|
|
|
|
$j.getJSON(thisUrl + '?request=modal&modal=eventdetail&eids[]=' + eid)
|
2020-09-16 20:57:44 +08:00
|
|
|
.done(function(data) {
|
2020-10-15 04:58:39 +08:00
|
|
|
insertModalHtml('eventDetailModal', data.html);
|
2020-09-16 20:57:44 +08:00
|
|
|
$j('#eventDetailModal').modal('show');
|
|
|
|
// Manage the Save button
|
|
|
|
$j('#eventDetailSaveBtn').click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
$j('#eventDetailForm').submit();
|
|
|
|
});
|
|
|
|
})
|
2020-09-20 21:41:16 +08:00
|
|
|
.fail(logAjaxFail);
|
2020-09-15 22:49:03 +08:00
|
|
|
}
|
|
|
|
|
2019-01-18 23:00:55 +08:00
|
|
|
function initPage() {
|
2020-09-13 23:39:51 +08:00
|
|
|
// Load the delete confirmation modal into the DOM
|
|
|
|
getDelConfirmModal();
|
|
|
|
|
2020-08-17 05:02:43 +08:00
|
|
|
// Init the bootstrap-table
|
2020-09-24 03:32:40 +08:00
|
|
|
table.bootstrapTable({icons: icons});
|
2008-07-14 21:54:50 +08:00
|
|
|
|
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');
|
2018-06-16 03:21:10 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +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() {
|
2020-08-18 00:56:20 +08:00
|
|
|
selections = table.bootstrapTable('getSelections');
|
2017-12-13 23:20:02 +08:00
|
|
|
|
2020-08-18 00:56:20 +08:00
|
|
|
viewBtn.prop('disabled', !(selections.length && canViewEvents));
|
|
|
|
archiveBtn.prop('disabled', !(selections.length && canEditEvents));
|
2020-08-17 00:34:37 +08:00
|
|
|
unarchiveBtn.prop('disabled', !(getArchivedSelections()) && canEditEvents);
|
2020-08-18 00:56:20 +08:00
|
|
|
editBtn.prop('disabled', !(selections.length && canEditEvents));
|
|
|
|
exportBtn.prop('disabled', !(selections.length && canViewEvents));
|
|
|
|
downloadBtn.prop('disabled', !(selections.length && canViewEvents));
|
|
|
|
deleteBtn.prop('disabled', !(selections.length && canEditEvents));
|
2020-08-17 00:34:37 +08:00
|
|
|
});
|
2020-08-20 01:07:31 +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-08-19 01:00:20 +08:00
|
|
|
// Setup the thumbnail video animation
|
|
|
|
initThumbAnimation();
|
2020-08-19 01:40:27 +08:00
|
|
|
|
2020-08-19 01:00:20 +08:00
|
|
|
// Some toolbar events break the thumbnail animation, so re-init eventlistener
|
|
|
|
table.on('all.bs.table', initThumbAnimation);
|
2020-08-19 01:40:27 +08:00
|
|
|
|
2020-08-17 02:44:18 +08:00
|
|
|
// Manage the BACK button
|
|
|
|
document.getElementById("backBtn").addEventListener("click", function onBackClick(evt) {
|
|
|
|
evt.preventDefault();
|
2020-08-19 05:57:03 +08:00
|
|
|
window.history.back();
|
2019-02-07 02:31:34 +08:00
|
|
|
});
|
2020-08-20 01:07:31 +08:00
|
|
|
|
2020-08-17 02:44:18 +08:00
|
|
|
// Manage the REFRESH Button
|
|
|
|
document.getElementById("refreshBtn").addEventListener("click", function onRefreshClick(evt) {
|
2019-02-10 09:34:59 +08:00
|
|
|
evt.preventDefault();
|
|
|
|
window.location.reload(true);
|
|
|
|
});
|
2020-08-20 01:07:31 +08:00
|
|
|
|
2020-08-17 02:44:18 +08:00
|
|
|
// Manage the TIMELINE Button
|
|
|
|
document.getElementById("tlineBtn").addEventListener("click", function onTlineClick(evt) {
|
2019-02-10 09:34:59 +08:00
|
|
|
evt.preventDefault();
|
2020-08-17 02:44:18 +08:00
|
|
|
window.location.assign('?view=timeline'+filterQuery);
|
2019-02-07 02:31:34 +08:00
|
|
|
});
|
2020-08-20 01:07:31 +08:00
|
|
|
|
2020-10-15 21:01:32 +08:00
|
|
|
// Manage the FILTER Button
|
|
|
|
document.getElementById("filterBtn").addEventListener("click", function onFilterClick(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
window.location.assign('?view=filter'+filterQuery);
|
|
|
|
});
|
|
|
|
|
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';
|
|
|
|
});
|
2020-08-20 01:07:31 +08:00
|
|
|
|
2020-08-16 04:27:58 +08:00
|
|
|
// 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();
|
2020-10-19 20:50:11 +08:00
|
|
|
$j.getJSON(thisUrl + '?request=events&task=archive&eids[]='+selections.join('&eids[]='))
|
2020-09-14 00:32:28 +08:00
|
|
|
.done( function(data) {
|
|
|
|
$j('#eventTable').bootstrapTable('refresh');
|
|
|
|
window.location.reload(true);
|
|
|
|
})
|
2020-09-20 21:41:16 +08:00
|
|
|
.fail(logAjaxFail);
|
2020-08-16 04:54:58 +08:00
|
|
|
});
|
2020-08-20 01:07:31 +08:00
|
|
|
|
2020-08-16 04:27:58 +08:00
|
|
|
// Manage the UNARCHIVE button
|
|
|
|
document.getElementById("unarchiveBtn").addEventListener("click", function onUnarchiveClick(evt) {
|
|
|
|
if ( ! canEditEvents ) {
|
2020-09-14 00:09:15 +08:00
|
|
|
enoperm();
|
2020-08-16 04:27:58 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var selections = getIdSelections();
|
2020-08-18 00:56:20 +08:00
|
|
|
console.log(selections);
|
2020-08-16 04:54:58 +08:00
|
|
|
|
2020-08-16 04:27:58 +08:00
|
|
|
evt.preventDefault();
|
2020-10-19 20:50:11 +08:00
|
|
|
$j.getJSON(thisUrl + '?request=events&task=unarchive&eids[]='+selections.join('&eids[]='))
|
2020-09-14 00:32:28 +08:00
|
|
|
.done( function(data) {
|
|
|
|
$j('#eventTable').bootstrapTable('refresh');
|
|
|
|
window.location.reload(true);
|
|
|
|
})
|
2020-09-20 21:41:16 +08:00
|
|
|
.fail(logAjaxFail);
|
2020-08-16 04:54:58 +08:00
|
|
|
|
2020-09-29 21:42:31 +08:00
|
|
|
//window.location.reload(true);
|
2020-08-16 04:27:58 +08:00
|
|
|
});
|
2020-08-20 01:07:31 +08:00
|
|
|
|
2020-08-16 04:27:58 +08:00
|
|
|
// Manage the EDIT button
|
|
|
|
document.getElementById("editBtn").addEventListener("click", function onEditClick(evt) {
|
|
|
|
if ( ! canEditEvents ) {
|
2020-09-14 00:09:15 +08:00
|
|
|
enoperm();
|
2020-08-16 04:27:58 +08:00
|
|
|
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();
|
2020-09-15 21:55:32 +08:00
|
|
|
$j.getJSON(thisUrl + '?request=modal&modal=eventdetail&eids[]='+selections.join('&eids[]='))
|
2020-09-16 20:57:44 +08:00
|
|
|
.done(function(data) {
|
2020-10-15 04:58:39 +08:00
|
|
|
insertModalHtml('eventDetailModal', data.html);
|
2020-09-16 20:57:44 +08:00
|
|
|
$j('#eventDetailModal').modal('show');
|
|
|
|
// Manage the Save button
|
|
|
|
$j('#eventDetailSaveBtn').click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
$j('#eventDetailForm').submit();
|
|
|
|
});
|
|
|
|
})
|
2020-09-20 21:41:16 +08:00
|
|
|
.fail(logAjaxFail);
|
2020-08-16 04:27:58 +08:00
|
|
|
});
|
2020-08-20 01:07:31 +08:00
|
|
|
|
2020-08-16 04:27:58 +08:00
|
|
|
// 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[]='));
|
|
|
|
});
|
2020-08-20 01:07:31 +08:00
|
|
|
|
2020-08-16 04:27:58 +08:00
|
|
|
// 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();
|
2020-09-30 22:12:54 +08:00
|
|
|
$j.getJSON(thisUrl + '?request=modal&modal=download&eids[]='+selections.join('&eids[]='))
|
|
|
|
.done(function(data) {
|
2020-10-15 04:58:39 +08:00
|
|
|
insertModalHtml('downloadModal', data.html);
|
2020-09-30 22:12:54 +08:00
|
|
|
$j('#downloadModal').modal('show');
|
|
|
|
// Manage the GENERATE DOWNLOAD button
|
|
|
|
$j('#exportButton').click(exportEvent);
|
|
|
|
})
|
|
|
|
.fail(logAjaxFail);
|
2020-08-16 04:27:58 +08:00
|
|
|
});
|
2020-08-20 01:07:31 +08:00
|
|
|
|
2020-08-16 04:27:58 +08:00
|
|
|
// Manage the DELETE button
|
|
|
|
document.getElementById("deleteBtn").addEventListener("click", function onDeleteClick(evt) {
|
|
|
|
if ( ! canEditEvents ) {
|
2020-09-14 00:09:15 +08:00
|
|
|
enoperm();
|
2020-08-16 04:27:58 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-18 21:06:58 +08:00
|
|
|
evt.preventDefault();
|
|
|
|
$j('#deleteConfirm').modal('show');
|
|
|
|
});
|
|
|
|
|
2020-09-15 22:49:03 +08:00
|
|
|
// Manage the eventdetail links in the events list
|
|
|
|
$j(".eDetailLink").click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
var eid = $j(this).data('eid');
|
|
|
|
getEventDetailModal(eid);
|
|
|
|
});
|
|
|
|
|
2020-10-20 21:10:43 +08:00
|
|
|
// Update table links each time after new data is loaded
|
|
|
|
table.on('post-body.bs.table', function(data) {
|
|
|
|
// Manage the eventdetail links in the events list
|
|
|
|
$j(".eDetailLink").click(function(evt) {
|
|
|
|
evt.preventDefault();
|
|
|
|
var eid = $j(this).data('eid');
|
|
|
|
getEventDetailModal(eid);
|
|
|
|
});
|
2020-10-21 01:13:12 +08:00
|
|
|
|
|
|
|
var thumb_ndx = $j('#eventTable tr th').filter(function() {
|
|
|
|
return $j(this).text().trim() == 'Thumbnail';
|
|
|
|
}).index();
|
|
|
|
table.find("tr td:nth-child(" + (thumb_ndx+1) + ")").addClass('colThumbnail zoom');
|
2020-10-20 21:10:43 +08:00
|
|
|
});
|
|
|
|
|
2020-08-19 04:33:04 +08:00
|
|
|
// The table is initially given a hidden style, so now that we are done rendering, show it
|
2020-08-18 00:56:20 +08:00
|
|
|
table.show();
|
2017-12-13 23:20:02 +08:00
|
|
|
}
|
|
|
|
|
2020-08-16 04:27:58 +08:00
|
|
|
$j(document).ready(function() {
|
|
|
|
initPage();
|
|
|
|
});
|