Handle errors returned from Ajax more gracefully.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2709 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
viseon 2008-12-05 23:58:58 +00:00
parent f2ad7cc770
commit 2419b6582e
1 changed files with 165 additions and 152 deletions

View File

@ -102,6 +102,9 @@ function getStreamCmdResponse( respText )
if ( !respText ) if ( !respText )
return; return;
var response = Json.evaluate( respText ); var response = Json.evaluate( respText );
if ( response.result == 'Ok' )
{
streamStatus = response.status; streamStatus = response.status;
$('fpsValue').setText( streamStatus.fps ); $('fpsValue').setText( streamStatus.fps );
@ -197,6 +200,7 @@ function getStreamCmdResponse( respText )
{ {
$('enableDisableAlarms').addClass( 'hidden' ); $('enableDisableAlarms').addClass( 'hidden' );
} }
}
var streamCmdTimeout = statusRefreshTimeout; var streamCmdTimeout = statusRefreshTimeout;
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT )
@ -349,9 +353,12 @@ function getStatusCmdResponse( respText )
if ( !respText ) if ( !respText )
return; return;
var response = Json.evaluate( respText ); var response = Json.evaluate( respText );
$('fpsValue').setText( response.monitor.FrameRate );
if ( response.result == 'Ok' )
{
$('fpsValue').setText( response.monitor.FrameRate );
setAlarmState( response.monitor.Status ); setAlarmState( response.monitor.Status );
}
var statusCmdTimeout = statusRefreshTimeout; var statusCmdTimeout = statusRefreshTimeout;
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT )
@ -401,10 +408,13 @@ function getActResponse( respText )
return; return;
var response = Json.evaluate( respText ); var response = Json.evaluate( respText );
if ( response.result == 'Ok' )
{
if ( response.refreshParent ) if ( response.refreshParent )
{ {
window.opener.location.reload(); window.opener.location.reload();
} }
}
eventCmdQuery(); eventCmdQuery();
} }
@ -435,6 +445,8 @@ function getEventCmdResponse( respText )
return; return;
var response = Json.evaluate( respText ); var response = Json.evaluate( respText );
if ( response.result == 'Ok' )
{
var dbEvents = response.events.reverse(); var dbEvents = response.events.reverse();
var eventList = $('eventList'); var eventList = $('eventList');
var eventListBody = $(eventList).getElement( 'tbody' ); var eventListBody = $(eventList).getElement( 'tbody' );
@ -518,6 +530,8 @@ function getEventCmdResponse( respText )
rows[rows.length-1].remove(); rows[rows.length-1].remove();
rows.length--; rows.length--;
} }
}
var eventCmdTimeout = eventsRefreshTimeout; var eventCmdTimeout = eventsRefreshTimeout;
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT )
eventCmdTimeout = eventCmdTimeout/5; eventCmdTimeout = eventCmdTimeout/5;
@ -539,8 +553,7 @@ function getControlResponse( respText )
return; return;
//console.log( respText ); //console.log( respText );
var response = Json.evaluate( respText ); var response = Json.evaluate( respText );
result = response.result; if ( response.result != 'Ok' )
if ( result != 'Ok' )
{ {
alert( "Control response was status = "+response.status+"\nmessage = "+response.message ); alert( "Control response was status = "+response.status+"\nmessage = "+response.message );
} }
@ -627,11 +640,11 @@ function handleClick( event )
function initPage() function initPage()
{ {
if ( streamMode == "single" ) if ( streamMode == "single" )
statusCmdTimer = statusCmdQuery.delay( 1000 ); statusCmdTimer = statusCmdQuery.delay( (Math.random()+0.5)*statusRefreshTimeout );
else else
streamCmdTimer = streamCmdQuery.delay( 1000 ); streamCmdTimer = streamCmdQuery.delay( (Math.random()+0.5)*statusRefreshTimeout );
eventCmdTimer = eventCmdQuery.delay( 1500 ); eventCmdTimer = eventCmdQuery.delay( (Math.random()+0.5)*eventsRefreshTimeout );
if ( canStreamNative || streamMode == "single" ) if ( canStreamNative || streamMode == "single" )
{ {