Use getStat instead of other jquery code to update the event data. Don't refresh before rename ajax finishes. Deprecate the n/a handling in getStat. Not sure why it's needed. Sync update eventData with what is returned by ajax status call. Fixes #3265

This commit is contained in:
Isaac Connor 2021-06-08 15:58:17 -04:00
parent 131e57a99e
commit 2288d32928
2 changed files with 15 additions and 32 deletions

View File

@ -424,7 +424,6 @@ function streamFastRev(action) {
if (vid) { //There is no reverse play with mp4. Set the speed to 0 and manually set the time back. if (vid) { //There is no reverse play with mp4. Set the speed to 0 and manually set the time back.
revSpeed = -1*(rates[rates.indexOf(revSpeed*-100)-1]/100); revSpeed = -1*(rates[rates.indexOf(revSpeed*-100)-1]/100);
if (rates.indexOf(revSpeed*-100) == 0) { if (rates.indexOf(revSpeed*-100) == 0) {
console.log("paused?");
setButtonState('fastRevBtn', 'unavail'); setButtonState('fastRevBtn', 'unavail');
} }
clearInterval(intervalRewind); clearInterval(intervalRewind);
@ -583,28 +582,9 @@ function getEventResponse(respObj, respText) {
} }
eventData = respObj.event; eventData = respObj.event;
getStat();
currEventId = eventData.Id; currEventId = eventData.Id;
$j('#dataEventId').text( eventData.Id );
$j('#dataEventName').text( eventData.Name );
$j('#dataMonitorId').text('<a href="?video=monitor&mid='+eventData.MonitorId+'">'+eventData.MonitorId+'</a>');
$j('#dataMonitorName').text('<a href="?video=monitor&mid='+eventData.MonitorId+'">'+eventData.MonitorName+'</a>');
$j('#dataCause').text( eventData.Cause );
if ( eventData.Notes ) {
$j('#dataCause').prop( 'title', eventData.Notes );
} else {
$j('#dataCause').prop( 'title', causeString );
}
$j('#dataStartTime').text( eventData.StartDateTime );
$j('#dataDuration').text( eventData.Length );
$j('#dataFrames').text( eventData.Frames );
$j('#dataAlarmFrames').text( eventData.AlarmFrames );
$j('dataTotalScore').text( eventData.TotScore );
$j('dataAvgScore').text( eventData.AvgScore );
$j('dataMaxScore').text( eventData.MaxScore );
$j('dataDiskSpace').text( eventData.DiskSpace );
$j('dataStorage').text( eventData.Storage );
// Refresh the status of the archive buttons // Refresh the status of the archive buttons
archiveBtn.prop('disabled', !(!eventData.Archived && canEdit.Events)); archiveBtn.prop('disabled', !(!eventData.Archived && canEdit.Events));
unarchiveBtn.prop('disabled', !(eventData.Archived && canEdit.Events)); unarchiveBtn.prop('disabled', !(eventData.Archived && canEdit.Events));
@ -612,7 +592,6 @@ function getEventResponse(respObj, respText) {
history.replaceState(null, null, '?view=event&eid=' + eventData.Id + filterQuery + sortQuery); //if popup removed, check if this allows forward history.replaceState(null, null, '?view=event&eid=' + eventData.Id + filterQuery + sortQuery); //if popup removed, check if this allows forward
if ( vid && CurEventDefVideoPath ) { if ( vid && CurEventDefVideoPath ) {
vid.src({type: 'video/mp4', src: CurEventDefVideoPath}); //Currently mp4 is all we use vid.src({type: 'video/mp4', src: CurEventDefVideoPath}); //Currently mp4 is all we use
console.log('getEventResponse');
initialAlarmCues(eventData.Id);//ajax and render, new event initialAlarmCues(eventData.Id);//ajax and render, new event
addVideoTimingTrack(vid, LabelFormat, eventData.MonitorName, eventData.Length, eventData.StartDateTime); addVideoTimingTrack(vid, LabelFormat, eventData.MonitorName, eventData.Length, eventData.StartDateTime);
CurEventDefVideoPath = null; CurEventDefVideoPath = null;
@ -640,7 +619,6 @@ function getNearEventsResponse(respObj, respText) {
if (checkStreamForErrors('getNearEventsResponse', respObj)) { if (checkStreamForErrors('getNearEventsResponse', respObj)) {
return; return;
} }
console.log(respObj);
prevEventId = respObj.nearevents.PrevEventId; prevEventId = respObj.nearevents.PrevEventId;
nextEventId = respObj.nearevents.NextEventId; nextEventId = respObj.nearevents.NextEventId;
prevEventStartTime = Date.parse(respObj.nearevents.PrevEventStartTime); prevEventStartTime = Date.parse(respObj.nearevents.PrevEventStartTime);
@ -709,6 +687,7 @@ function getActResponse(respObj, respText) {
if (respObj.refreshEvent) { if (respObj.refreshEvent) {
eventQuery(eventData.Id); eventQuery(eventData.Id);
} }
$j('#eventRenameModal').modal('hide');
} }
function actQuery(action, parms) { function actQuery(action, parms) {
@ -726,8 +705,6 @@ function actQuery(action, parms) {
function renameEvent() { function renameEvent() {
var newName = $j('input').val(); var newName = $j('input').val();
actQuery('rename', {eventName: newName}); actQuery('rename', {eventName: newName});
//FIXME: update the value of the event name rather than reload the whole page
window.location.reload(true);
} }
function exportEvent() { function exportEvent() {
@ -826,7 +803,8 @@ function getStat() {
var th = $j('<th>').addClass('text-right').text(eventDataStrings[key]); var th = $j('<th>').addClass('text-right').text(eventDataStrings[key]);
var tdString; var tdString;
switch ( ( eventData[key] && eventData[key].length ) ? key : 'n/a') { //switch ( ( eventData[key] && eventData[key].length ) ? key : 'n/a') {
switch (key) {
case 'Frames': case 'Frames':
tdString = '<a href="?view=frames&amp;eid=' + eventData.Id + '">' + eventData[key] + '</a>'; tdString = '<a href="?view=frames&amp;eid=' + eventData.Id + '">' + eventData[key] + '</a>';
break; break;
@ -839,6 +817,10 @@ function getStat() {
case 'n/a': case 'n/a':
tdString = 'n/a'; tdString = 'n/a';
break; break;
case 'Archived':
case 'Emailed':
tdString = eventData[key] ? yesStr : noStr;
break;
default: default:
tdString = eventData[key]; tdString = eventData[key];
} }

View File

@ -49,7 +49,7 @@ var eventData = {
Height: '<?php echo $Event->Height() ?>', Height: '<?php echo $Event->Height() ?>',
Length: '<?php echo $Event->Length() ?>', Length: '<?php echo $Event->Length() ?>',
StartDateTime: '<?php echo $Event->StartDateTime() ?>', StartDateTime: '<?php echo $Event->StartDateTime() ?>',
StartDateTimeFmt: '<?php echo strftime(STRF_FMT_DATETIME_SHORT, strtotime($Event->StartDateTime())) ?>', StartDateTimeShort: '<?php echo strftime(STRF_FMT_DATETIME_SHORT, strtotime($Event->StartDateTime())) ?>',
EndDateTime: '<?php echo $Event->EndDateTime() ?>', EndDateTime: '<?php echo $Event->EndDateTime() ?>',
Frames: '<?php echo $Event->Frames() ?>', Frames: '<?php echo $Event->Frames() ?>',
AlarmFrames: '<?php echo $Event->AlarmFrames() ?>', AlarmFrames: '<?php echo $Event->AlarmFrames() ?>',
@ -58,20 +58,21 @@ var eventData = {
MaxScore: '<?php echo $Event->MaxScore() ?>', MaxScore: '<?php echo $Event->MaxScore() ?>',
DiskSpace: '<?php echo human_filesize($Event->DiskSpace(null)) ?>', DiskSpace: '<?php echo human_filesize($Event->DiskSpace(null)) ?>',
Storage: '<?php echo validHtmlStr($Event->Storage()->Name()).( $Event->SecondaryStorageId() ? ', '.validHtmlStr($Event->SecondaryStorage()->Name()) : '' ) ?>', Storage: '<?php echo validHtmlStr($Event->Storage()->Name()).( $Event->SecondaryStorageId() ? ', '.validHtmlStr($Event->SecondaryStorage()->Name()) : '' ) ?>',
ArchivedStr: '<?php echo $Event->Archived ? translate('Yes') : translate('No') ?>',
EmailedStr: '<?php echo $Event->Emailed ? translate('Yes') : translate('No') ?>',
Archived: <?php echo $Event->Archived?'true':'false' ?>, Archived: <?php echo $Event->Archived?'true':'false' ?>,
Emailed: <?php echo $Event->Emailed?'true':'false' ?> Emailed: <?php echo $Event->Emailed?'true':'false' ?>
<?php } ?> <?php } ?>
}; };
var yesStr = '<?php echo translate('Yes') ?>';
var noStr = '<?php echo translate('No') ?>';
var eventDataStrings = { var eventDataStrings = {
Id: '<?php echo translate('EventId') ?>', Id: '<?php echo translate('EventId') ?>',
Name: '<?php echo translate('EventName') ?>', Name: '<?php echo translate('EventName') ?>',
MonitorId: '<?php echo translate('AttrMonitorId') ?>', MonitorId: '<?php echo translate('AttrMonitorId') ?>',
MonitorName: '<?php echo translate('AttrMonitorName') ?>', MonitorName: '<?php echo translate('AttrMonitorName') ?>',
Cause: '<?php echo translate('Cause') ?>', Cause: '<?php echo translate('Cause') ?>',
StartDateTimeFmt: '<?php echo translate('AttrStartTime') ?>', StartDateTimeShort: '<?php echo translate('AttrStartTime') ?>',
Length: '<?php echo translate('Duration') ?>', Length: '<?php echo translate('Duration') ?>',
Frames: '<?php echo translate('AttrFrames') ?>', Frames: '<?php echo translate('AttrFrames') ?>',
AlarmFrames: '<?php echo translate('AttrAlarmFrames') ?>', AlarmFrames: '<?php echo translate('AttrAlarmFrames') ?>',
@ -80,8 +81,8 @@ var eventDataStrings = {
MaxScore: '<?php echo translate('AttrMaxScore') ?>', MaxScore: '<?php echo translate('AttrMaxScore') ?>',
DiskSpace: '<?php echo translate('DiskSpace') ?>', DiskSpace: '<?php echo translate('DiskSpace') ?>',
Storage: '<?php echo translate('Storage') ?>', Storage: '<?php echo translate('Storage') ?>',
ArchivedStr: '<?php echo translate('Archived') ?>', Archived: '<?php echo translate('Archived') ?>',
EmailedStr: '<?php echo translate('Emailed') ?>' Emailed: '<?php echo translate('Emailed') ?>'
}; };
var monitorUrl = '<?php echo $Event->Storage()->Server()->UrlToIndex(); ?>'; var monitorUrl = '<?php echo $Event->Storage()->Server()->UrlToIndex(); ?>';