2008-07-14 21:54:50 +08:00
|
|
|
function setButtonState( element, butClass )
|
|
|
|
{
|
|
|
|
element.className = butClass;
|
|
|
|
element.disabled = (butClass != 'inactive');
|
|
|
|
}
|
|
|
|
|
|
|
|
function showEvents()
|
|
|
|
{
|
|
|
|
$('ptzControls').addClass( 'hidden' );
|
|
|
|
$('events').removeClass( 'hidden' );
|
|
|
|
if ( $('eventsControl') )
|
|
|
|
$('eventsControl').addClass('hidden');
|
|
|
|
if ( $('controlControl') )
|
|
|
|
$('controlControl').removeClass('hidden');
|
|
|
|
showMode = "events";
|
|
|
|
}
|
|
|
|
|
2008-12-06 02:46:32 +08:00
|
|
|
function showPtzControls()
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
|
|
|
$('events').addClass( 'hidden' );
|
|
|
|
$('ptzControls').removeClass( 'hidden' );
|
|
|
|
if ( $('eventsControl') )
|
|
|
|
$('eventsControl').removeClass('hidden');
|
|
|
|
if ( $('controlControl') )
|
|
|
|
$('controlControl').addClass('hidden');
|
|
|
|
showMode = "control";
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeScale()
|
|
|
|
{
|
|
|
|
var scale = $('scale').getValue();
|
|
|
|
var newWidth = ( monitorWidth * scale ) / SCALE_BASE;
|
|
|
|
var newHeight = ( monitorHeight * scale ) / SCALE_BASE;
|
|
|
|
|
|
|
|
streamCmdScale( scale );
|
|
|
|
|
|
|
|
var streamImg = $('imageFeed').getElement('img');
|
|
|
|
if ( !streamImg )
|
|
|
|
streamImg = $('imageFeed').getElement('object');
|
|
|
|
streamImg.setStyles( { width: newWidth, height: newHeight } );
|
|
|
|
}
|
|
|
|
|
|
|
|
var alarmState = STATE_IDLE;
|
|
|
|
var lastAlarmState = STATE_IDLE;
|
|
|
|
|
2008-07-16 23:47:33 +08:00
|
|
|
function setAlarmState( currentAlarmState )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2008-07-16 23:47:33 +08:00
|
|
|
alarmState = currentAlarmState;
|
2008-07-14 21:54:50 +08:00
|
|
|
|
|
|
|
var stateString = "Unknown";
|
|
|
|
var stateClass = "";
|
|
|
|
if ( alarmState == STATE_ALARM )
|
|
|
|
stateClass = "alarm";
|
|
|
|
else if ( alarmState == STATE_ALERT )
|
|
|
|
stateClass = "alert";
|
2009-03-28 00:01:59 +08:00
|
|
|
$('stateValue').set( 'text', stateStrings[alarmState] );
|
2008-07-14 21:54:50 +08:00
|
|
|
if ( stateClass )
|
|
|
|
$('stateValue').setProperty( 'class', stateClass );
|
|
|
|
else
|
|
|
|
$('stateValue').removeProperty( 'class' );
|
|
|
|
|
2008-07-16 23:47:33 +08:00
|
|
|
var isAlarmed = ( alarmState == STATE_ALARM || alarmState == STATE_ALERT );
|
|
|
|
var wasAlarmed = ( lastAlarmState == STATE_ALARM || lastAlarmState == STATE_ALERT );
|
|
|
|
|
|
|
|
var newAlarm = ( isAlarmed && !wasAlarmed );
|
|
|
|
var oldAlarm = ( !isAlarmed && wasAlarmed );
|
|
|
|
|
|
|
|
if ( newAlarm )
|
|
|
|
{
|
|
|
|
if ( SOUND_ON_ALARM )
|
|
|
|
{
|
|
|
|
// Enable the alarm sound
|
|
|
|
$('alarmSound').removeClass( 'hidden' );
|
|
|
|
}
|
|
|
|
if ( POPUP_ON_ALARM )
|
|
|
|
{
|
|
|
|
window.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( SOUND_ON_ALARM )
|
|
|
|
{
|
|
|
|
if ( oldAlarm )
|
|
|
|
{
|
|
|
|
// Disable alarm sound
|
|
|
|
$('alarmSound').addClass( 'hidden' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastAlarmState = alarmState;
|
|
|
|
}
|
|
|
|
|
|
|
|
var streamCmdParms = "view=request&request=stream&connkey="+connKey;
|
2009-03-28 00:01:59 +08:00
|
|
|
var streamCmdReq = new Request.JSON( { url: thisUrl, method: 'post', timeout: AJAX_TIMEOUT, onSuccess: getStreamCmdResponse } );
|
2008-07-16 23:47:33 +08:00
|
|
|
var streamCmdTimer = null;
|
|
|
|
|
|
|
|
var streamStatus;
|
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
function getStreamCmdResponse( respObj, respText )
|
2008-07-16 23:47:33 +08:00
|
|
|
{
|
|
|
|
if ( streamCmdTimer )
|
|
|
|
streamCmdTimer = $clear( streamCmdTimer );
|
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
if ( respObj.result == 'Ok' )
|
2008-12-06 07:58:58 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
streamStatus = respObj.status;
|
|
|
|
$('fpsValue').set( 'text', streamStatus.fps );
|
2008-07-16 23:47:33 +08:00
|
|
|
|
2008-12-06 07:58:58 +08:00
|
|
|
setAlarmState( streamStatus.state );
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
$('levelValue').set( 'text', streamStatus.level );
|
2008-12-06 07:58:58 +08:00
|
|
|
if ( streamStatus.level > 95 )
|
|
|
|
$('levelValue').className = "alarm";
|
|
|
|
else if ( streamStatus.level > 80 )
|
|
|
|
$('levelValue').className = "alert";
|
|
|
|
else
|
|
|
|
$('levelValue').className = "ok";
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2008-12-06 07:58:58 +08:00
|
|
|
var delayString = secsToTime( streamStatus.delay );
|
|
|
|
|
|
|
|
if ( streamStatus.paused == true )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
$('modeValue').set( 'text', "Paused" );
|
2008-12-06 07:58:58 +08:00
|
|
|
$('rate').addClass( 'hidden' );
|
2009-03-28 00:01:59 +08:00
|
|
|
$('delayValue').set( 'text', delayString );
|
2008-12-06 07:58:58 +08:00
|
|
|
$('delay').removeClass( 'hidden' );
|
|
|
|
$('level').removeClass( 'hidden' );
|
|
|
|
streamCmdPause( false );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2008-12-06 07:58:58 +08:00
|
|
|
else if ( streamStatus.delayed == true )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
$('modeValue').set( 'text', "Replay" );
|
|
|
|
$('rateValue').set( 'text', streamStatus.rate );
|
2008-12-06 07:58:58 +08:00
|
|
|
$('rate').removeClass( 'hidden' );
|
2009-03-28 00:01:59 +08:00
|
|
|
$('delayValue').set( 'text', delayString );
|
2008-12-06 07:58:58 +08:00
|
|
|
$('delay').removeClass( 'hidden' );
|
|
|
|
$('level').removeClass( 'hidden' );
|
|
|
|
if ( streamStatus.rate == 1 )
|
|
|
|
{
|
|
|
|
streamCmdPlay( false );
|
|
|
|
}
|
|
|
|
else if ( streamStatus.rate > 0 )
|
|
|
|
{
|
|
|
|
if ( streamStatus.rate < 1 )
|
|
|
|
streamCmdSlowFwd( false );
|
|
|
|
else
|
|
|
|
streamCmdFastFwd( false );
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
else
|
2008-12-06 07:58:58 +08:00
|
|
|
{
|
|
|
|
if ( streamStatus.rate > -1 )
|
|
|
|
streamCmdSlowRev( false );
|
|
|
|
else
|
|
|
|
streamCmdFastRev( false );
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2008-12-06 07:58:58 +08:00
|
|
|
else
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
$('modeValue').set( 'text', "Live" );
|
2008-12-06 07:58:58 +08:00
|
|
|
$('rate').addClass( 'hidden' );
|
|
|
|
$('delay').addClass( 'hidden' );
|
|
|
|
$('level').addClass( 'hidden' );
|
|
|
|
streamCmdPlay( false );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2009-03-28 00:01:59 +08:00
|
|
|
$('zoomValue').set( 'text', streamStatus.zoom );
|
2008-12-06 07:58:58 +08:00
|
|
|
if ( streamStatus.zoom == "1.0" )
|
|
|
|
setButtonState( $('zoomOutBtn'), 'unavail' );
|
|
|
|
else
|
|
|
|
setButtonState( $('zoomOutBtn'), 'inactive' );
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2008-12-06 07:58:58 +08:00
|
|
|
if ( canEditMonitors )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2008-12-06 07:58:58 +08:00
|
|
|
if ( streamStatus.enabled )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2008-12-06 07:58:58 +08:00
|
|
|
$('enableAlarmsLink').addClass( 'hidden' );
|
|
|
|
$('disableAlarmsLink').removeClass( 'hidden' );
|
|
|
|
if ( streamStatus.forced )
|
|
|
|
{
|
|
|
|
$('forceAlarmLink').addClass( 'hidden' );
|
|
|
|
$('cancelAlarmLink').removeClass( 'hidden' );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$('forceAlarmLink').removeClass( 'hidden' );
|
|
|
|
$('cancelAlarmLink').addClass( 'hidden' );
|
|
|
|
}
|
|
|
|
$('forceCancelAlarm').removeClass( 'hidden' );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-06 07:58:58 +08:00
|
|
|
$('enableAlarmsLink').removeClass( 'hidden' );
|
|
|
|
$('disableAlarmsLink').addClass( 'hidden' );
|
|
|
|
$('forceCancelAlarm').addClass( 'hidden' );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2008-12-06 07:58:58 +08:00
|
|
|
$('enableDisableAlarms').removeClass( 'hidden' );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-06 07:58:58 +08:00
|
|
|
$('enableDisableAlarms').addClass( 'hidden' );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var streamCmdTimeout = statusRefreshTimeout;
|
|
|
|
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT )
|
|
|
|
streamCmdTimeout = streamCmdTimeout/5;
|
|
|
|
streamCmdTimer = streamCmdQuery.delay( streamCmdTimeout );
|
2008-07-16 23:47:33 +08:00
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
|
|
|
|
function streamCmdPause( action )
|
|
|
|
{
|
|
|
|
setButtonState( $('pauseBtn'), 'active' );
|
|
|
|
setButtonState( $('playBtn'), 'inactive' );
|
|
|
|
setButtonState( $('stopBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowRevBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastRevBtn'), 'inactive' );
|
|
|
|
if ( action )
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_PAUSE );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdPlay( action )
|
|
|
|
{
|
|
|
|
setButtonState( $('pauseBtn'), 'inactive' );
|
|
|
|
setButtonState( $('playBtn'), 'active' );
|
2008-07-16 23:47:33 +08:00
|
|
|
if ( streamStatus.delayed == true )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
|
|
|
setButtonState( $('stopBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowRevBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastRevBtn'), 'inactive' );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setButtonState( $('stopBtn'), 'unavail' );
|
|
|
|
setButtonState( $('fastFwdBtn'), 'unavail' );
|
|
|
|
setButtonState( $('slowFwdBtn'), 'unavail' );
|
|
|
|
setButtonState( $('slowRevBtn'), 'unavail' );
|
|
|
|
setButtonState( $('fastRevBtn'), 'unavail' );
|
|
|
|
}
|
|
|
|
if ( action )
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_PLAY );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdStop( action )
|
|
|
|
{
|
|
|
|
setButtonState( $('pauseBtn'), 'inactive' );
|
|
|
|
setButtonState( $('playBtn'), 'unavail' );
|
|
|
|
setButtonState( $('stopBtn'), 'active' );
|
|
|
|
setButtonState( $('fastFwdBtn'), 'unavail' );
|
|
|
|
setButtonState( $('slowFwdBtn'), 'unavail' );
|
|
|
|
setButtonState( $('slowRevBtn'), 'unavail' );
|
|
|
|
setButtonState( $('fastRevBtn'), 'unavail' );
|
|
|
|
if ( action )
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_STOP );
|
2008-07-14 21:54:50 +08:00
|
|
|
setButtonState( $('stopBtn'), 'unavail' );
|
|
|
|
setButtonState( $('playBtn'), 'active' );
|
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdFastFwd( action )
|
|
|
|
{
|
|
|
|
setButtonState( $('pauseBtn'), 'inactive' );
|
|
|
|
setButtonState( $('playBtn'), 'inactive' );
|
|
|
|
setButtonState( $('stopBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowRevBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastRevBtn'), 'inactive' );
|
|
|
|
if ( action )
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_FASTFWD );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdSlowFwd( action )
|
|
|
|
{
|
|
|
|
setButtonState( $('pauseBtn'), 'inactive' );
|
|
|
|
setButtonState( $('playBtn'), 'inactive' );
|
|
|
|
setButtonState( $('stopBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowFwdBtn'), 'active' );
|
|
|
|
setButtonState( $('slowRevBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastRevBtn'), 'inactive' );
|
|
|
|
if ( action )
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_SLOWFWD );
|
2008-07-14 21:54:50 +08:00
|
|
|
setButtonState( $('pauseBtn'), 'active' );
|
|
|
|
setButtonState( $('slowFwdBtn'), 'inactive' );
|
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdSlowRev( action )
|
|
|
|
{
|
|
|
|
setButtonState( $('pauseBtn'), 'inactive' );
|
|
|
|
setButtonState( $('playBtn'), 'inactive' );
|
|
|
|
setButtonState( $('stopBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowRevBtn'), 'active' );
|
|
|
|
setButtonState( $('fastRevBtn'), 'inactive' );
|
|
|
|
if ( action )
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_SLOWREV );
|
2008-07-14 21:54:50 +08:00
|
|
|
setButtonState( $('pauseBtn'), 'active' );
|
|
|
|
setButtonState( $('slowRevBtn'), 'inactive' );
|
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdFastRev( action )
|
|
|
|
{
|
|
|
|
setButtonState( $('pauseBtn'), 'inactive' );
|
|
|
|
setButtonState( $('playBtn'), 'inactive' );
|
|
|
|
setButtonState( $('stopBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowFwdBtn'), 'inactive' );
|
|
|
|
setButtonState( $('slowRevBtn'), 'inactive' );
|
|
|
|
setButtonState( $('fastRevBtn'), 'inactive' );
|
|
|
|
if ( action )
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_FASTREV );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdZoomIn( x, y )
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_ZOOMIN+"&x="+x+"&y="+y );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdZoomOut()
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_ZOOMOUT );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdScale( scale )
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_SCALE+"&scale="+scale );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdPan( x, y )
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_PAN+"&x="+x+"&y="+y );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function streamCmdQuery()
|
2008-07-16 23:47:33 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
streamCmdReq.send( streamCmdParms+"&command="+CMD_QUERY );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2008-07-16 23:47:33 +08:00
|
|
|
var statusCmdParms = "view=request&request=status&entity=monitor&id="+monitorId+"&element[]=Status&element[]=FrameRate";
|
2009-03-28 00:01:59 +08:00
|
|
|
var statusCmdReq = new Request.JSON( { url: thisUrl, method: 'post', data: statusCmdParms, timeout: AJAX_TIMEOUT, onSuccess: getStatusCmdResponse } );
|
2008-07-16 23:47:33 +08:00
|
|
|
var statusCmdTimer = null;
|
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
function getStatusCmdResponse( respObj, respText )
|
2008-07-16 23:47:33 +08:00
|
|
|
{
|
|
|
|
if ( statusCmdTimer )
|
|
|
|
statusCmdTimer = $clear( statusCmdTimer );
|
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
if ( respObj.result == 'Ok' )
|
2008-12-06 07:58:58 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
$('fpsValue').set( 'text', respObj.monitor.FrameRate );
|
|
|
|
setAlarmState( respObj.monitor.Status );
|
2008-12-06 07:58:58 +08:00
|
|
|
}
|
2008-07-16 23:47:33 +08:00
|
|
|
|
|
|
|
var statusCmdTimeout = statusRefreshTimeout;
|
|
|
|
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT )
|
|
|
|
statusCmdTimeout = statusCmdTimeout/5;
|
|
|
|
statusCmdTimer = statusCmdQuery.delay( statusCmdTimeout );
|
|
|
|
}
|
|
|
|
|
|
|
|
function statusCmdQuery()
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
statusCmdReq.send();
|
2008-07-16 23:47:33 +08:00
|
|
|
}
|
|
|
|
|
2008-07-14 21:54:50 +08:00
|
|
|
var alarmCmdParms = "view=request&request=alarm&id="+monitorId;
|
2009-03-28 00:01:59 +08:00
|
|
|
var alarmCmdReq = new Request.JSON( { url: thisUrl, method: 'post', timeout: AJAX_TIMEOUT, onSuccess: getAlarmCmdResponse, onTimeout: streamCmdQuery } );
|
2008-07-14 21:54:50 +08:00
|
|
|
var alarmCmdFirst = true;
|
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
function getAlarmCmdResponse( respObj, respText )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
function cmdDisableAlarms()
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
alarmCmdReq.send( alarmCmdParms+"&command=disableAlarms" );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function cmdEnableAlarms()
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
alarmCmdReq.send( alarmCmdParms+"&command=enableAlarms" );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function cmdForceAlarm()
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
alarmCmdReq.send( alarmCmdParms+"&command=forceAlarm" );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function cmdCancelForcedAlarm()
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
alarmCmdReq.send( alarmCmdParms+"&command=cancelForcedAlarm" );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
function getActResponse( respObj, respText )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
if ( respObj.result == 'Ok' )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
if ( respObj.refreshParent )
|
2008-12-06 07:58:58 +08:00
|
|
|
{
|
|
|
|
window.opener.location.reload();
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
eventCmdQuery();
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteEvent( event, eventId )
|
|
|
|
{
|
|
|
|
var actParms = "view=request&request=event&action=delete&id="+eventId;
|
2009-03-28 00:01:59 +08:00
|
|
|
var actReq = new Request.JSON( { url: thisUrl, method: 'post', timeout: 3000, data: actParms, onSuccess: getActResponse } );
|
|
|
|
actReq.send();
|
2008-07-14 21:54:50 +08:00
|
|
|
event.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
var eventCmdParms = "view=request&request=status&entity=events&id="+monitorId+"&count="+maxDisplayEvents+"&sort=Id%20desc";
|
2009-03-28 00:01:59 +08:00
|
|
|
var eventCmdReq = new Request.JSON( { url: thisUrl, method: 'post', timeout: AJAX_TIMEOUT, data: eventCmdParms, onSuccess: getEventCmdResponse, onTimeout: eventCmdQuery } );
|
2008-07-14 21:54:50 +08:00
|
|
|
var eventCmdTimer = null;
|
|
|
|
var eventCmdFirst = true;
|
|
|
|
|
|
|
|
function highlightRow( row )
|
|
|
|
{
|
|
|
|
$(row).toggleClass( 'highlight' );
|
|
|
|
}
|
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
function getEventCmdResponse( respObj, respText )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
|
|
|
if ( eventCmdTimer )
|
|
|
|
eventCmdTimer = $clear( eventCmdTimer );
|
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
if ( respObj.result == 'Ok' )
|
2008-12-06 07:58:58 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
var dbEvents = respObj.events.reverse();
|
2008-12-06 07:58:58 +08:00
|
|
|
var eventList = $('eventList');
|
|
|
|
var eventListBody = $(eventList).getElement( 'tbody' );
|
|
|
|
var eventListRows = $(eventListBody).getElements( 'tr' );
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2008-12-06 07:58:58 +08:00
|
|
|
eventListRows.each( function( row ) { row.removeClass( 'updated' ); } );
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2008-12-06 07:58:58 +08:00
|
|
|
for ( var i = 0; i < dbEvents.length; i++ )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2008-12-06 07:58:58 +08:00
|
|
|
var event = dbEvents[i];
|
|
|
|
var row = $('event'+event.Id);
|
|
|
|
var newEvent = (row == null ? true : false);
|
|
|
|
if ( newEvent )
|
|
|
|
{
|
|
|
|
row = new Element( 'tr', { 'id': 'event'+event.Id } );
|
|
|
|
new Element( 'td', { 'class': 'colId' } ).injectInside( row );
|
|
|
|
new Element( 'td', { 'class': 'colName' } ).injectInside( row );
|
|
|
|
new Element( 'td', { 'class': 'colTime' } ).injectInside( row );
|
|
|
|
new Element( 'td', { 'class': 'colSecs' } ).injectInside( row );
|
|
|
|
new Element( 'td', { 'class': 'colFrames' } ).injectInside( row );
|
|
|
|
new Element( 'td', { 'class': 'colScore' } ).injectInside( row );
|
|
|
|
new Element( 'td', { 'class': 'colDelete' } ).injectInside( row );
|
|
|
|
|
|
|
|
var cells = row.getElements( 'td' );
|
|
|
|
|
|
|
|
var link = new Element( 'a', { 'href': '#', 'events': { 'click': createEventPopup.pass( [ event.Id, '&trms=1&attr1=MonitorId&op1=%3d&val1='+monitorId+'&page=1', event.Width, event.Height ] ) } });
|
2009-03-28 00:01:59 +08:00
|
|
|
link.set( 'text', event.Id );
|
2008-12-06 07:58:58 +08:00
|
|
|
link.injectInside( row.getElement( 'td.colId' ) );
|
|
|
|
|
|
|
|
link = new Element( 'a', { 'href': '#', 'events': { 'click': createEventPopup.pass( [ event.Id, '&trms=1&attr1=MonitorId&op1=%3d&val1='+monitorId+'&page=1', event.Width, event.Height ] ) } });
|
2009-03-28 00:01:59 +08:00
|
|
|
link.set( 'text', event.Name );
|
2008-12-06 07:58:58 +08:00
|
|
|
link.injectInside( row.getElement( 'td.colName' ) );
|
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
row.getElement( 'td.colTime' ).set( 'text', event.StartTime );
|
|
|
|
row.getElement( 'td.colSecs' ).set( 'text', event.Length );
|
2008-12-06 07:58:58 +08:00
|
|
|
|
|
|
|
link = new Element( 'a', { 'href': '#', 'events': { 'click': createFramesPopup.pass( [ event.Id, event.Width, event.Height ] ) } });
|
2009-03-28 00:01:59 +08:00
|
|
|
link.set( 'text', event.Frames+'/'+event.AlarmFrames );
|
2008-12-06 07:58:58 +08:00
|
|
|
link.injectInside( row.getElement( 'td.colFrames' ) );
|
|
|
|
|
|
|
|
link = new Element( 'a', { 'href': '#', 'events': { 'click': createFramePopup.pass( [ event.Id, '0', event.Width, event.Height ] ) } });
|
2009-03-28 00:01:59 +08:00
|
|
|
link.set( 'text', event.AvgScore+'/'+event.MaxScore );
|
2008-12-06 07:58:58 +08:00
|
|
|
link.injectInside( row.getElement( 'td.colScore' ) );
|
|
|
|
|
|
|
|
link = new Element( 'a', { 'href': '#', 'title': deleteString, 'events': { 'click': deleteEvent.bindWithEvent( link, event.Id ), 'mouseover': highlightRow.pass( row ), 'mouseout': highlightRow.pass( row ) } });
|
2009-03-28 00:01:59 +08:00
|
|
|
link.set( 'text', 'X' );
|
2008-12-06 07:58:58 +08:00
|
|
|
link.injectInside( row.getElement( 'td.colDelete' ) );
|
|
|
|
|
|
|
|
if ( i == 0 )
|
|
|
|
row.injectInside( $(eventListBody) );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
row.injectTop( $(eventListBody) );
|
|
|
|
if ( !eventCmdFirst )
|
|
|
|
row.addClass( 'recent' );
|
|
|
|
}
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
else
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
row.getElement( 'td.colName a' ).set( 'text', event.Name );
|
|
|
|
row.getElement( 'td.colSecs' ).set( 'text', event.Length );
|
|
|
|
row.getElement( 'td.colFrames a' ).set( 'text', event.Frames+'/'+event.AlarmFrames );
|
|
|
|
row.getElement( 'td.colScore a' ).set( 'text', event.AvgScore+'/'+event.MaxScore );
|
2008-12-06 07:58:58 +08:00
|
|
|
row.removeClass( 'recent' );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2008-12-06 07:58:58 +08:00
|
|
|
row.addClass( 'updated' );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2008-12-06 07:58:58 +08:00
|
|
|
|
|
|
|
var rows = $(eventListBody).getElements( 'tr' );
|
|
|
|
for ( var i = 0; i < rows.length; i++ )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2008-12-06 07:58:58 +08:00
|
|
|
if ( !rows[i].hasClass( 'updated' ) )
|
|
|
|
{
|
|
|
|
rows[i].remove();
|
|
|
|
rows.splice( i, 1 );
|
|
|
|
i--;
|
|
|
|
}
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
2008-12-06 07:58:58 +08:00
|
|
|
while ( rows.length > maxDisplayEvents )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2008-12-06 07:58:58 +08:00
|
|
|
rows[rows.length-1].remove();
|
|
|
|
rows.length--;
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
}
|
2008-12-06 07:58:58 +08:00
|
|
|
|
2008-07-14 21:54:50 +08:00
|
|
|
var eventCmdTimeout = eventsRefreshTimeout;
|
|
|
|
if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT )
|
|
|
|
eventCmdTimeout = eventCmdTimeout/5;
|
|
|
|
eventCmdTimer = eventCmdQuery.delay( eventCmdTimeout );
|
|
|
|
eventCmdFirst = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function eventCmdQuery()
|
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
eventCmdReq.send();
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var controlParms = "view=request&request=control&id="+monitorId;
|
2009-03-28 00:01:59 +08:00
|
|
|
var controlReq = new Request.JSON( { url: thisUrl, method: 'post', timeout: AJAX_TIMEOUT, onSuccess: getControlResponse } );
|
2008-07-14 21:54:50 +08:00
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
function getControlResponse( respObj, respText )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
if ( !respObj )
|
2008-07-14 21:54:50 +08:00
|
|
|
return;
|
|
|
|
//console.log( respText );
|
2009-03-28 00:01:59 +08:00
|
|
|
if ( respObj.result != 'Ok' )
|
2008-07-14 21:54:50 +08:00
|
|
|
{
|
2009-03-28 00:01:59 +08:00
|
|
|
alert( "Control response was status = "+respObj.status+"\nmessage = "+respObj.message );
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function controlCmd( control, event, xtell, ytell )
|
|
|
|
{
|
|
|
|
var locParms = "";
|
|
|
|
if ( event && (xtell || ytell) )
|
|
|
|
{
|
|
|
|
var xEvent = new Event( event );
|
|
|
|
var target = xEvent.target;
|
|
|
|
var coords = $(target).getCoordinates();
|
|
|
|
|
|
|
|
var l = coords.left;
|
|
|
|
var t = coords.top;
|
|
|
|
var x = xEvent.page.x - l;
|
|
|
|
var y = xEvent.page.y - t;
|
|
|
|
|
|
|
|
if ( xtell )
|
|
|
|
{
|
|
|
|
var xge = parseInt( (x*100)/coords.width );
|
|
|
|
if ( xtell == -1 )
|
|
|
|
xge = 100 - xge;
|
|
|
|
else if ( xtell == 2 )
|
|
|
|
xge = 2*(50 - xge);
|
|
|
|
locParms += "&xge="+xge;
|
|
|
|
}
|
|
|
|
if ( ytell )
|
|
|
|
{
|
|
|
|
var yge = parseInt( (y*100)/coords.height );
|
|
|
|
if ( ytell == -1 )
|
|
|
|
yge = 100 - yge;
|
|
|
|
else if ( ytell == 2 )
|
|
|
|
yge = 2*(50 - yge);
|
|
|
|
locParms += "&yge="+yge;
|
|
|
|
}
|
|
|
|
}
|
2009-03-28 00:01:59 +08:00
|
|
|
controlReq.send( controlParms+"&control="+control+locParms );
|
2008-07-14 21:54:50 +08:00
|
|
|
if ( streamMode == "single" )
|
|
|
|
fetchImage.pass( $('imageFeed').getElement('img') ).delay( 1000 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function controlCmdImage( x, y )
|
|
|
|
{
|
|
|
|
var imageControlParms = controlParms;
|
|
|
|
imageControlParms += "&scale="+scale;
|
|
|
|
imageControlParms += "&control="+imageControlMode;
|
|
|
|
|
2009-03-28 00:01:59 +08:00
|
|
|
controlReq.send( imageControlParms+"&x="+x+"&y="+y );
|
2008-07-14 21:54:50 +08:00
|
|
|
if ( streamMode == "single" )
|
|
|
|
fetchImage.pass( $('imageFeed').getElement('img') ).delay( 1000 );
|
|
|
|
}
|
|
|
|
|
|
|
|
var tempImage = null;
|
|
|
|
function fetchImage( streamImage )
|
|
|
|
{
|
|
|
|
var now = new Date();
|
|
|
|
if ( !tempImage )
|
|
|
|
tempImage = new Element( 'img' );
|
|
|
|
tempImage.setProperty( 'src', streamSrc+'&'+now.getTime() );
|
|
|
|
$(streamImage).setProperty( 'src', tempImage.getProperty( 'src' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleClick( event )
|
|
|
|
{
|
|
|
|
var target = event.target;
|
|
|
|
var x = event.page.x - $(target).getLeft();
|
|
|
|
var y = event.page.y - $(target).getTop();
|
|
|
|
|
|
|
|
if ( showMode == "events" || !imageControlMode )
|
|
|
|
{
|
|
|
|
if ( event.shift )
|
|
|
|
streamCmdPan( x, y );
|
|
|
|
else
|
|
|
|
streamCmdZoomIn( x, y );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
controlCmdImage( x, y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initPage()
|
|
|
|
{
|
2008-07-16 23:47:33 +08:00
|
|
|
if ( streamMode == "single" )
|
2009-01-28 22:14:41 +08:00
|
|
|
statusCmdTimer = statusCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout );
|
2008-07-16 23:47:33 +08:00
|
|
|
else
|
2009-01-28 22:14:41 +08:00
|
|
|
streamCmdTimer = streamCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout );
|
2008-07-16 23:47:33 +08:00
|
|
|
|
2009-01-28 22:14:41 +08:00
|
|
|
eventCmdTimer = eventCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout );
|
2008-07-14 21:54:50 +08:00
|
|
|
|
|
|
|
if ( canStreamNative || streamMode == "single" )
|
|
|
|
{
|
|
|
|
var streamImg = $('imageFeed').getElement('img');
|
|
|
|
if ( !streamImg )
|
|
|
|
streamImg = $('imageFeed').getElement('object');
|
|
|
|
$(streamImg).addEvent( 'click', handleClick.bindWithEvent( $(streamImg) ) );
|
|
|
|
if ( streamMode == "single" )
|
|
|
|
fetchImage.pass( streamImg ).periodical( imageRefreshTimeout );
|
|
|
|
}
|
2008-07-16 23:47:33 +08:00
|
|
|
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Kick everything off
|
|
|
|
window.addEvent( 'domready', initPage );
|