diff --git a/web/includes/functions.php b/web/includes/functions.php index 8791c2dc5..5d7e077fc 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -331,12 +331,12 @@ function getVideoStreamHTML( $id, $src, $width, $height, $format, $title="" ) { '; } -function outputImageStream( $id, $src, $width, $height, $title="" ) { +function outputImageStream( $id, $src, $width, $height, $title='' ) { echo getImageStream( $id, $src, $width, $height, $title ); } -function getImageStream( $id, $src, $width, $height, $title="" ) { +function getImageStream( $id, $src, $width, $height, $title='' ) { if ( canStreamIframe() ) { return ''; } else { diff --git a/web/index.php b/web/index.php index 6523b3c46..2aa801b29 100644 --- a/web/index.php +++ b/web/index.php @@ -175,9 +175,9 @@ foreach ( getSkinIncludes( 'skin.php' ) as $includeFile ) if ( ZM_OPT_USE_AUTH && ZM_AUTH_HASH_LOGINS ) { if ( empty($user) && ! empty($_REQUEST['auth']) ) { -Debug("Getting user from auth hash"); +Logger::Debug("Getting user from auth hash"); if ( $authUser = getAuthUser( $_REQUEST['auth'] ) ) { -Debug("Success Getting user from auth hash"); +Logger::Debug("Success Getting user from auth hash"); userLogin( $authUser['Username'], $authUser['Password'], true ); } } else if ( ! empty($user) ) { @@ -205,7 +205,7 @@ require_once( 'includes/actions.php' ); # If I put this here, it protects all views and popups, but it has to go after actions.php because actions.php does the actual logging in. if ( ZM_OPT_USE_AUTH && ! isset($user) ) { - Debug("Redirecting to login" ); + Logger::Debug("Redirecting to login" ); $view = 'login'; } diff --git a/web/skins/classic/css/classic/control.css b/web/skins/classic/css/classic/control.css index 737191cd7..320d391e4 100644 --- a/web/skins/classic/css/classic/control.css +++ b/web/skins/classic/css/classic/control.css @@ -45,11 +45,11 @@ */ .ptzControls .controlsPanel .upBtn { - background: url("../../graphics/arrow-l-u.gif") no-repeat 0 0; + background: url("../../graphics/arrow-l-u.png") no-repeat 0 0; } .ptzControls .controlsPanel .downBtn { - background: url("../../graphics/arrow-l-d.gif") no-repeat 0 0; + background: url("../../graphics/arrow-l-d.png") no-repeat 0 0; } .ptzControls .controlsPanel .focusControls { @@ -92,39 +92,39 @@ } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .upLeftBtn { - background: url("../../graphics/arrow-ul.gif") no-repeat 0 0; + background: url("../../graphics/arrow-ul.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .upBtn { - background: url("../../graphics/arrow-u.gif") no-repeat 0 0; + background: url("../../graphics/arrow-u.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .upRightBtn { - background: url("../../graphics/arrow-ur.gif") no-repeat 0 0; + background: url("../../graphics/arrow-ur.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .leftBtn { - background: url("../../graphics/arrow-l.gif") no-repeat 0 0; + background: url("../../graphics/arrow-l.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .centerBtn { - background: url("../../graphics/center.gif") no-repeat 0 0; + background: url("../../graphics/center.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .rightBtn { - background: url("../../graphics/arrow-r.gif") no-repeat 0 0; + background: url("../../graphics/arrow-r.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .downLeftBtn { - background: url("../../graphics/arrow-dl.gif") no-repeat 0 0; + background: url("../../graphics/arrow-dl.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .downBtn { - background: url("../../graphics/arrow-d.gif") no-repeat 0 0; + background: url("../../graphics/arrow-d.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .downRightBtn { - background: url("../../graphics/arrow-dr.gif") no-repeat 0 0; + background: url("../../graphics/arrow-dr.png") no-repeat 0 0; } .ptzControls .controlsPanel .powerControls { diff --git a/web/skins/classic/css/dark/control.css b/web/skins/classic/css/dark/control.css index cd404583c..56fc0e41c 100644 --- a/web/skins/classic/css/dark/control.css +++ b/web/skins/classic/css/dark/control.css @@ -45,11 +45,11 @@ */ .ptzControls .controlsPanel .upBtn { - background: url("../../graphics/arrow-l-u.gif") no-repeat 0 0; + background: url("../../graphics/arrow-l-u.png") no-repeat 0 0; } .ptzControls .controlsPanel .downBtn { - background: url("../../graphics/arrow-l-d.gif") no-repeat 0 0; + background: url("../../graphics/arrow-l-d.png") no-repeat 0 0; } .ptzControls .controlsPanel .focusControls { @@ -92,39 +92,39 @@ } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .upLeftBtn { - background: url("../../graphics/arrow-ul.gif") no-repeat 0 0; + background: url("../../graphics/arrow-ul.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .upBtn { - background: url("../../graphics/arrow-u.gif") no-repeat 0 0; + background: url("../../graphics/arrow-u.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .upRightBtn { - background: url("../../graphics/arrow-ur.gif") no-repeat 0 0; + background: url("../../graphics/arrow-ur.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .leftBtn { - background: url("../../graphics/arrow-l.gif") no-repeat 0 0; + background: url("../../graphics/arrow-l.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .centerBtn { - background: url("../../graphics/center.gif") no-repeat 0 0; + background: url("../../graphics/center.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .rightBtn { - background: url("../../graphics/arrow-r.gif") no-repeat 0 0; + background: url("../../graphics/arrow-r.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .downLeftBtn { - background: url("../../graphics/arrow-dl.gif") no-repeat 0 0; + background: url("../../graphics/arrow-dl.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .downBtn { - background: url("../../graphics/arrow-d.gif") no-repeat 0 0; + background: url("../../graphics/arrow-d.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .downRightBtn { - background: url("../../graphics/arrow-dr.gif") no-repeat 0 0; + background: url("../../graphics/arrow-dr.png") no-repeat 0 0; } .ptzControls .controlsPanel .powerControls { diff --git a/web/skins/classic/css/flat/control.css b/web/skins/classic/css/flat/control.css index cd404583c..56fc0e41c 100644 --- a/web/skins/classic/css/flat/control.css +++ b/web/skins/classic/css/flat/control.css @@ -45,11 +45,11 @@ */ .ptzControls .controlsPanel .upBtn { - background: url("../../graphics/arrow-l-u.gif") no-repeat 0 0; + background: url("../../graphics/arrow-l-u.png") no-repeat 0 0; } .ptzControls .controlsPanel .downBtn { - background: url("../../graphics/arrow-l-d.gif") no-repeat 0 0; + background: url("../../graphics/arrow-l-d.png") no-repeat 0 0; } .ptzControls .controlsPanel .focusControls { @@ -92,39 +92,39 @@ } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .upLeftBtn { - background: url("../../graphics/arrow-ul.gif") no-repeat 0 0; + background: url("../../graphics/arrow-ul.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .upBtn { - background: url("../../graphics/arrow-u.gif") no-repeat 0 0; + background: url("../../graphics/arrow-u.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .upRightBtn { - background: url("../../graphics/arrow-ur.gif") no-repeat 0 0; + background: url("../../graphics/arrow-ur.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .leftBtn { - background: url("../../graphics/arrow-l.gif") no-repeat 0 0; + background: url("../../graphics/arrow-l.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .centerBtn { - background: url("../../graphics/center.gif") no-repeat 0 0; + background: url("../../graphics/center.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .rightBtn { - background: url("../../graphics/arrow-r.gif") no-repeat 0 0; + background: url("../../graphics/arrow-r.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .downLeftBtn { - background: url("../../graphics/arrow-dl.gif") no-repeat 0 0; + background: url("../../graphics/arrow-dl.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .downBtn { - background: url("../../graphics/arrow-d.gif") no-repeat 0 0; + background: url("../../graphics/arrow-d.png") no-repeat 0 0; } .ptzControls .controlsPanel .pantiltPanel .pantiltControls .downRightBtn { - background: url("../../graphics/arrow-dr.gif") no-repeat 0 0; + background: url("../../graphics/arrow-dr.png") no-repeat 0 0; } .ptzControls .controlsPanel .powerControls { diff --git a/web/skins/classic/css/flat/views/filter.css b/web/skins/classic/css/flat/views/filter.css index 2287cfea2..ed0087d08 100644 --- a/web/skins/classic/css/flat/views/filter.css +++ b/web/skins/classic/css/flat/views/filter.css @@ -10,8 +10,9 @@ table.filterTable { } #fieldsTable input[type=button] { - width: 1.6em; + width: 1.8em; margin-left: 2px; + padding: 5px; text-align: center; } diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 0a9297a78..9e59f5392 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -22,8 +22,7 @@ // Don't load in additional JS to these views $bad_views = array('monitor', 'log'); -function xhtmlHeaders( $file, $title ) -{ +function xhtmlHeaders( $file, $title ) { global $css; global $skin; $skinCssFile = getSkinFile( 'css/'.$css.'/skin.css' ); @@ -55,14 +54,12 @@ function xhtmlHeaders( $file, $title ) diff --git a/web/skins/classic/views/js/group.js b/web/skins/classic/views/js/group.js index ee3d1a27d..89f830b6c 100644 --- a/web/skins/classic/views/js/group.js +++ b/web/skins/classic/views/js/group.js @@ -1,18 +1,16 @@ -function selectMonitors() -{ - createPopup( '?view=monitorselect&callForm=groupForm&callField=newGroup[MonitorIds]', 'zmMonitors', 'monitorselect' ); +function selectMonitors() { + createPopup( '?view=monitorselect&callForm=groupForm&callField=newGroup[MonitorIds]', 'zmMonitors', 'monitorselect' ); } -if ( refreshParent ) -{ - opener.location.reload(true); +if ( refreshParent ) { + opener.location.reload(true); } function configureButtons( element ) { - if ( canEditGroups ) { - var form = element.form; - form.saveBtn.disabled = (element.value == 0); - } + if ( canEditGroups ) { + var form = element.form; + form.saveBtn.disabled = (element.value == 0); + } } window.focus(); diff --git a/web/skins/classic/views/js/groups.js b/web/skins/classic/views/js/groups.js index 199ababc2..7b570299f 100644 --- a/web/skins/classic/views/js/groups.js +++ b/web/skins/classic/views/js/groups.js @@ -1,47 +1,38 @@ -function newGroup() -{ - createPopup( '?view=group', 'zmGroup', 'group' ); +function newGroup() { + createPopup( '?view=group', 'zmGroup', 'group' ); } -function editGroup( element ) -{ - var form = element.form; - form.action.value = 'setgroup'; - form.submit(); +function editGroup( element ) { + var form = element.form; + form.action.value = 'setgroup'; + form.submit(); } -function editGroup( element ) -{ - var form = element.form; - for ( var i = 0; i < form.gid.length; i++ ) - { - if ( form.gid[i].checked ) - { - createPopup( '?view=group&gid='+form.gid[i].value, 'zmGroup', 'group' ); - return; - } +function editGroup( element ) { + var form = element.form; + for ( var i = 0; i < form.gid.length; i++ ) { + if ( form.gid[i].checked ) { + createPopup( '?view=group&gid='+form.gid[i].value, 'zmGroup', 'group' ); + return; } + } } -function deleteGroup( element ) -{ +function deleteGroup( element ) { + var form = element.form; + form.view.value = currentView; + form.action.value = 'delete'; + form.submit(); +} + +function configureButtons( element ) { + if ( canEditGroups ) { var form = element.form; - form.view.value = currentView; - form.action.value = 'delete'; - form.submit(); -} - -function configureButtons( element ) -{ - if ( canEditGroups ) - { - var form = element.form; - if ( element.checked ) - { - form.editBtn.disabled = (element.value == 0); - form.deleteBtn.disabled = (element.value == 0); - } + if ( element.checked ) { + form.editBtn.disabled = (element.value == 0); + form.deleteBtn.disabled = (element.value == 0); } + } } window.focus(); diff --git a/web/skins/classic/views/js/log.js b/web/skins/classic/views/js/log.js index e27db6517..34a0178da 100644 --- a/web/skins/classic/views/js/log.js +++ b/web/skins/classic/views/js/log.js @@ -25,313 +25,269 @@ var sortReversed = false; var filterFields = ['Component', 'ServerId', 'Pid', 'Level', 'File', 'Line']; var options = {}; -function buildFetchParms( parms ) -{ - var fetchParms = logParms+'&limit='+maxLogFetch; - if ( parms ) - fetchParms += '&'+parms; - Object.each(filter, - function( value, key ) - { - fetchParms += '&filter['+key+']='+value; - } - ); - return( fetchParms ); +function buildFetchParms( parms ) { + var fetchParms = logParms+'&limit='+maxLogFetch; + if ( parms ) + fetchParms += '&'+parms; + Object.each(filter, + function( value, key ) { + fetchParms += '&filter['+key+']='+value; + } + ); + return( fetchParms ); } -function fetchNextLogs() -{ - logReq.send( buildFetchParms( 'minTime='+maxLogTime ) ); +function fetchNextLogs() { + logReq.send( buildFetchParms( 'minTime='+maxLogTime ) ); } -function fetchPrevLogs() -{ - logReq.send( buildFetchParms( 'maxTime='+minLogTime ) ); +function fetchPrevLogs() { + logReq.send( buildFetchParms( 'maxTime='+minLogTime ) ); } -function logResponse( respObj ) -{ - if ( logTimer ) - logTimer = clearTimeout( logTimer ); +function logResponse( respObj ) { + if ( logTimer ) + logTimer = clearTimeout( logTimer ); - if ( respObj.result == 'Ok' ) - { - if ( respObj.logs.length > 0 ) - { - logTimeout = minSampleTime; - logCount += respObj.logs.length; - try { - respObj.logs.each( - function( log ) - { - if ( !maxLogTime || log.TimeKey > maxLogTime ) - maxLogTime = log.TimeKey; - if ( !minLogTime || log.TimeKey < minLogTime ) - minLogTime = log.TimeKey; - var row = logTable.push( [{ content: log.DateTime, properties: { style: 'white-space: nowrap' }}, log.Component, log.Server, log.Pid, log.Code, log.Message, log.File, log.Line] ); - delete log.Message; - row.tr.store( 'log', log ); - if ( log.Level <= -3 ) - row.tr.addClass( 'log-fat' ); - else if ( log.Level <= -2 ) - row.tr.addClass( 'log-err' ); - else if ( log.Level <= -1 ) - row.tr.addClass( 'log-war' ); - else if ( log.Level > 0 ) - row.tr.addClass( 'log-dbg' ); - if ( !firstLoad ) - { - var color = document.defaultView.getComputedStyle(row.tr, null).getPropertyValue('color'); - var colorParts = color.match(/^rgb.*\((\d+),\s*(\d+),\s*(\d+)/); - rowOrigColor = '#' + parseInt(colorParts[1]).toString(16) + parseInt(colorParts[2]).toString(16) + parseInt(colorParts[3]).toString(16); - new Fx.Tween( row.tr, { duration: 10000, transition: Fx.Transitions.Sine } ).start( 'color', '#6495ED', rowOrigColor ); - } - } - ); - options = respObj.options; - updateFilterSelectors(); - $('lastUpdate').set('text', respObj.updated); - $('logState').set('text', respObj.state); - $('logState').removeClass('ok'); - $('logState').removeClass('alert'); - $('logState').removeClass('alarm'); - $('logState').addClass(respObj.state); - $('totalLogs').set('text', respObj.total); - $('availLogs').set('text', respObj.available); - $('displayLogs').set('text', logCount); - if ( firstLoad ) - { - if ( logCount < displayLimit ) - fetchPrevLogs(); - } - logTable.reSort(); + if ( respObj.result == 'Ok' ) { + if ( respObj.logs.length > 0 ) { + logTimeout = minSampleTime; + logCount += respObj.logs.length; + try { + respObj.logs.each( + function( log ) { + if ( !maxLogTime || log.TimeKey > maxLogTime ) + maxLogTime = log.TimeKey; + if ( !minLogTime || log.TimeKey < minLogTime ) + minLogTime = log.TimeKey; + var row = logTable.push( [{ content: log.DateTime, properties: { style: 'white-space: nowrap' }}, log.Component, log.Server, log.Pid, log.Code, log.Message, log.File, log.Line] ); + delete log.Message; + row.tr.store( 'log', log ); + if ( log.Level <= -3 ) + row.tr.addClass( 'log-fat' ); + else if ( log.Level <= -2 ) + row.tr.addClass( 'log-err' ); + else if ( log.Level <= -1 ) + row.tr.addClass( 'log-war' ); + else if ( log.Level > 0 ) + row.tr.addClass( 'log-dbg' ); + if ( !firstLoad ) { + var color = document.defaultView.getComputedStyle(row.tr, null).getPropertyValue('color'); + var colorParts = color.match(/^rgb.*\((\d+),\s*(\d+),\s*(\d+)/); + rowOrigColor = '#' + parseInt(colorParts[1]).toString(16) + parseInt(colorParts[2]).toString(16) + parseInt(colorParts[3]).toString(16); + new Fx.Tween( row.tr, { duration: 10000, transition: Fx.Transitions.Sine } ).start( 'color', '#6495ED', rowOrigColor ); + } } - catch( e ) - { - console.error( e ); - } - logTimeout /= 2; - if ( logTimeout < minSampleTime ) - logTimeout = minSampleTime; - } - else - { - firstLoad = false; - logTimeout *= 2; - if ( logTimeout > maxSampleTime ) - logTimeout = maxSampleTime; + ); + options = respObj.options; + updateFilterSelectors(); + $('lastUpdate').set('text', respObj.updated); + $('logState').set('text', respObj.state); + $('logState').removeClass('ok'); + $('logState').removeClass('alert'); + $('logState').removeClass('alarm'); + $('logState').addClass(respObj.state); + $('totalLogs').set('text', respObj.total); + $('availLogs').set('text', respObj.available); + $('displayLogs').set('text', logCount); + if ( firstLoad ) { + if ( logCount < displayLimit ) + fetchPrevLogs(); } + logTable.reSort(); + } catch( e ) { + console.error( e ); + } + logTimeout /= 2; + if ( logTimeout < minSampleTime ) + logTimeout = minSampleTime; + } else { + firstLoad = false; + logTimeout *= 2; + if ( logTimeout > maxSampleTime ) + logTimeout = maxSampleTime; } - logTimer = fetchNextLogs.delay( logTimeout ); + } + logTimer = fetchNextLogs.delay( logTimeout ); } -function refreshLog() -{ - options = {}; - logTable.empty(); - firstLoad = true; - maxLogTime = 0; - minLogTime = 0; - logCount = 0; - logTimeout = maxSampleTime; - displayLimit = initialDisplayLimit; - fetchNextLogs(); +function refreshLog() { + options = {}; + logTable.empty(); + firstLoad = true; + maxLogTime = 0; + minLogTime = 0; + logCount = 0; + logTimeout = maxSampleTime; + displayLimit = initialDisplayLimit; + fetchNextLogs(); } -function expandLog() -{ - displayLimit += maxLogFetch; - fetchPrevLogs(); +function expandLog() { + displayLimit += maxLogFetch; + fetchPrevLogs(); } -function clearLog() -{ - logReq.cancel(); - minLogTime = 0; - logCount = 0; - logTimeout = maxSampleTime; - displayLimit = initialDisplayLimit; - $('displayLogs').set('text', logCount); - options = {}; - logTable.empty(); +function clearLog() { + logReq.cancel(); + minLogTime = 0; + logCount = 0; + logTimeout = maxSampleTime; + displayLimit = initialDisplayLimit; + $('displayLogs').set('text', logCount); + options = {}; + logTable.empty(); } -function filterLog() -{ - filter = {}; - filterFields.each( - function( field ) - { - var selector = $('filter['+field+']'); - if ( ! selector ) { - if ( window.console && window.console.log ) { - window.console.log("No selector found for " + field ); - } - return; - } - var value = selector.get('value'); - if ( value ) - filter[field] = value; +function filterLog() { + filter = {}; + filterFields.each( + function( field ) { + var selector = $('filter['+field+']'); + if ( ! selector ) { + if ( window.console && window.console.log ) { + window.console.log("No selector found for " + field ); + } + return; } - ); - refreshLog(); + var value = selector.get('value'); + if ( value ) + filter[field] = value; + } + ); + refreshLog(); } -function resetLog() -{ - filter = {}; - refreshLog(); +function resetLog() { + filter = {}; + refreshLog(); } var exportFormValidator; -function exportLog() -{ - exportFormValidator.reset(); - $('exportLog').overlayShow(); +function exportLog() { + exportFormValidator.reset(); + $('exportLog').overlayShow(); } -function exportResponse( response ) -{ - $('exportLog').unspin(); - if ( response.result == 'Ok' ) - { - window.location.replace( thisUrl+'?view=request&request=log&task=download&key='+response.key+'&format='+response.format ); +function exportResponse( response ) { + $('exportLog').unspin(); + if ( response.result == 'Ok' ) { + window.location.replace( thisUrl+'?view=request&request=log&task=download&key='+response.key+'&format='+response.format ); + } +} + +function exportFail( request ) { + $('exportLog').unspin(); + $('exportErrorText').set('text', request.status+" / "+request.statusText ); + $('exportError').show(); + Error( "Export request failed: "+request.status+" / "+request.statusText ); +} + +function exportRequest() { + var form = $('exportForm'); + $('exportErrorText').set('text', "" ); + $('exportError').hide(); + if ( form.validate() ) { + var exportParms = "view=request&request=log&task=export"; + var exportReq = new Request.JSON( { url: thisUrl, method: 'post', link: 'cancel', onSuccess: exportResponse, onFailure: exportFail } ); + var selection = form.getElement('input[name=selector]:checked').get('value'); + if ( selection == 'filter' || selection == 'current' ) { + $$('#filters select').each( + function( select ) { + exportParms += "&"+select.get('id')+"="+select.get('value'); + } + ); } + if ( selection == 'current' ) { + var tbody = $(logTable).getElement( 'tbody' ); + var rows = tbody.getElements( 'tr' ); + if ( rows ) { + var minTime = rows[0].getElement('td').get('text'); + exportParms += "&minTime="+encodeURIComponent(minTime); + var maxTime = rows[rows.length-1].getElement('td').get('text'); + exportParms += "&maxTime="+encodeURIComponent(maxTime); + } + } + exportReq.send( exportParms+"&"+form.toQueryString() ); + $('exportLog').spin(); + } } -function exportFail( request ) -{ - $('exportLog').unspin(); - $('exportErrorText').set('text', request.status+" / "+request.statusText ); - $('exportError').show(); - Error( "Export request failed: "+request.status+" / "+request.statusText ); -} - -function exportRequest() -{ - var form = $('exportForm'); - $('exportErrorText').set('text', "" ); - $('exportError').hide(); - if ( form.validate() ) - { - var exportParms = "view=request&request=log&task=export"; - var exportReq = new Request.JSON( { url: thisUrl, method: 'post', link: 'cancel', onSuccess: exportResponse, onFailure: exportFail } ); - var selection = form.getElement('input[name=selector]:checked').get('value'); - if ( selection == 'filter' || selection == 'current' ) - { - $$('#filters select').each( - function( select ) - { - exportParms += "&"+select.get('id')+"="+select.get('value'); +function updateFilterSelectors() { + Object.each(options, + function( values, key ) { + var selector = $('filter['+key+']'); + if ( ! selector ) { + if ( window.console && window.console.log ) { + window.console.log("No selector found for " + key ); + } + return; + } + selector.options.length = 1; + if ( key == 'Level' ) { + Object.each(values, + function( value, label ) { + selector.options[selector.options.length] = new Option( value, label ); } ); - } - if ( selection == 'current' ) - { - var tbody = $(logTable).getElement( 'tbody' ); - var rows = tbody.getElements( 'tr' ); - if ( rows ) - { - var minTime = rows[0].getElement('td').get('text'); - exportParms += "&minTime="+encodeURIComponent(minTime); - var maxTime = rows[rows.length-1].getElement('td').get('text'); - exportParms += "&maxTime="+encodeURIComponent(maxTime); - } - } - exportReq.send( exportParms+"&"+form.toQueryString() ); - $('exportLog').spin(); - } -} - -function updateFilterSelectors() -{ - Object.each(options, - function( values, key ) - { - var selector = $('filter['+key+']'); - if ( ! selector ) { - if ( window.console && window.console.log ) { - window.console.log("No selector found for " + key ); - } - return; - } - selector.options.length = 1; - if ( key == 'Level' ) - { - Object.each(values, - function( value, label ) - { - selector.options[selector.options.length] = new Option( value, label ); - } - ); - } - else if ( key == 'ServerId' ) - { - Object.each(values, - function( value, label ) - { - selector.options[selector.options.length] = new Option( value, label ); - } - ); - } - else - { - values.each( - function( value ) - { - selector.options[selector.options.length] = new Option( value ); - } - ); - } - if ( filter[key] ) - selector.set('value', filter[key]); - } - ); -} - -function initPage() -{ - displayLimit = initialDisplayLimit; - for ( var i = 1; i <= 9; i++ ) - logCodes[''+i] = 'DB'+i; - logTable = new HtmlTable( $('logTable'), - { - zebra: true, - sortable: true, - sortReverse: true - } - ); - logTable.addEvent( 'sort', function( tbody, index ) - { - var header = tbody.getParent( 'table' ).getElement( 'thead' ); - var columns = header.getElement( 'tr' ).getElements( 'th' ); - var column = columns[index]; - sortReversed = column.hasClass( 'table-th-sort-rev' ); - if ( logCount > displayLimit ) - { - var rows = tbody.getElements( 'tr' ); - var startIndex; - if ( sortReversed ) - startIndex = displayLimit; - else - startIndex = 0; - for ( var i = startIndex; logCount > displayLimit; i++ ) - { - rows[i].destroy(); - logCount--; + } else if ( key == 'ServerId' ) { + Object.each(values, + function( value, label ) { + selector.options[selector.options.length] = new Option( value, label ); } - $('displayLogs').set('text', logCount); - } + ); + } else { + values.each( + function( value ) { + selector.options[selector.options.length] = new Option( value ); + } + ); + } + if ( filter[key] ) + selector.set('value', filter[key]); + } + ); +} + +function initPage() { + displayLimit = initialDisplayLimit; + for ( var i = 1; i <= 9; i++ ) + logCodes[''+i] = 'DB'+i; + logTable = new HtmlTable( $('logTable'), + { +zebra: true, +sortable: true, +sortReverse: true +} +); + logTable.addEvent( 'sort', function( tbody, index ) { + var header = tbody.getParent( 'table' ).getElement( 'thead' ); + var columns = header.getElement( 'tr' ).getElements( 'th' ); + var column = columns[index]; + sortReversed = column.hasClass( 'table-th-sort-rev' ); + if ( logCount > displayLimit ) { + var rows = tbody.getElements( 'tr' ); + var startIndex; + if ( sortReversed ) + startIndex = displayLimit; + else + startIndex = 0; + for ( var i = startIndex; logCount > displayLimit; i++ ) { + rows[i].destroy(); + logCount--; } - ); - exportFormValidator = new Form.Validator.Inline($('exportForm'), { - useTitles: true, - warningPrefix: "", - errorPrefix: "" - }); - new Asset.css( "/css/spinner.css" ); - fetchNextLogs(); + $('displayLogs').set('text', logCount); + } // end if loCount > displayLimit + } + ); + exportFormValidator = new Form.Validator.Inline($('exportForm'), { + useTitles: true, + warningPrefix: "", + errorPrefix: "" + }); + new Asset.css( "/css/spinner.css" ); + fetchNextLogs(); } // Kick everything off diff --git a/web/skins/classic/views/js/monitor.js b/web/skins/classic/views/js/monitor.js index bf83fa7f7..9c5cc2a89 100644 --- a/web/skins/classic/views/js/monitor.js +++ b/web/skins/classic/views/js/monitor.js @@ -1,56 +1,49 @@ -function updateMonitorDimensions( element ) -{ - var form = element.form; - var widthFactor = parseInt( defaultAspectRatio.replace( /:.*$/, '' ) ); - var heightFactor = parseInt( defaultAspectRatio.replace( /^.*:/, '' ) ); +function updateMonitorDimensions( element ) { + var form = element.form; + var widthFactor = parseInt( defaultAspectRatio.replace( /:.*$/, '' ) ); + var heightFactor = parseInt( defaultAspectRatio.replace( /^.*:/, '' ) ); - if ( form.elements['preserveAspectRatio'].checked ) - { - var monitorWidth = parseInt(form.elements['newMonitor[Width]'].value); - var monitorHeight = parseInt(form.elements['newMonitor[Height]'].value); - switch( element.name ) - { - case 'newMonitor[Width]': - if ( monitorWidth >= 0 ) - form.elements['newMonitor[Height]'].value = Math.round((monitorWidth * heightFactor) / widthFactor); - else - form.elements['newMonitor[Height]'].value = ''; - break; - case 'newMonitor[Height]': - if ( monitorHeight >= 0 ) - form.elements['newMonitor[Width]'].value = Math.round((monitorHeight * widthFactor) / heightFactor); - else - form.elements['newMonitor[Width]'].value = ''; - break; - } + if ( form.elements['preserveAspectRatio'].checked ) { + var monitorWidth = parseInt(form.elements['newMonitor[Width]'].value); + var monitorHeight = parseInt(form.elements['newMonitor[Height]'].value); + switch( element.name ) { + case 'newMonitor[Width]': + if ( monitorWidth >= 0 ) + form.elements['newMonitor[Height]'].value = Math.round((monitorWidth * heightFactor) / widthFactor); + else + form.elements['newMonitor[Height]'].value = ''; + break; + case 'newMonitor[Height]': + if ( monitorHeight >= 0 ) + form.elements['newMonitor[Width]'].value = Math.round((monitorHeight * widthFactor) / heightFactor); + else + form.elements['newMonitor[Width]'].value = ''; + break; } - return( false ); + } + return( false ); } -function loadLocations( element ) -{ - var form = element.form; - var controlIdSelect = form.elements['newMonitor[ControlId]']; - var returnLocationSelect = form.elements['newMonitor[ReturnLocation]']; +function loadLocations( element ) { + var form = element.form; + var controlIdSelect = form.elements['newMonitor[ControlId]']; + var returnLocationSelect = form.elements['newMonitor[ReturnLocation]']; - returnLocationSelect.options.length = 1; - //returnLocationSelect.options[0] = new Option( noneString, -1 ); + returnLocationSelect.options.length = 1; + //returnLocationSelect.options[0] = new Option( noneString, -1 ); - var returnLocationOptions = controlOptions[controlIdSelect.selectedIndex]; - if ( returnLocationOptions ) - { - for ( var i = 0; i < returnLocationOptions.length; i++ ) - { - returnLocationSelect.options[returnLocationSelect.options.length] = new Option( returnLocationOptions[i], i ); - } + var returnLocationOptions = controlOptions[controlIdSelect.selectedIndex]; + if ( returnLocationOptions ) { + for ( var i = 0; i < returnLocationOptions.length; i++ ) { + returnLocationSelect.options[returnLocationSelect.options.length] = new Option( returnLocationOptions[i], i ); } + } } -function initPage() -{ - //var protocolSelector = $('contentForm').elements['newMonitor[Protocol]']; - //if ( $(protocolSelector).getTag() == 'select' ) - //updateMethods( $(protocolSelector) ); +function initPage() { + //var protocolSelector = $('contentForm').elements['newMonitor[Protocol]']; + //if ( $(protocolSelector).getTag() == 'select' ) + //updateMethods( $(protocolSelector) ); } window.addEvent( 'domready', initPage ); diff --git a/web/skins/classic/views/js/monitor.js.php b/web/skins/classic/views/js/monitor.js.php index 32a1bf2a4..db8adf7ee 100644 --- a/web/skins/classic/views/js/monitor.js.php +++ b/web/skins/classic/views/js/monitor.js.php @@ -2,194 +2,174 @@ var optControl = ; var defaultAspectRatio = ''; var controlOptions = new Object(); translate('None') ); -# Temporary workaround to show all ptz control types regardless of monitor source type -# $sql = "select * from Controls where Type = '".$newMonitor['Type']."'"; - $sql = "select * from Controls"; - foreach( dbFetchAll( $sql ) as $row ) - { - $controlTypes[$row['Id']] = $row['Name']; + global $controlTypes; + $controlTypes = array( ''=>translate('None') ); + # Temporary workaround to show all ptz control types regardless of monitor source type + # $sql = "select * from Controls where Type = '".$newMonitor['Type']."'"; + $sql = "select * from Controls"; + foreach( dbFetchAll( $sql ) as $row ) { + $controlTypes[$row['Id']] = $row['Name']; ?> controlOptions[] = new Array(); controlOptions[][0] = ''; controlOptions[][0] = null; controlOptions[][] = ''; var monitorNames = new Object(); monitorNames[''] = true; -function validateForm( form ) -{ - var errors = new Array(); +function validateForm( form ) { + var errors = new Array(); - if ( form.elements['newMonitor[Name]'].value.search( /[^\w- ]/ ) >= 0 ) - errors[errors.length] = ""; - else if ( form.elements.mid.value == 0 && monitorNames[form.elements['newMonitor[Name]'].value] ) - errors[errors.length] = ""; + if ( form.elements['newMonitor[Name]'].value.search( /[^\w- ]/ ) >= 0 ) + errors[errors.length] = ""; + else if ( form.elements.mid.value == 0 && monitorNames[form.elements['newMonitor[Name]'].value] ) + errors[errors.length] = ""; - if ( form.elements['newMonitor[AnalysisFPS]'].value && !(parseFloat(form.elements['newMonitor[AnalysisFPS]'].value) > 0 ) ) - errors[errors.length] = ""; - if ( form.elements['newMonitor[MaxFPS]'].value && !(parseFloat(form.elements['newMonitor[MaxFPS]'].value) > 0 ) ) - errors[errors.length] = ""; - if ( form.elements['newMonitor[AlarmMaxFPS]'].value && !(parseFloat(form.elements['newMonitor[AlarmMaxFPS]'].value) > 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[RefBlendPerc]'].value || (parseInt(form.elements['newMonitor[RefBlendPerc]'].value) > 100 ) || (parseInt(form.elements['newMonitor[RefBlendPerc]'].value) < 0 ) ) - errors[errors.length] = ""; - if ( form.elements['newMonitor[Type]'].value == 'Local' ) - { - if ( !form.elements['newMonitor[Palette]'].value || !form.elements['newMonitor[Palette]'].value.match( /^\d+$/ ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[Device]'].value ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[Channel]'].value || !form.elements['newMonitor[Channel]'].value.match( /^\d+$/ ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[Format]'].value || !form.elements['newMonitor[Format]'].value.match( /^\d+$/ ) ) - errors[errors.length] = ""; - } - else if ( form.elements['newMonitor[Type]'].value == 'Remote' ) - { - //if ( !form.elements['newMonitor[Host]'].value || !form.elements['newMonitor[Host]'].value.match( /^[0-9a-zA-Z_.:@-]+$/ ) ) - //errors[errors.length] = ""; - if ( form.elements['newMonitor[Port]'].value && !form.elements['newMonitor[Port]'].value.match( /^\d+$/ ) ) - errors[errors.length] = ""; - //if ( !form.elements['newMonitor[Path]'].value ) - //errors[errors.length] = ""; - } - else if ( form.elements['newMonitor[Type]'].value == 'File' ) - { - if ( !form.elements['newMonitor[Path]'].value ) - errors[errors.length] = ""; - } - if ( !form.elements['newMonitor[Colours]'].value || (parseInt(form.elements['newMonitor[Colours]'].value) != 1 && parseInt(form.elements['newMonitor[Colours]'].value) != 3 && parseInt(form.elements['newMonitor[Colours]'].value) != 4 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[Width]'].value || !(parseInt(form.elements['newMonitor[Width]'].value) > 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[Height]'].value || !(parseInt(form.elements['newMonitor[Height]'].value) > 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[LabelX]'].value || !(parseInt(form.elements['newMonitor[LabelX]'].value) >= 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[LabelY]'].value || !(parseInt(form.elements['newMonitor[LabelY]'].value) >= 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[ImageBufferCount]'].value || !(parseInt(form.elements['newMonitor[ImageBufferCount]'].value) >= 10 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[WarmupCount]'].value || !(parseInt(form.elements['newMonitor[WarmupCount]'].value) >= 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[PreEventCount]'].value || !(parseInt(form.elements['newMonitor[PreEventCount]'].value) > 0 ) || (parseInt(form.elements['newMonitor[PreEventCount]'].value) > parseInt(form.elements['newMonitor[ImageBufferCount]'].value)) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[PostEventCount]'].value || !(parseInt(form.elements['newMonitor[PostEventCount]'].value) >= 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[StreamReplayBuffer]'].value || !(parseInt(form.elements['newMonitor[StreamReplayBuffer]'].value) >= 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[AlarmFrameCount]'].value || !(parseInt(form.elements['newMonitor[AlarmFrameCount]'].value) > 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[SectionLength]'].value || !(parseInt(form.elements['newMonitor[SectionLength]'].value) >= 30 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[AnalysisUpdateDelay]'].value || !(parseInt(form.elements['newMonitor[AnalysisUpdateDelay]'].value) >= 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[FPSReportInterval]'].value || !(parseInt(form.elements['newMonitor[FPSReportInterval]'].value) >= 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[FrameSkip]'].value || !(parseInt(form.elements['newMonitor[FrameSkip]'].value) >= 0 ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[MotionFrameSkip]'].value || !(parseInt(form.elements['newMonitor[MotionFrameSkip]'].value) >= 0 ) ) - errors[errors.length] = ""; - if ( form.elements['newMonitor[Type]'].value == 'Local' ) - if ( !form.elements['newMonitor[SignalCheckColour]'].value || !form.elements['newMonitor[SignalCheckColour]'].value.match( /^[#0-9a-zA-Z]+$/ ) ) - errors[errors.length] = ""; - if ( !form.elements['newMonitor[WebColour]'].value || !form.elements['newMonitor[WebColour]'].value.match( /^[#0-9a-zA-Z]+$/ ) ) - errors[errors.length] = ""; + if ( form.elements['newMonitor[AnalysisFPS]'].value && !(parseFloat(form.elements['newMonitor[AnalysisFPS]'].value) > 0 ) ) + errors[errors.length] = ""; + if ( form.elements['newMonitor[MaxFPS]'].value && !(parseFloat(form.elements['newMonitor[MaxFPS]'].value) > 0 ) ) + errors[errors.length] = ""; + if ( form.elements['newMonitor[AlarmMaxFPS]'].value && !(parseFloat(form.elements['newMonitor[AlarmMaxFPS]'].value) > 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[RefBlendPerc]'].value || (parseInt(form.elements['newMonitor[RefBlendPerc]'].value) > 100 ) || (parseInt(form.elements['newMonitor[RefBlendPerc]'].value) < 0 ) ) + errors[errors.length] = ""; + if ( form.elements['newMonitor[Type]'].value == 'Local' ) { + if ( !form.elements['newMonitor[Palette]'].value || !form.elements['newMonitor[Palette]'].value.match( /^\d+$/ ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[Device]'].value ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[Channel]'].value || !form.elements['newMonitor[Channel]'].value.match( /^\d+$/ ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[Format]'].value || !form.elements['newMonitor[Format]'].value.match( /^\d+$/ ) ) + errors[errors.length] = ""; + } else if ( form.elements['newMonitor[Type]'].value == 'Remote' ) { + //if ( !form.elements['newMonitor[Host]'].value || !form.elements['newMonitor[Host]'].value.match( /^[0-9a-zA-Z_.:@-]+$/ ) ) + //errors[errors.length] = ""; + if ( form.elements['newMonitor[Port]'].value && !form.elements['newMonitor[Port]'].value.match( /^\d+$/ ) ) + errors[errors.length] = ""; + //if ( !form.elements['newMonitor[Path]'].value ) + //errors[errors.length] = ""; + } else if ( form.elements['newMonitor[Type]'].value == 'File' ) { + if ( !form.elements['newMonitor[Path]'].value ) + errors[errors.length] = ""; + } + if ( !form.elements['newMonitor[Colours]'].value || (parseInt(form.elements['newMonitor[Colours]'].value) != 1 && parseInt(form.elements['newMonitor[Colours]'].value) != 3 && parseInt(form.elements['newMonitor[Colours]'].value) != 4 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[Width]'].value || !(parseInt(form.elements['newMonitor[Width]'].value) > 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[Height]'].value || !(parseInt(form.elements['newMonitor[Height]'].value) > 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[LabelX]'].value || !(parseInt(form.elements['newMonitor[LabelX]'].value) >= 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[LabelY]'].value || !(parseInt(form.elements['newMonitor[LabelY]'].value) >= 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[ImageBufferCount]'].value || !(parseInt(form.elements['newMonitor[ImageBufferCount]'].value) >= 10 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[WarmupCount]'].value || !(parseInt(form.elements['newMonitor[WarmupCount]'].value) >= 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[PreEventCount]'].value || !(parseInt(form.elements['newMonitor[PreEventCount]'].value) > 0 ) || (parseInt(form.elements['newMonitor[PreEventCount]'].value) > parseInt(form.elements['newMonitor[ImageBufferCount]'].value)) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[PostEventCount]'].value || !(parseInt(form.elements['newMonitor[PostEventCount]'].value) >= 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[StreamReplayBuffer]'].value || !(parseInt(form.elements['newMonitor[StreamReplayBuffer]'].value) >= 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[AlarmFrameCount]'].value || !(parseInt(form.elements['newMonitor[AlarmFrameCount]'].value) > 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[SectionLength]'].value || !(parseInt(form.elements['newMonitor[SectionLength]'].value) >= 30 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[AnalysisUpdateDelay]'].value || !(parseInt(form.elements['newMonitor[AnalysisUpdateDelay]'].value) >= 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[FPSReportInterval]'].value || !(parseInt(form.elements['newMonitor[FPSReportInterval]'].value) >= 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[FrameSkip]'].value || !(parseInt(form.elements['newMonitor[FrameSkip]'].value) >= 0 ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[MotionFrameSkip]'].value || !(parseInt(form.elements['newMonitor[MotionFrameSkip]'].value) >= 0 ) ) + errors[errors.length] = ""; + if ( form.elements['newMonitor[Type]'].value == 'Local' ) + if ( !form.elements['newMonitor[SignalCheckColour]'].value || !form.elements['newMonitor[SignalCheckColour]'].value.match( /^[#0-9a-zA-Z]+$/ ) ) + errors[errors.length] = ""; + if ( !form.elements['newMonitor[WebColour]'].value || !form.elements['newMonitor[WebColour]'].value.match( /^[#0-9a-zA-Z]+$/ ) ) + errors[errors.length] = ""; - if ( errors.length ) - { - alert( errors.join( "\n" ) ); - return( false ); - } - return( true ); + if ( errors.length ) { + alert( errors.join( "\n" ) ); + return( false ); + } + return( true ); } -function updateLinkedMonitors( element ) -{ - var form = element.form; - var monitorIds = new Array(); - for ( var i = 0; i < element.options.length; i++ ) - if ( element.options[i].selected ) - monitorIds[monitorIds.length] = element.options[i].value; - form.elements['newMonitor[LinkedMonitors]'].value = monitorIds.join( ',' ); +function updateLinkedMonitors( element ) { + var form = element.form; + var monitorIds = new Array(); + for ( var i = 0; i < element.options.length; i++ ) + if ( element.options[i].selected ) + monitorIds[monitorIds.length] = element.options[i].value; + form.elements['newMonitor[LinkedMonitors]'].value = monitorIds.join( ',' ); } -function updateMethods( element ) -{ - var form = element.form; +function updateMethods( element ) { + var form = element.form; - var origMethod = form.elements['origMethod']; - var methodSelector = form.elements['newMonitor[Method]']; - methodSelector.options.length = 0; - switch ( element.value ) - { - case 'http' : - { -$label ) -{ -?> - methodSelector.options[methodSelector.options.length] = new Option( "", "" ); + var origMethod = form.elements['origMethod']; + var methodSelector = form.elements['newMonitor[Method]']; + methodSelector.options.length = 0; + switch ( element.value ) { + case 'http' : + { + $label ) { + ?> + methodSelector.options[methodSelector.options.length] = new Option( "", "" ); if ( origMethod.value == "" ) - methodSelector.selectedIndex = methodSelector.options.length-1; - - break; - } - case 'rtsp' : - { -$label ) -{ -?> - methodSelector.options[methodSelector.options.length] = new Option( "", "" ); + methodSelector.selectedIndex = methodSelector.options.length-1; + + break; + } + case 'rtsp' : + { + $label ) { + ?> + methodSelector.options[methodSelector.options.length] = new Option( "", "" ); if ( origMethod.value == "" ) - methodSelector.selectedIndex = form.elements['newMonitor[Method]'].options.length-1; - - break; - } - } - return( true ); + methodSelector.selectedIndex = form.elements['newMonitor[Method]'].options.length-1; + + break; + } + } + return( true ); } diff --git a/web/skins/classic/views/js/monitorpreset.js b/web/skins/classic/views/js/monitorpreset.js index 7a396016e..57b9e343b 100644 --- a/web/skins/classic/views/js/monitorpreset.js +++ b/web/skins/classic/views/js/monitorpreset.js @@ -1,14 +1,12 @@ -function submitPreset( element ) -{ - var form = element.form; - form.target = opener.name; - form.view.value = 'monitor'; - form.submit(); - closeWindow.delay( 250 ); +function submitPreset( element ) { + var form = element.form; + form.target = opener.name; + form.view.value = 'monitor'; + form.submit(); + closeWindow.delay( 250 ); } -function configureButtons( element ) -{ - var form = element.form; - form.saveBtn.disabled = (form.preset.selectedIndex==0); +function configureButtons( element ) { + var form = element.form; + form.saveBtn.disabled = (form.preset.selectedIndex==0); } diff --git a/web/skins/classic/views/js/monitorprobe.js b/web/skins/classic/views/js/monitorprobe.js index 264143f5f..cc507b8d9 100644 --- a/web/skins/classic/views/js/monitorprobe.js +++ b/web/skins/classic/views/js/monitorprobe.js @@ -1,14 +1,12 @@ -function submitCamera( element ) -{ - var form = element.form; - form.target = opener.name; - form.view.value = 'monitor'; - form.submit(); - closeWindow.delay( 250 ); +function submitCamera( element ) { + var form = element.form; + form.target = opener.name; + form.view.value = 'monitor'; + form.submit(); + closeWindow.delay( 250 ); } -function configureButtons( element ) -{ - var form = element.form; - form.saveBtn.disabled = (form.probe.selectedIndex==0); +function configureButtons( element ) { + var form = element.form; + form.saveBtn.disabled = (form.probe.selectedIndex==0); } diff --git a/web/skins/classic/views/js/montage.js b/web/skins/classic/views/js/montage.js index 641168c0b..2d1e23dfa 100644 --- a/web/skins/classic/views/js/montage.js +++ b/web/skins/classic/views/js/montage.js @@ -1,209 +1,191 @@ var requestQueue = new Request.Queue( { concurrent: 2 } ); -function Monitor( monitorData ) -{ - this.id = monitorData.id; - this.connKey = monitorData.connKey; - this.server_url = monitorData.server_url; - this.status = null; - this.alarmState = STATE_IDLE; - this.lastAlarmState = STATE_IDLE; - this.streamCmdParms = "view=request&request=stream&connkey="+this.connKey; - this.streamCmdTimer = null; +function Monitor( monitorData ) { + this.id = monitorData.id; + this.connKey = monitorData.connKey; + this.server_url = monitorData.server_url; + this.status = null; + this.alarmState = STATE_IDLE; + this.lastAlarmState = STATE_IDLE; + this.streamCmdParms = "view=request&request=stream&connkey="+this.connKey; + this.streamCmdTimer = null; - this.start = function( delay ) - { - this.streamCmdTimer = this.streamCmdQuery.delay( delay, this ); - }; + this.start = function( delay ) { + this.streamCmdTimer = this.streamCmdQuery.delay( delay, this ); + }; - this.setStateClass = function( element, stateClass ) - { - if ( !element.hasClass( stateClass ) ) - { - if ( stateClass != 'alarm' ) - element.removeClass( 'alarm' ); - if ( stateClass != 'alert' ) - element.removeClass( 'alert' ); - if ( stateClass != 'idle' ) - element.removeClass( 'idle' ); - element.addClass( stateClass ); + this.setStateClass = function( element, stateClass ) { + if ( !element.hasClass( stateClass ) ) { + if ( stateClass != 'alarm' ) + element.removeClass( 'alarm' ); + if ( stateClass != 'alert' ) + element.removeClass( 'alert' ); + if ( stateClass != 'idle' ) + element.removeClass( 'idle' ); + element.addClass( stateClass ); + } + }; + + this.getStreamCmdResponse = function( respObj, respText ) { + if ( this.streamCmdTimer ) + this.streamCmdTimer = clearTimeout( this.streamCmdTimer ); + + var stream = document.getElementById( "liveStream"+this.id ); + if ( respObj.result == 'Ok' ) { + this.status = respObj.status; + this.alarmState = this.status.state; + + var stateClass = ""; + if ( this.alarmState == STATE_ALARM ) + stateClass = "alarm"; + else if ( this.alarmState == STATE_ALERT ) + stateClass = "alert"; + else + stateClass = "idle"; + + if ( !COMPACT_MONTAGE ) { + $('fpsValue'+this.id).set( 'text', this.status.fps ); + $('stateValue'+this.id).set( 'text', stateStrings[this.alarmState] ); + this.setStateClass( $('monitorState'+this.id), stateClass ); + } + this.setStateClass( $('monitor'+this.id), stateClass ); + + /*Stream could be an applet so can't use moo tools*/ + stream.className = stateClass; + + var isAlarmed = ( this.alarmState == STATE_ALARM || this.alarmState == STATE_ALERT ); + var wasAlarmed = ( this.lastAlarmState == STATE_ALARM || this.lastAlarmState == STATE_ALERT ); + + var newAlarm = ( isAlarmed && !wasAlarmed ); + var oldAlarm = ( !isAlarmed && wasAlarmed ); + + if ( newAlarm ) { + if ( false && SOUND_ON_ALARM ) { + // Enable the alarm sound + $('alarmSound').removeClass( 'hidden' ); } - }; - - this.getStreamCmdResponse = function( respObj, respText ) - { - if ( this.streamCmdTimer ) - this.streamCmdTimer = clearTimeout( this.streamCmdTimer ); - - var stream = document.getElementById( "liveStream"+this.id ); - if ( respObj.result == 'Ok' ) - { - this.status = respObj.status; - this.alarmState = this.status.state; - - var stateClass = ""; - if ( this.alarmState == STATE_ALARM ) - stateClass = "alarm"; - else if ( this.alarmState == STATE_ALERT ) - stateClass = "alert"; - else - stateClass = "idle"; - - if ( !COMPACT_MONTAGE ) - { - $('fpsValue'+this.id).set( 'text', this.status.fps ); - $('stateValue'+this.id).set( 'text', stateStrings[this.alarmState] ); - this.setStateClass( $('monitorState'+this.id), stateClass ); - } - this.setStateClass( $('monitor'+this.id), stateClass ); - - /*Stream could be an applet so can't use moo tools*/ - stream.className = stateClass; - - var isAlarmed = ( this.alarmState == STATE_ALARM || this.alarmState == STATE_ALERT ); - var wasAlarmed = ( this.lastAlarmState == STATE_ALARM || this.lastAlarmState == STATE_ALERT ); - - var newAlarm = ( isAlarmed && !wasAlarmed ); - var oldAlarm = ( !isAlarmed && wasAlarmed ); - - if ( newAlarm ) - { - if ( false && SOUND_ON_ALARM ) - { - // Enable the alarm sound - $('alarmSound').removeClass( 'hidden' ); - } - if ( POPUP_ON_ALARM ) - { - windowToFront(); - } - } - if ( false && SOUND_ON_ALARM ) - { - if ( oldAlarm ) - { - // Disable alarm sound - $('alarmSound').addClass( 'hidden' ); - } - } - if ( this.status.auth ) { - // Try to reload the image stream. - if ( stream ) - stream.src = stream.src.replace( /auth=\w+/i, 'auth='+this.status.auth ); - console.log("Changed auth to " + this.status.auth ); - } // end if haev a new auth hash + if ( POPUP_ON_ALARM ) { + windowToFront(); } - else - { - console.error( respObj.message ); - // Try to reload the image stream. - if ( stream ) - stream.src = stream.src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) )); + } + if ( false && SOUND_ON_ALARM ) { + if ( oldAlarm ) { + // Disable alarm sound + $('alarmSound').addClass( 'hidden' ); } - var streamCmdTimeout = statusRefreshTimeout; - if ( this.alarmState == STATE_ALARM || this.alarmState == STATE_ALERT ) - streamCmdTimeout = streamCmdTimeout/5; - this.streamCmdTimer = this.streamCmdQuery.delay( streamCmdTimeout, this ); - this.lastAlarmState = this.alarmState; - }; + } + if ( this.status.auth ) { + // Try to reload the image stream. + if ( stream ) + stream.src = stream.src.replace( /auth=\w+/i, 'auth='+this.status.auth ); + console.log("Changed auth to " + this.status.auth ); + } // end if haev a new auth hash + } else { + console.error( respObj.message ); + // Try to reload the image stream. + if ( stream ) + stream.src = stream.src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) )); + } + var streamCmdTimeout = statusRefreshTimeout; + if ( this.alarmState == STATE_ALARM || this.alarmState == STATE_ALERT ) + streamCmdTimeout = streamCmdTimeout/5; + this.streamCmdTimer = this.streamCmdQuery.delay( streamCmdTimeout, this ); + this.lastAlarmState = this.alarmState; + }; - this.streamCmdQuery = function( resent ) - { - //if ( resent ) - //console.log( this.connKey+": Resending" ); - //this.streamCmdReq.cancel(); - this.streamCmdReq.send( this.streamCmdParms+"&command="+CMD_QUERY ); - }; + this.streamCmdQuery = function( resent ) { + //if ( resent ) + //console.log( this.connKey+": Resending" ); + //this.streamCmdReq.cancel(); + this.streamCmdReq.send( this.streamCmdParms+"&command="+CMD_QUERY ); + }; - this.streamCmdReq = new Request.JSON( { url: this.server_url, method: 'get', timeout: AJAX_TIMEOUT, onSuccess: this.getStreamCmdResponse.bind( this ), onTimeout: this.streamCmdQuery.bind( this, true ), link: 'cancel' } ); + this.streamCmdReq = new Request.JSON( { url: this.server_url, method: 'get', timeout: AJAX_TIMEOUT, onSuccess: this.getStreamCmdResponse.bind( this ), onTimeout: this.streamCmdQuery.bind( this, true ), link: 'cancel' } ); - requestQueue.addRequest( "cmdReq"+this.id, this.streamCmdReq ); + requestQueue.addRequest( "cmdReq"+this.id, this.streamCmdReq ); } -function selectLayout( element ) -{ - var cssFile = skinPath+'/css/'+Cookie.read('zmCSS')+'/views/'+$(element).get('value'); - if ( $('dynamicStyles') ) - $('dynamicStyles').destroy(); - new Asset.css( cssFile, { id: 'dynamicStyles' } ); - Cookie.write( 'zmMontageLayout', $(element).get('value'), { duration: 10*365 } ); +function selectLayout( element ) { + var cssFile = skinPath+'/css/'+Cookie.read('zmCSS')+'/views/'+$(element).get('value'); + if ( $('dynamicStyles') ) + $('dynamicStyles').destroy(); + new Asset.css( cssFile, { id: 'dynamicStyles' } ); + Cookie.write( 'zmMontageLayout', $(element).get('value'), { duration: 10*365 } ); } function changeWidth() { - var width = $('width').get('value'); + var width = $('width').get('value'); - for ( var x = 0; x < monitors.length; x++ ) { - var monitor = monitors[x]; - /*Stream could be an applet so can't use moo tools*/ - var streamImg = document.getElementById( 'liveStream'+monitor.id ); - if ( streamImg ) { - streamImg.src = streamImg.src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) )); - streamImg.style.width = width + "px"; - streamImg.style.height = ''; - } + for ( var x = 0; x < monitors.length; x++ ) { + var monitor = monitors[x]; + /*Stream could be an applet so can't use moo tools*/ + var streamImg = document.getElementById( 'liveStream'+monitor.id ); + if ( streamImg ) { + streamImg.src = streamImg.src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) )); + streamImg.style.width = width + "px"; + streamImg.style.height = ''; } - $('scale').set('value', '' ); - Cookie.write( 'zmMontageScale', '', { duration: 10*365 } ); - Cookie.write( 'zmMontageWidth', width, { duration: 10*365 } ); + } + $('scale').set('value', '' ); + Cookie.write( 'zmMontageScale', '', { duration: 10*365 } ); + Cookie.write( 'zmMontageWidth', width, { duration: 10*365 } ); } // end function changeWidth() function changeHeight() { - var height = $('height').get('value'); + var height = $('height').get('value'); - for ( var x = 0; x < monitors.length; x++ ) { - var monitor = monitors[x]; - /*Stream could be an applet so can't use moo tools*/ - var streamImg = document.getElementById( 'liveStream'+monitor.id ); - if ( streamImg ) { - streamImg.src = streamImg.src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) )); - streamImg.style.height = height + "px"; - } + for ( var x = 0; x < monitors.length; x++ ) { + var monitor = monitors[x]; + /*Stream could be an applet so can't use moo tools*/ + var streamImg = document.getElementById( 'liveStream'+monitor.id ); + if ( streamImg ) { + streamImg.src = streamImg.src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) )); + streamImg.style.height = height + "px"; } - $('scale').set('value', '' ); - Cookie.write( 'zmMontageHeight', height, { duration: 10*365 } ); - Cookie.write( 'zmMontageScale', '', { duration: 10*365 } ); + } + $('scale').set('value', '' ); + Cookie.write( 'zmMontageHeight', height, { duration: 10*365 } ); + Cookie.write( 'zmMontageScale', '', { duration: 10*365 } ); } // end function changeHeight() function changeScale() { - var scale = $('scale').get('value'); + var scale = $('scale').get('value'); - for ( var x = 0; x < monitors.length; x++ ) { - var monitor = monitors[x]; - var newWidth = ( monitorData[x].width * scale ) / SCALE_BASE; - var newHeight = ( monitorData[x].height * scale ) / SCALE_BASE; - /*Stream could be an applet so can't use moo tools*/ - var streamImg = document.getElementById( 'liveStream'+monitor.id ); - if ( streamImg ) { - var src = streamImg.src; - streamImg.src=''; + for ( var x = 0; x < monitors.length; x++ ) { + var monitor = monitors[x]; + var newWidth = ( monitorData[x].width * scale ) / SCALE_BASE; + var newHeight = ( monitorData[x].height * scale ) / SCALE_BASE; + /*Stream could be an applet so can't use moo tools*/ + var streamImg = document.getElementById( 'liveStream'+monitor.id ); + if ( streamImg ) { + var src = streamImg.src; + streamImg.src=''; - streamImg.style.width = newWidth + "px"; - streamImg.style.height = newHeight + "px"; - //src = src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) )); - src = src.replace(/scale=[\.\d]+/i,'scale='+ scale ); - src = src.replace(/width=[\.\d]+/i,'width='+newWidth ); - src = src.replace(/height=[\.\d]+/i,'height='+newHeight ); - streamImg.src = src; - } + streamImg.style.width = newWidth + "px"; + streamImg.style.height = newHeight + "px"; + //src = src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) )); + src = src.replace(/scale=[\.\d]+/i,'scale='+ scale ); + src = src.replace(/width=[\.\d]+/i,'width='+newWidth ); + src = src.replace(/height=[\.\d]+/i,'height='+newHeight ); + streamImg.src = src; } - $('width').set('value', ''); - $('height').set('value', ''); - Cookie.write( 'zmMontageScale', scale, { duration: 10*365 } ); - Cookie.write( 'zmMontageWidth', '', { duration: 10*365 } ); - Cookie.write( 'zmMontageHeight', '', { duration: 10*365 } ); + } + $('width').set('value', ''); + $('height').set('value', ''); + Cookie.write( 'zmMontageScale', scale, { duration: 10*365 } ); + Cookie.write( 'zmMontageWidth', '', { duration: 10*365 } ); + Cookie.write( 'zmMontageHeight', '', { duration: 10*365 } ); } var monitors = new Array(); -function initPage() -{ - for ( var i = 0; i < monitorData.length; i++ ) - { - monitors[i] = new Monitor( monitorData[i] ); - var delay = Math.round( (Math.random()+0.5)*statusRefreshTimeout ); - monitors[i].start( delay ); - } - selectLayout( $('layout') ); +function initPage() { + for ( var i = 0; i < monitorData.length; i++ ) { + monitors[i] = new Monitor( monitorData[i] ); + var delay = Math.round( (Math.random()+0.5)*statusRefreshTimeout ); + monitors[i].start( delay ); + } + selectLayout( $('layout') ); } // Kick everything off diff --git a/web/skins/classic/views/js/montage.js.php b/web/skins/classic/views/js/montage.js.php index 7eaebb75b..da4e47f23 100644 --- a/web/skins/classic/views/js/montage.js.php +++ b/web/skins/classic/views/js/montage.js.php @@ -28,8 +28,7 @@ var canStreamNative = ; var monitorData = new Array(); monitorData[monitorData.length] = { 'id': Id() ?>, diff --git a/web/skins/classic/views/js/onvifprobe.js b/web/skins/classic/views/js/onvifprobe.js index 93b2c53e9..45819dfb6 100644 --- a/web/skins/classic/views/js/onvifprobe.js +++ b/web/skins/classic/views/js/onvifprobe.js @@ -1,39 +1,35 @@ -function submitCamera( element ) -{ - var form = element.form; - form.target = opener.name; - form.view.value = 'monitor'; - form.submit(); - closeWindow.delay( 250 ); +function submitCamera( element ) { + var form = element.form; + form.target = opener.name; + form.view.value = 'monitor'; + form.submit(); + closeWindow.delay( 250 ); } -function gotoStep1( element ) -{ - var form = element.form; - form.target = self.name; - form.view.value = 'onvifprobe'; - form.step.value = '1'; - form.submit(); +function gotoStep1( element ) { + var form = element.form; + form.target = self.name; + form.view.value = 'onvifprobe'; + form.step.value = '1'; + form.submit(); } -function gotoStep2( element ) -{ - var form = element.form; - form.target = self.name; - form.view.value = 'onvifprobe'; - form.step.value = '2'; - form.submit(); +function gotoStep2( element ) { + var form = element.form; + form.target = self.name; + form.view.value = 'onvifprobe'; + form.step.value = '2'; + form.submit(); } -function configureButtons( element ) -{ - var form = element.form; - if(form.elements.namedItem("nextBtn")) { - form.nextBtn.disabled = (form.probe.selectedIndex==0) || - (form.username == "") || (form.username == null) || - (form.password == "") || (form.password == null); - } - if(form.elements.namedItem("saveBtn")) { - form.saveBtn.disabled = (form.probe.selectedIndex==0); - } +function configureButtons( element ) { + var form = element.form; + if (form.elements.namedItem("nextBtn")) { + form.nextBtn.disabled = (form.probe.selectedIndex==0) || + (form.username == "") || (form.username == null) || + (form.password == "") || (form.password == null); + } + if(form.elements.namedItem("saveBtn")) { + form.saveBtn.disabled = (form.probe.selectedIndex==0); + } } diff --git a/web/skins/classic/views/js/options.js.php b/web/skins/classic/views/js/options.js.php index 6d9d18312..88387134a 100644 --- a/web/skins/classic/views/js/options.js.php +++ b/web/skins/classic/views/js/options.js.php @@ -1,5 +1,4 @@ var restartWarning = ; -if ( restartWarning ) -{ - alert( "" ); +if ( restartWarning ) { + alert( "" ); } diff --git a/web/skins/classic/views/js/plugin.js b/web/skins/classic/views/js/plugin.js index f03768317..ec7f9b96d 100644 --- a/web/skins/classic/views/js/plugin.js +++ b/web/skins/classic/views/js/plugin.js @@ -1,29 +1,22 @@ -function validateForm( form ) -{ - return( true ); +function validateForm( form ) { + return( true ); } -function submitForm( form ) -{ - form.submit(); +function submitForm( form ) { + form.submit(); } -function limitRange( field, minValue, maxValue ) -{ - if ( parseInt(field.value) < parseInt(minValue) ) - { - field.value = minValue; - } - else if ( parseInt(field.value) > parseInt(maxValue) ) - { - field.value = maxValue; - } +function limitRange( field, minValue, maxValue ) { + if ( parseInt(field.value) < parseInt(minValue) ) { + field.value = minValue; + } else if ( parseInt(field.value) > parseInt(maxValue) ) { + field.value = maxValue; + } } -function initPage() -{ - return( true ); +function initPage() { + return( true ); } window.addEvent( 'domready', initPage ); diff --git a/web/skins/classic/views/js/postlogin.js.php b/web/skins/classic/views/js/postlogin.js.php index 6e3c21ec1..914d3e77b 100644 --- a/web/skins/classic/views/js/postlogin.js.php +++ b/web/skins/classic/views/js/postlogin.js.php @@ -9,8 +9,7 @@ ?> ( - function () - { + function () { // Append '?(GET query)' to URL if the GET query is not empty. var querySuffix = ">>>>>> master diff --git a/web/skins/classic/views/js/user.js b/web/skins/classic/views/js/user.js index 49e51394f..485254cdc 100644 --- a/web/skins/classic/views/js/user.js +++ b/web/skins/classic/views/js/user.js @@ -1,36 +1,26 @@ -function validateForm( form, newUser ) -{ - var errors = new Array(); - if ( !form.elements['newUser[Username]'].value ) - { - errors[errors.length] = "You must supply a username"; +function validateForm( form, newUser ) { + var errors = new Array(); + if ( !form.elements['newUser[Username]'].value ) { + errors[errors.length] = "You must supply a username"; + } + if ( form.elements['newUser[Password]'].value ) { + if ( !form.conf_password.value ) { + errors[errors.length] = "You must confirm the password"; + } else if ( form.elements['newUser[Password]'].value != form.conf_password.value ) { + errors[errors.length] = "The new and confirm passwords are different"; } - if ( form.elements['newUser[Password]'].value ) - { - if ( !form.conf_password.value ) - { - errors[errors.length] = "You must confirm the password"; - } - else if ( form.elements['newUser[Password]'].value != form.conf_password.value ) - { - errors[errors.length] = "The new and confirm passwords are different"; - } - } - else if ( newUser ) - { - errors[errors.length] = "You must supply a password"; - } - var monitorIds = new Array(); - for ( var i = 0; i < form.elements['monitorIds'].options.length; i++ ) - { - if ( form.elements['monitorIds'].options[i].selected ) - monitorIds[monitorIds.length] = form.elements['monitorIds'].options[i].value; - } - form.elements['newUser[MonitorIds]'].value = monitorIds.join( ',' ); - if ( errors.length ) - { - alert( errors.join( "\n" ) ); - return( false ); - } - return( true ); + } else if ( newUser ) { + errors[errors.length] = "You must supply a password"; + } + var monitorIds = new Array(); + for ( var i = 0; i < form.elements['monitorIds'].options.length; i++ ) { + if ( form.elements['monitorIds'].options[i].selected ) + monitorIds[monitorIds.length] = form.elements['monitorIds'].options[i].value; + } + form.elements['newUser[MonitorIds]'].value = monitorIds.join( ',' ); + if ( errors.length ) { + alert( errors.join( "\n" ) ); + return( false ); + } + return( true ); } diff --git a/web/skins/classic/views/js/version.js b/web/skins/classic/views/js/version.js index ac3b17f95..adec52bfb 100644 --- a/web/skins/classic/views/js/version.js +++ b/web/skins/classic/views/js/version.js @@ -1,18 +1,13 @@ -function submitForm( element ) -{ - var form = element.form; - if ( form.option.selectedIndex == 0 ) - { - form.view.value = currentView; - } - else - { - form.view.value = 'none'; - } +function submitForm( element ) { + var form = element.form; + if ( form.option.selectedIndex == 0 ) { + form.view.value = currentView; + } else { + form.view.value = 'none'; + } } -if ( openZmWindow ) -{ - zmWindow(); +if ( openZmWindow ) { + zmWindow(); } diff --git a/web/skins/classic/views/js/video.js b/web/skins/classic/views/js/video.js index 5c4bdebce..c4af2260a 100644 --- a/web/skins/classic/views/js/video.js +++ b/web/skins/classic/views/js/video.js @@ -1,38 +1,33 @@ -function deleteVideo( index ) -{ - window.location.replace( thisUrl+'?view='+currentView+'&eid='+eventId+'&deleteIndex='+index ); +function deleteVideo( index ) { + window.location.replace( thisUrl+'?view='+currentView+'&eid='+eventId+'&deleteIndex='+index ); } -function downloadVideo( index ) -{ - window.location.replace( thisUrl+'?view='+currentView+'&eid='+eventId+'&downloadIndex='+index ); +function downloadVideo( index ) { + window.location.replace( thisUrl+'?view='+currentView+'&eid='+eventId+'&downloadIndex='+index ); } var generateVideoTimer = null; -function generateVideoProgress() -{ - var tickerText = $('videoProgressTicker').get('text'); - if ( tickerText.length < 1 || tickerText.length > 4 ) - $('videoProgressTicker').set( 'text', '.' ); - else - $('videoProgressTicker').appendText( '.' ); +function generateVideoProgress() { + var tickerText = $('videoProgressTicker').get('text'); + if ( tickerText.length < 1 || tickerText.length > 4 ) + $('videoProgressTicker').set( 'text', '.' ); + else + $('videoProgressTicker').appendText( '.' ); } -function generateVideoResponse( respObj, respText ) -{ - window.location.replace( thisUrl+'?view='+currentView+'&eid='+eventId+'&generated='+((respObj.result=='Ok')?1:0) ); +function generateVideoResponse( respObj, respText ) { + window.location.replace( thisUrl+'?view='+currentView+'&eid='+eventId+'&generated='+((respObj.result=='Ok')?1:0) ); } -function generateVideo( form ) -{ - var parms = 'view=request&request=event&action=video'; - parms += '&'+$(form).toQueryString(); - var query = new Request.JSON( { url: thisUrl, method: 'post', data: parms, onSuccess: generateVideoResponse } ); - query.send(); - $('videoProgress').removeClass( 'hidden' ); - $('videoProgress').setProperty( 'class', 'warnText' ); - $('videoProgressText').set( 'text', videoGenProgressString ); - generateVideoProgress(); - generateVideoTimer = generateVideoProgress.periodical( 500 ); +function generateVideo( form ) { + var parms = 'view=request&request=event&action=video'; + parms += '&'+$(form).toQueryString(); + var query = new Request.JSON( { url: thisUrl, method: 'post', data: parms, onSuccess: generateVideoResponse } ); + query.send(); + $('videoProgress').removeClass( 'hidden' ); + $('videoProgress').setProperty( 'class', 'warnText' ); + $('videoProgressText').set( 'text', videoGenProgressString ); + generateVideoProgress(); + generateVideoTimer = generateVideoProgress.periodical( 500 ); } diff --git a/web/skins/classic/views/js/watch.js b/web/skins/classic/views/js/watch.js index c7fd09ae6..4512b2e05 100644 --- a/web/skins/classic/views/js/watch.js +++ b/web/skins/classic/views/js/watch.js @@ -1,4 +1,3 @@ -<<<<<<< HEAD function setButtonState( element, butClass ) { element.className = butClass; element.disabled = (butClass != 'inactive'); @@ -37,58 +36,10 @@ function changeScale() { streamImg.style.width = newWidth + "px"; streamImg.style.height = newHeight + "px"; - streamImg.src = streamImg.src.replace(/scale=\d+/i,'scale='+scale); + streamImg.src = streamImg.src.replace(/scale=\d+/i, 'scale='+scale); } else { console.error("No element found for liveStream."); } -======= -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"; -} - -function showPtzControls() -{ - $('events').addClass( 'hidden' ); - $('ptzControls').removeClass( 'hidden' ); - if ( $('eventsControl') ) - $('eventsControl').removeClass('hidden'); - if ( $('controlControl') ) - $('controlControl').addClass('hidden'); - showMode = "control"; -} - -function changeScale() -{ - var scale = $('scale').get('value'); - var newWidth = ( monitorWidth * scale ) / SCALE_BASE; - var newHeight = ( monitorHeight * scale ) / SCALE_BASE; - - Cookie.write( 'zmWatchScale'+monitorId, scale, { duration: 10*365 } ); - - /*Stream could be an applet so can't use moo tools*/ - var streamImg = document.getElementById('liveStream'); - if ( streamImg ) { - streamImg.style.width = newWidth + "px"; - streamImg.style.height = newHeight + "px"; - - streamImg.src = streamImg.src.replace(/scale=\d+/i, 'scale='+scale); - } else { - console.error("No element found for liveStream."); - } ->>>>>>> master } var alarmState = STATE_IDLE; @@ -192,64 +143,10 @@ function getStreamCmdResponse( respObj, respText ) { if ( streamStatus.rate < 1 ) streamCmdSlowFwd( false ); else -<<<<<<< HEAD streamCmdFastFwd( false ); } else { if ( streamStatus.rate > -1 ) streamCmdSlowRev( false ); -======= - $('levelValue').className = "ok"; - - var delayString = secsToTime( streamStatus.delay ); - - if ( streamStatus.paused == true ) - { - $('modeValue').set( 'text', "Paused" ); - $('rate').addClass( 'hidden' ); - $('delayValue').set( 'text', delayString ); - $('delay').removeClass( 'hidden' ); - $('level').removeClass( 'hidden' ); - streamCmdPause( false ); - } - else if ( streamStatus.delayed == true ) - { - $('modeValue').set( 'text', "Replay" ); - $('rateValue').set( 'text', streamStatus.rate ); - $('rate').removeClass( 'hidden' ); - $('delayValue').set( 'text', delayString ); - $('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 ); - } - else - { - if ( streamStatus.rate > -1 ) - streamCmdSlowRev( false ); - else - streamCmdFastRev( false ); - } - } - else - { - $('modeValue').set( 'text', "Live" ); - $('rate').addClass( 'hidden' ); - $('delay').addClass( 'hidden' ); - $('level').addClass( 'hidden' ); - streamCmdPlay( false ); - } - $('zoomValue').set( 'text', streamStatus.zoom ); - if ( streamStatus.zoom == "1.0" ) - setButtonState( $('zoomOutBtn'), 'unavail' ); ->>>>>>> master else streamCmdFastRev( false ); } // rate @@ -304,29 +201,13 @@ function getStreamCmdResponse( respObj, respText ) { } else { console.log("Unable to find streamImg liveStream"); } -<<<<<<< HEAD } var streamCmdTimeout = statusRefreshTimeout; if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) streamCmdTimeout = streamCmdTimeout/5; streamCmdTimer = streamCmdQuery.delay( streamCmdTimeout ); -} -======= - else { - checkStreamForErrors("getStreamCmdResponse", respObj);//log them - // Try to reload the image stream. - var streamImg = document.getElementById('liveStream'); - if ( streamImg ) - streamImg.src = streamImg.src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) )); - } - - var streamCmdTimeout = statusRefreshTimeout; - if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) - streamCmdTimeout = streamCmdTimeout/5; - streamCmdTimer = streamCmdQuery.delay( streamCmdTimeout ); } ->>>>>>> master function streamCmdPause( action ) { setButtonState( $('pauseBtn'), 'active' ); @@ -355,7 +236,6 @@ function streamCmdPlay( action ) { setButtonState( $('slowFwdBtn'), 'unavail' ); setButtonState( $('slowRevBtn'), 'unavail' ); setButtonState( $('fastRevBtn'), 'unavail' ); -<<<<<<< HEAD } if ( action ) streamCmdReq.send( streamCmdParms+"&command="+CMD_PLAY ); @@ -445,169 +325,43 @@ function streamCmdPan( x, y ) { function streamCmdQuery() { streamCmdReq.send( streamCmdParms+"&command="+CMD_QUERY ); -} -======= - if ( action ) - streamCmdReq.send( streamCmdParms+"&command="+CMD_STOP ); - 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 ) - streamCmdReq.send( streamCmdParms+"&command="+CMD_FASTFWD ); -} - -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 ) - streamCmdReq.send( streamCmdParms+"&command="+CMD_SLOWFWD ); - 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 ) - streamCmdReq.send( streamCmdParms+"&command="+CMD_SLOWREV ); - 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 ) - streamCmdReq.send( streamCmdParms+"&command="+CMD_FASTREV ); -} - -function streamCmdZoomIn( x, y ) -{ - streamCmdReq.send( streamCmdParms+"&command="+CMD_ZOOMIN+"&x="+x+"&y="+y ); -} - -function streamCmdZoomOut() -{ - streamCmdReq.send( streamCmdParms+"&command="+CMD_ZOOMOUT ); -} - -function streamCmdScale( scale ) -{ - streamCmdReq.send( streamCmdParms+"&command="+CMD_SCALE+"&scale="+scale ); -} - -function streamCmdPan( x, y ) -{ - streamCmdReq.send( streamCmdParms+"&command="+CMD_PAN+"&x="+x+"&y="+y ); -} - -function streamCmdQuery() -{ - streamCmdReq.send( streamCmdParms+"&command="+CMD_QUERY ); -} ->>>>>>> master - var statusCmdParms = "view=request&request=status&entity=monitor&id="+monitorId+"&element[]=Status&element[]=FrameRate"; if ( auth_hash ) statusCmdParms += '&auth='+auth_hash; var statusCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'get', data: statusCmdParms, timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getStatusCmdResponse } ); var statusCmdTimer = null; -<<<<<<< HEAD function getStatusCmdResponse( respObj, respText ) { -console.log("Got statusCmdQuery"); watchdogOk("status"); if ( statusCmdTimer ) statusCmdTimer = clearTimeout( statusCmdTimer ); if ( respObj.result == 'Ok' ) { -console.log("Got ok for status"); $('fpsValue').set( 'text', respObj.monitor.FrameRate ); setAlarmState( respObj.monitor.Status ); - } else { - console.log("Got bad response for status"); - checkStreamForErrors("getStatusCmdResponse",respObj); - } + } else + checkStreamForErrors("getStatusCmdResponse", respObj); var statusCmdTimeout = statusRefreshTimeout; if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) statusCmdTimeout = statusCmdTimeout/5; statusCmdTimer = statusCmdQuery.delay( statusCmdTimeout ); -} +} function statusCmdQuery() { -console.log("Sending statusCmdQuery"); statusCmdReq.send(); -} -======= -function getStatusCmdResponse( respObj, respText ) -{ - watchdogOk("status"); - if ( statusCmdTimer ) - statusCmdTimer = clearTimeout( statusCmdTimer ); - - if ( respObj.result == 'Ok' ) - { - $('fpsValue').set( 'text', respObj.monitor.FrameRate ); - setAlarmState( respObj.monitor.Status ); - } - else - checkStreamForErrors("getStatusCmdResponse", respObj); - - var statusCmdTimeout = statusRefreshTimeout; - if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) - statusCmdTimeout = statusCmdTimeout/5; - statusCmdTimer = statusCmdQuery.delay( statusCmdTimeout ); } -function statusCmdQuery() -{ - statusCmdReq.send(); -} ->>>>>>> master - var alarmCmdParms = "view=request&request=alarm&id="+monitorId; if ( auth_hash ) alarmCmdParms += '&auth='+auth_hash; var alarmCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getAlarmCmdResponse, onTimeout: streamCmdQuery } ); var alarmCmdFirst = true; -<<<<<<< HEAD function getAlarmCmdResponse( respObj, respText ) { - checkStreamForErrors("getAlarmCmdResponse",respObj); -======= -function getAlarmCmdResponse( respObj, respText ) -{ - checkStreamForErrors("getAlarmCmdResponse", respObj); ->>>>>>> master + checkStreamForErrors("getAlarmCmdResponse", respObj); } function cmdDisableAlarms() { @@ -649,7 +403,6 @@ var eventCmdReq = new Request.JSON( { url: thisUrl, method: 'post', timeout: AJA var eventCmdTimer = null; var eventCmdFirst = true; -<<<<<<< HEAD function highlightRow( row ) { $(row).toggleClass( 'highlight' ); } @@ -712,87 +465,6 @@ function getEventCmdResponse( respObj, respText ) { row.inject( $(eventListBody), 'top' ); if ( !eventCmdFirst ) row.addClass( 'recent' ); -======= -function highlightRow( row ) -{ - $(row).toggleClass( 'highlight' ); -} - -function getEventCmdResponse( respObj, respText ) -{ - watchdogOk("event"); - if ( eventCmdTimer ) - eventCmdTimer = clearTimeout( eventCmdTimer ); - - if ( respObj.result == 'Ok' ) - { - var dbEvents = respObj.events.reverse(); - var eventList = $('eventList'); - var eventListBody = $(eventList).getElement( 'tbody' ); - var eventListRows = $(eventListBody).getElements( 'tr' ); - - eventListRows.each( function( row ) { row.removeClass( 'updated' ); } ); - - for ( var i = 0; i < dbEvents.length; i++ ) - { - 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' } ).inject( row ); - new Element( 'td', { 'class': 'colName' } ).inject( row ); - new Element( 'td', { 'class': 'colTime' } ).inject( row ); - new Element( 'td', { 'class': 'colSecs' } ).inject( row ); - new Element( 'td', { 'class': 'colFrames' } ).inject( row ); - new Element( 'td', { 'class': 'colScore' } ).inject( row ); - new Element( 'td', { 'class': 'colDelete' } ).inject( 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] ) } }); - link.set( 'text', event.Id ); - link.inject( 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] ) } }); - link.set( 'text', event.Name ); - link.inject( row.getElement( 'td.colName' ) ); - - row.getElement( 'td.colTime' ).set( 'text', event.StartTime ); - row.getElement( 'td.colSecs' ).set( 'text', event.Length ); - - link = new Element( 'a', { 'href': '#', 'events': { 'click': createFramesPopup.pass( [event.Id, event.Width, event.Height] ) } }); - link.set( 'text', event.Frames+'/'+event.AlarmFrames ); - link.inject( row.getElement( 'td.colFrames' ) ); - - link = new Element( 'a', { 'href': '#', 'events': { 'click': createFramePopup.pass( [event.Id, '0', event.Width, event.Height] ) } }); - link.set( 'text', event.AvgScore+'/'+event.MaxScore ); - link.inject( row.getElement( 'td.colScore' ) ); - - link = new Element( 'a', { 'href': '#', 'title': deleteString, 'events': { 'click': function( e ) { deleteEvent( e, event.Id ); }, 'mouseover': highlightRow.pass( row ), 'mouseout': highlightRow.pass( row ) } }); - link.set( 'text', 'X' ); - link.inject( row.getElement( 'td.colDelete' ) ); - - if ( i == 0 ) - row.inject( $(eventListBody) ); - else - { - row.inject( $(eventListBody), 'top' ); - if ( !eventCmdFirst ) - row.addClass( 'recent' ); - } - } - else - { - 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 ); - row.removeClass( 'recent' ); - } - row.addClass( 'updated' ); ->>>>>>> master } } else { row.getElement( 'td.colName a' ).set( 'text', event.Name ); @@ -812,17 +484,12 @@ function getEventCmdResponse( respObj, respText ) i--; } } -<<<<<<< HEAD while ( rows.length > maxDisplayEvents ) { rows[rows.length-1].destroy(); rows.length--; } } else - checkStreamForErrors("getEventCmdResponse",respObj); -======= - else - checkStreamForErrors("getEventCmdResponse", respObj); ->>>>>>> master + checkStreamForErrors("getEventCmdResponse", respObj); var eventCmdTimeout = eventsRefreshTimeout; if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) @@ -863,7 +530,7 @@ function controlCmd( control, event, xtell, ytell ) { var x = xEvent.page.x - l; var y = xEvent.page.y - t; - if ( xtell ) { + if ( xtell ) { var xge = parseInt( (x*100)/coords.width ); if ( xtell == -1 ) xge = 100 - xge; @@ -871,7 +538,6 @@ function controlCmd( control, event, xtell, ytell ) { xge = 2*(50 - xge); locParms += "&xge="+xge; } -<<<<<<< HEAD if ( ytell ) { var yge = parseInt( (y*100)/coords.height ); if ( ytell == -1 ) @@ -879,42 +545,6 @@ function controlCmd( control, event, xtell, ytell ) { else if ( ytell == 2 ) yge = 2*(50 - yge); locParms += "&yge="+yge; -======= -} - -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; - } ->>>>>>> master } } controlReq.send( controlParms+"&control="+control+locParms ); @@ -927,7 +557,6 @@ function controlCmdImage( x, y ) { imageControlParms += "&scale="+scale; imageControlParms += "&control="+imageControlMode; -<<<<<<< HEAD controlReq.send( imageControlParms+"&x="+x+"&y="+y ); if ( streamMode == "single" ) fetchImage.pass( $('imageFeed').getElement('img') ).delay( 1000 ); @@ -935,40 +564,6 @@ function controlCmdImage( x, y ) { function fetchImage( streamImage ) { streamImage.src = streamImage.src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) )); -======= - controlReq.send( imageControlParms+"&x="+x+"&y="+y ); - 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 ); - } ->>>>>>> master } function handleClick( event ) { @@ -1017,7 +612,6 @@ function watchdogCheck( type ) { console.log( "Detected streamWatch of type: " + type + " stopped, restarting" ); watchdogFunctions[type](); watchdogInactive[type] = false; -<<<<<<< HEAD } else { watchdogInactive[type] = true; } @@ -1052,42 +646,6 @@ function initPage() { if ( refreshApplet && appletRefreshTime ) appletRefresh.delay( appletRefreshTime*1000 ); -======= -} - -function initPage() -{ - if ( streamMode == "single" ) - { - statusCmdTimer = statusCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout ); - watchdogCheck.pass('status').periodical(statusRefreshTimeout*2); - } - else - { - streamCmdTimer = streamCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout ); - watchdogCheck.pass('stream').periodical(statusRefreshTimeout*2); - } - - eventCmdTimer = eventCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout ); - watchdogCheck.pass('event').periodical(eventsRefreshTimeout*2); - - if ( canStreamNative || streamMode == "single" ) - { - var streamImg = $('imageFeed').getElement('img'); - if ( !streamImg ) - streamImg = $('imageFeed').getElement('object'); - if ( streamMode == "single" ) - { - streamImg.addEvent( 'click', fetchImage.pass( streamImg ) ); - fetchImage.pass( streamImg ).periodical( imageRefreshTimeout ); - } - else - streamImg.addEvent( 'click', function( event ) { handleClick( event ); } ); - } - - if ( refreshApplet && appletRefreshTime ) - appletRefresh.delay( appletRefreshTime*1000 ); ->>>>>>> master } // Kick everything off diff --git a/web/skins/classic/views/js/zone.js b/web/skins/classic/views/js/zone.js index 60637bf55..e24cc87dd 100644 --- a/web/skins/classic/views/js/zone.js +++ b/web/skins/classic/views/js/zone.js @@ -1,633 +1,72 @@ function validateForm( form ) { - var errors = new Array(); - if ( selfIntersecting ) { - errors[errors.length] = selfIntersectingString; + var errors = new Array(); + if ( selfIntersecting ) { + errors[errors.length] = selfIntersectingString; + } + if ( form.elements['newZone[Type]'].value != 'Inactive' && form.elements['newZone[Type]'].value != 'Privacy' ) { + if ( !form.newAlarmRgbR.value || !form.newAlarmRgbG.value || !form.newAlarmRgbB.value ) { + errors[errors.length] = alarmRGBUnsetString; } - if ( form.elements['newZone[Type]'].value != 'Inactive' && form.elements['newZone[Type]'].value != 'Privacy' ) { - if ( !form.newAlarmRgbR.value || !form.newAlarmRgbG.value || !form.newAlarmRgbB.value ) { - errors[errors.length] = alarmRGBUnsetString; - } - form.elements['newZone[AlarmRGB]'].value = (form.newAlarmRgbR.value<<16)|(form.newAlarmRgbG.value<<8)|form.newAlarmRgbB.value; - if ( !form.elements['newZone[MinPixelThreshold]'].value || (parseInt(form.elements['newZone[MinPixelThreshold]'].value) <= 0 ) ) { - errors[errors.length] = minPixelThresUnsetString; - } else if ( (parseInt(form.elements['newZone[MinPixelThreshold]'].value) >= parseInt(form.elements['newZone[MaxPixelThreshold]'].value)) && (parseInt(form.elements['newZone[MaxPixelThreshold]'].value) > 0) ) { - errors[errors.length] = minPixelThresLtMaxString; - } - if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' || form.elements['newZone[CheckMethod]'].value == 'Blobs' ) { - if ( !form.elements['newZone[FilterX]'].value || !form.elements['newZone[FilterY]'].value ) { - errors[errors.length] = filterUnsetString; - } - } - if ( !form.elements['newZone[MinAlarmPixels]'].value || (parseFloat(form.elements['newZone[MinAlarmPixels]'].value) <= 0 ) ) { - errors[errors.length] = minAlarmAreaUnsetString; - } else if ( (parseFloat(form.elements['newZone[MinAlarmPixels]'].value) >= parseFloat(form.elements['newZone[MaxAlarmPixels]'].value)) && (parseFloat(form.elements['newZone[MaxAlarmPixels]'].value) > 0) ) { - errors[errors.length] = minAlarmAreaLtMaxString; - } - if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' || form.elements['newZone[CheckMethod]'].value == 'Blobs' ) { - if ( !form.elements['newZone[MinFilterPixels]'].value || (parseFloat(form.elements['newZone[MinFilterPixels]'].value) <= 0 ) ) { - errors[errors.length] = minFilterAreaUnsetString; - } else if ( (parseFloat(form.elements['newZone[MinFilterPixels]'].value) >= parseFloat(form.elements['newZone[MaxFilterPixels]'].value)) && (parseFloat(form.elements['newZone[MaxFilterPixels]'].value) > 0) ) { - errors[errors.length] = minFilterAreaLtMaxString; - } else if ( parseFloat(form.elements['newZone[MinAlarmPixels]'].value) < parseFloat(form.elements['newZone[MinFilterPixels]'].value) ) { - errors[errors.length] = minFilterLtMinAlarmString; - } - if ( form.elements['newZone[CheckMethod]'].value == 'Blobs' ) { - if ( !form.elements['newZone[MinBlobPixels]'].value || (parseFloat(form.elements['newZone[MinBlobPixels]'].value) <= 0 ) ) { - errors[errors.length] = minBlobAreaUnsetString; - } else if ( (parseFloat(form.elements['newZone[MinBlobPixels]'].value) >= parseFloat(form.elements['newZone[MaxBlobPixels]'].value)) && (parseFloat(form.elements['newZone[MaxBlobPixels]'].value) > 0) ) { - errors[errors.length] = minBlobAreaLtMaxString; - } else if ( parseFloat(form.elements['newZone[MinFilterPixels]'].value) < parseFloat(form.elements['newZone[MinBlobPixels]'].value) ) { - errors[errors.length] = minBlobLtMinFilterString; - } - if ( !form.elements['newZone[MinBlobs]'].value || (parseInt(form.elements['newZone[MinBlobs]'].value) <= 0 ) ) { - errors[errors.length] = minBlobsUnsetString; - } else if ( (parseInt(form.elements['newZone[MinBlobs]'].value) >= parseInt(form.elements['newZone[MaxBlobs]'].value)) && (parseInt(form.elements['newZone[MaxBlobs]'].value) > 0) ) { - errors[errors.length] = minBlobsLtMaxString; - } - } - } + form.elements['newZone[AlarmRGB]'].value = (form.newAlarmRgbR.value<<16)|(form.newAlarmRgbG.value<<8)|form.newAlarmRgbB.value; + if ( !form.elements['newZone[MinPixelThreshold]'].value || (parseInt(form.elements['newZone[MinPixelThreshold]'].value) <= 0 ) ) { + errors[errors.length] = minPixelThresUnsetString; + } else if ( (parseInt(form.elements['newZone[MinPixelThreshold]'].value) >= parseInt(form.elements['newZone[MaxPixelThreshold]'].value)) && (parseInt(form.elements['newZone[MaxPixelThreshold]'].value) > 0) ) { + errors[errors.length] = minPixelThresLtMaxString; } - if ( errors.length ) { - alert( errors.join( "\n" ) ); - return( false ); + if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' || form.elements['newZone[CheckMethod]'].value == 'Blobs' ) { + if ( !form.elements['newZone[FilterX]'].value || !form.elements['newZone[FilterY]'].value ) { + errors[errors.length] = filterUnsetString; + } } - return( true ); + if ( !form.elements['newZone[MinAlarmPixels]'].value || (parseFloat(form.elements['newZone[MinAlarmPixels]'].value) <= 0 ) ) { + errors[errors.length] = minAlarmAreaUnsetString; + } else if ( (parseFloat(form.elements['newZone[MinAlarmPixels]'].value) >= parseFloat(form.elements['newZone[MaxAlarmPixels]'].value)) && (parseFloat(form.elements['newZone[MaxAlarmPixels]'].value) > 0) ) { + errors[errors.length] = minAlarmAreaLtMaxString; + } + if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' || form.elements['newZone[CheckMethod]'].value == 'Blobs' ) { + if ( !form.elements['newZone[MinFilterPixels]'].value || (parseFloat(form.elements['newZone[MinFilterPixels]'].value) <= 0 ) ) { + errors[errors.length] = minFilterAreaUnsetString; + } else if ( (parseFloat(form.elements['newZone[MinFilterPixels]'].value) >= parseFloat(form.elements['newZone[MaxFilterPixels]'].value)) && (parseFloat(form.elements['newZone[MaxFilterPixels]'].value) > 0) ) { + errors[errors.length] = minFilterAreaLtMaxString; + } else if ( parseFloat(form.elements['newZone[MinAlarmPixels]'].value) < parseFloat(form.elements['newZone[MinFilterPixels]'].value) ) { + errors[errors.length] = minFilterLtMinAlarmString; + } + if ( form.elements['newZone[CheckMethod]'].value == 'Blobs' ) { + if ( !form.elements['newZone[MinBlobPixels]'].value || (parseFloat(form.elements['newZone[MinBlobPixels]'].value) <= 0 ) ) { + errors[errors.length] = minBlobAreaUnsetString; + } else if ( (parseFloat(form.elements['newZone[MinBlobPixels]'].value) >= parseFloat(form.elements['newZone[MaxBlobPixels]'].value)) && (parseFloat(form.elements['newZone[MaxBlobPixels]'].value) > 0) ) { + errors[errors.length] = minBlobAreaLtMaxString; + } else if ( parseFloat(form.elements['newZone[MinFilterPixels]'].value) < parseFloat(form.elements['newZone[MinBlobPixels]'].value) ) { + errors[errors.length] = minBlobLtMinFilterString; + } + if ( !form.elements['newZone[MinBlobs]'].value || (parseInt(form.elements['newZone[MinBlobs]'].value) <= 0 ) ) { + errors[errors.length] = minBlobsUnsetString; + } else if ( (parseInt(form.elements['newZone[MinBlobs]'].value) >= parseInt(form.elements['newZone[MaxBlobs]'].value)) && (parseInt(form.elements['newZone[MaxBlobs]'].value) > 0) ) { + errors[errors.length] = minBlobsLtMaxString; + } + } + } + } + if ( errors.length ) { + alert( errors.join( "\n" ) ); + return( false ); + } + return( true ); } function submitForm( form ) { - form.elements['newZone[AlarmRGB]'].value = (form.newAlarmRgbR.value<<16)|(form.newAlarmRgbG.value<<8)|form.newAlarmRgbB.value; - form.elements['newZone[NumCoords]'].value = zone['Points'].length; - form.elements['newZone[Coords]'].value = getCoordString(); - form.elements['newZone[Area]'].value = zone.Area; + form.elements['newZone[AlarmRGB]'].value = (form.newAlarmRgbR.value<<16)|(form.newAlarmRgbG.value<<8)|form.newAlarmRgbB.value; + form.elements['newZone[NumCoords]'].value = zone['Points'].length; + form.elements['newZone[Coords]'].value = getCoordString(); + form.elements['newZone[Area]'].value = zone.Area; - form.submit(); + form.submit(); } function applyZoneType() { - var form = document.zoneForm; - if ( form.elements['newZone[Type]'].value == 'Inactive' || form.elements['newZone[Type]'].value == 'Privacy' ) { - form.presetSelector.disabled = true; - form.newAlarmRgbR.disabled = true; - form.newAlarmRgbG.disabled = true; - form.newAlarmRgbB.disabled = true; - form.elements['newZone[CheckMethod]'].disabled = true; - form.elements['newZone[MinPixelThreshold]'].disabled = true; - form.elements['newZone[MaxPixelThreshold]'].disabled = true; - form.elements['newZone[MinAlarmPixels]'].disabled = true; - form.elements['newZone[MaxAlarmPixels]'].disabled = true; - form.elements['newZone[FilterX]'].disabled = true; - form.elements['newZone[FilterY]'].disabled = true; - form.elements['newZone[MinFilterPixels]'].disabled = true; - form.elements['newZone[MaxFilterPixels]'].disabled = true; - form.elements['newZone[MinBlobPixels]'].disabled = true; - form.elements['newZone[MaxBlobPixels]'].disabled = true; - form.elements['newZone[MinBlobs]'].disabled = true; - form.elements['newZone[MaxBlobs]'].disabled = true; - form.elements['newZone[OverloadFrames]'].disabled = true; - form.elements['newZone[ExtendAlarmFrames]'].disabled = true; - } else if ( form.elements['newZone[Type]'].value == 'Preclusive' ) { - form.presetSelector.disabled = false; - form.newAlarmRgbR.disabled = true; - form.newAlarmRgbG.disabled = true; - form.newAlarmRgbB.disabled = true; - form.elements['newZone[CheckMethod]'].disabled = false; - form.elements['newZone[MinPixelThreshold]'].disabled = false; - form.elements['newZone[MaxPixelThreshold]'].disabled = false; - form.elements['newZone[MinAlarmPixels]'].disabled = false; - form.elements['newZone[MaxAlarmPixels]'].disabled = false; - form.elements['newZone[OverloadFrames]'].disabled = false; - form.elements['newZone[ExtendAlarmFrames]'].disabled = false; - applyCheckMethod(); - } else { - form.presetSelector.disabled = false; - form.newAlarmRgbR.disabled = false; - form.newAlarmRgbG.disabled = false; - form.newAlarmRgbB.disabled = false; - form.elements['newZone[CheckMethod]'].disabled = false; - form.elements['newZone[MinPixelThreshold]'].disabled = false; - form.elements['newZone[MaxPixelThreshold]'].disabled = false; - form.elements['newZone[MinAlarmPixels]'].disabled = false; - form.elements['newZone[MaxAlarmPixels]'].disabled = false; - form.elements['newZone[OverloadFrames]'].disabled = false; - form.elements['newZone[ExtendAlarmFrames]'].disabled = true; - applyCheckMethod(); - } -} - -function applyCheckMethod() { - var form = document.zoneForm; - if ( form.elements['newZone[CheckMethod]'].value == 'AlarmedPixels' ) { - form.elements['newZone[FilterX]'].disabled = true; - form.elements['newZone[FilterY]'].disabled = true; - form.elements['newZone[MinFilterPixels]'].disabled = true; - form.elements['newZone[MaxFilterPixels]'].disabled = true; - form.elements['newZone[MinBlobPixels]'].disabled = true; - form.elements['newZone[MaxBlobPixels]'].disabled = true; - form.elements['newZone[MinBlobs]'].disabled = true; - form.elements['newZone[MaxBlobs]'].disabled = true; - } else if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' ) { - form.elements['newZone[FilterX]'].disabled = false; - form.elements['newZone[FilterY]'].disabled = false; - form.elements['newZone[MinFilterPixels]'].disabled = false; - form.elements['newZone[MaxFilterPixels]'].disabled = false; - form.elements['newZone[MinBlobPixels]'].disabled = true; - form.elements['newZone[MaxBlobPixels]'].disabled = true; - form.elements['newZone[MinBlobs]'].disabled = true; - form.elements['newZone[MaxBlobs]'].disabled = true; - } else { - form.elements['newZone[FilterX]'].disabled = false; - form.elements['newZone[FilterY]'].disabled = false; - form.elements['newZone[MinFilterPixels]'].disabled = false; - form.elements['newZone[MaxFilterPixels]'].disabled = false; - form.elements['newZone[MinBlobPixels]'].disabled = false; - form.elements['newZone[MaxBlobPixels]'].disabled = false; - form.elements['newZone[MinBlobs]'].disabled = false; - form.elements['newZone[MaxBlobs]'].disabled = false; - } -} - -function applyPreset() { - var form = document.zoneForm; - var presetId = $('presetSelector').get('value'); - - if ( presets[presetId] ) { - var preset = presets[presetId]; - - form.elements['newZone[Units]'].selectedIndex = preset['UnitsIndex']; - form.elements['newZone[CheckMethod]'].selectedIndex = preset['CheckMethodIndex']; - form.elements['newZone[MinPixelThreshold]'].value = preset['MinPixelThreshold']; - form.elements['newZone[MaxPixelThreshold]'].value = preset['MaxPixelThreshold']; - form.elements['newZone[FilterX]'].value = preset['FilterX']; - form.elements['newZone[FilterY]'].value = preset['FilterY']; - form.elements['newZone[MinAlarmPixels]'].value = preset['MinAlarmPixels']; - form.elements['newZone[MaxAlarmPixels]'].value = preset['MaxAlarmPixels']; - form.elements['newZone[MinFilterPixels]'].value = preset['MinFilterPixels']; - form.elements['newZone[MaxFilterPixels]'].value = preset['MaxFilterPixels']; - form.elements['newZone[MinBlobPixels]'].value = preset['MinBlobPixels']; - form.elements['newZone[MaxBlobPixels]'].value = preset['MaxBlobPixels']; - form.elements['newZone[MinBlobs]'].value = preset['MinBlobs']; - form.elements['newZone[MaxBlobs]'].value = preset['MaxBlobs']; - form.elements['newZone[OverloadFrames]'].value = preset['OverloadFrames']; - form.elements['newZone[ExtendAlarmFrames]'].value = preset['ExtendAlarmFrames']; - - applyCheckMethod(); - form.elements['newZone[TempArea]'].value = 100; - } -} - -function toPixels( field, maxValue ) { - if ( field.value != '' ) - field.value = Math.round((field.value*maxValue)/100); -} - -function toPercent( field, maxValue ) { - if ( field.value != '' ) - field.value = Math.round((100*100*field.value)/maxValue)/100; -} - -function applyZoneUnits() { - var area = zone.Area; - - var form = document.zoneForm; - if ( form.elements['newZone[Units]'].value == 'Pixels' ) { - form.elements['newZone[TempArea]'].value = area; - toPixels( form.elements['newZone[MinAlarmPixels]'], area ); - toPixels( form.elements['newZone[MaxAlarmPixels]'], area ); - toPixels( form.elements['newZone[MinFilterPixels]'], area ); - toPixels( form.elements['newZone[MaxFilterPixels]'], area ); - toPixels( form.elements['newZone[MinBlobPixels]'], area ); - toPixels( form.elements['newZone[MaxBlobPixels]'], area ); - } else { - form.elements['newZone[TempArea]'].value = Math.round( area/monitorArea * 100 ); - toPercent( form.elements['newZone[MinAlarmPixels]'], area ); - toPercent( form.elements['newZone[MaxAlarmPixels]'], area ); - toPercent( form.elements['newZone[MinFilterPixels]'], area ); - toPercent( form.elements['newZone[MaxFilterPixels]'], area ); - toPercent( form.elements['newZone[MinBlobPixels]'], area ); - toPercent( form.elements['newZone[MaxBlobPixels]'], area ); - } -} - -function limitRange( field, minValue, maxValue ) { - if ( field.value != '' ) - field.value = constrainValue( parseInt(field.value), parseInt(minValue), parseInt(maxValue) ); -} - -function limitFilter( field ) { - field.value = (Math.floor((field.value-1)/2)*2) + 1; - field.value = constrainValue(parseInt(field.value), 3, 15); -} - -function limitArea( field ) { - var minValue = 0; - var maxValue = zone.Area; - if ( document.zoneForm.elements['newZone[Units]'].value == "Percent" ) { - maxValue = 100; - } - limitRange( field, minValue, maxValue ); -} - -function highlightOn( index ) { - $('row'+index).addClass( 'highlight' ); - $('point'+index).addClass( 'highlight' ); -} - -function highlightOff( index ) { - $('row'+index).removeClass( 'highlight' ); - $('point'+index).removeClass( 'highlight' ); -} - -function setActivePoint( index ) { - highlightOff( index ); - $('row'+index).addClass( 'active' ); - $('point'+index).addClass( 'active' ); -} - -function unsetActivePoint( index ) { - $('row'+index).removeClass( 'active' ); - $('point'+index).removeClass( 'active' ); -} - -function getCoordString() { - var coords = new Array(); - for ( var i = 0; i < zone['Points'].length; i++ ) - coords[coords.length] = zone['Points'][i].x+','+zone['Points'][i].y; - return( coords.join( " " ) ); -} - -function updateZoneImage() { - var SVG = $('zoneSVG'); - var Poly = $('zonePoly'); - Poly.points.clear(); - for ( var i = 0; i < zone['Points'].length; i++ ) { - var Point = SVG.createSVGPoint(); - Point.x = zone['Points'][i].x; - Point.y = zone['Points'][i].y; - Poly.points.appendItem( Point ); - } -} - -function fixActivePoint( index ) { - updateActivePoint( index ); - unsetActivePoint( index ); - updateZoneImage(); -} - -function constrainValue( value, loVal, hiVal ) { - if ( value < loVal ) { - return loVal; - } - if ( value > hiVal ) { - return hiVal; - } - return value; -} - -function updateActivePoint( index ) { - var point = $('point'+index); - var x = constrainValue( point.getStyle( 'left' ).toInt(), 0, maxX ); - var y = constrainValue( point.getStyle( 'top' ).toInt(), 0, maxY ); - - $('newZone[Points]['+index+'][x]').value = x; - $('newZone[Points]['+index+'][y]').value = y; - zone['Points'][index].x = x; - zone['Points'][index].y = y; - var Point = $('zonePoly').points.getItem(index); - Point.x =x; - Point.y =y; - updateArea(); -} - -function addPoint( index ) { - var nextIndex = index+1; - if ( index >= (zone['Points'].length-1) ) - nextIndex = 0; - var newX = parseInt(Math.round((zone['Points'][index]['x']+zone['Points'][nextIndex]['x'])/2)); - var newY = parseInt(Math.round((zone['Points'][index]['y']+zone['Points'][nextIndex]['y'])/2)); - if ( nextIndex == 0 ) - zone['Points'][zone['Points'].length] = { 'x': newX, 'y': newY }; - else - zone['Points'].splice( nextIndex, 0, { 'x': newX, 'y': newY } ); - drawZonePoints(); - // drawZonePoints calls updateZoneImage - //updateZoneImage(); - //setActivePoint( nextIndex ); -} - -function delPoint( index ) { - zone['Points'].splice( index, 1 ); - drawZonePoints(); -} - -<<<<<<< HEAD -function limitPointValue( point, loVal, hiVal ) { -======= -function limitPointValue( point, loVal, hiVal ) -{ ->>>>>>> master - point.value = constrainValue(point.value, loVal, hiVal); -} - -function updateArea( ) { - area = Polygon_calcArea( zone['Points'] ); - zone.Area = area; - var form = $('zoneForm'); - form.elements['newZone[Area]'].value = area; - if ( form.elements['newZone[Units]'].value == 'Percent' ) { - form.elements['newZone[TempArea]'].value = Math.round( area/monitorArea*100 ); - } else if ( form.elements['newZone[Units]'].value == 'Pixels' ) { - form.elements['newZone[TempArea]'].value = area; - } else { - alert("Unknown units: " + form.elements['newZone[Units]'].value ); - } -} - -function updateX( index ) { - limitPointValue( $('newZone[Points]['+index+'][x]'), 0, maxX ); - - var point = $('point'+index); - var x = $('newZone[Points]['+index+'][x]').get('value'); - - point.setStyle( 'left', x+'px' ); - zone['Points'][index].x = x; - var Point = $('zonePoly').points.getItem(index); - Point.x = x; -} - -function updateY( index ) { - limitPointValue( $('newZone[Points]['+index+'][y]'), 0, maxY ); - - var point = $('point'+index); - var y = $('newZone[Points]['+index+'][y]').get('value'); - - point.setStyle( 'top', y+'px' ); - zone['Points'][index].y = y; - var Point = $('zonePoly').points.getItem(index); - Point.y = y; -} - -function saveChanges( element ) { - var form = element.form; - if ( validateForm( form ) ) { - submitForm( form ); - if ( form.elements['newZone[Type]'].value == 'Privacy' ) { - alert( 'Capture process for this monitor will be restarted for the Privacy zone changes to take effect.' ); - } - return( true ); - } - return( false ); -} - -function drawZonePoints() { - $('imageFrame').getElements( 'div.zonePoint' ).each( function( element ) { element.destroy(); } ); - for ( var i = 0; i < zone['Points'].length; i++ ) { - var div = new Element( 'div', { 'id': 'point'+i, 'class': 'zonePoint', 'title': 'Point '+(i+1), 'styles': { 'left': zone['Points'][i].x, 'top': zone['Points'][i].y } } ); - div.addEvent( 'mouseover', highlightOn.pass( i ) ); - div.addEvent( 'mouseout', highlightOff.pass( i ) ); - div.inject( $('imageFrame') ); - div.makeDraggable( { - 'container': $('imageFrame'), - 'onStart': setActivePoint.pass( i ), - 'onComplete': fixActivePoint.pass( i ), - 'onDrag': updateActivePoint.pass( i ) - } ); - } - - var tables = $('zonePoints').getElements( 'table' ); - tables.each( function( table ) { table.getElement( 'tbody' ).empty(); } ); - for ( var i = 0; i < zone['Points'].length; i++ ) { - var row = new Element( 'tr', { 'id': 'row'+i } ); - row.addEvents( { 'mouseover': highlightOn.pass( i ), 'mouseout': highlightOff.pass( i ) } ); - var cell = new Element( 'td' ); - cell.set( 'text', i+1 ); - cell.inject( row ); - - cell = new Element( 'td' ); - var input = new Element( 'input', { 'id': 'newZone[Points]['+i+'][x]', 'name': 'newZone[Points]['+i+'][x]', 'value': zone['Points'][i].x, 'size': 5 } ); - input.addEvent( 'input', updateX.pass( i ) ); - input.inject( cell ); - cell.inject( row ); - - cell = new Element( 'td' ); - input = new Element( 'input', { 'id': 'newZone[Points]['+i+'][y]', 'name': 'newZone[Points]['+i+'][y]', 'value': zone['Points'][i].y, 'size': 5 } ); - input.addEvent( 'input', updateY.pass( i ) ); - input.inject( cell ); - cell.inject( row ); - - cell = new Element( 'td' ); - new Element( 'a', { 'href': '#', 'events': { 'click': addPoint.pass( i ) } } ).set( 'text', '+' ).inject( cell ); - if ( zone['Points'].length > 3 ) - new Element( 'a', { 'id': 'delete'+i, 'href': '#', 'events': { 'click': delPoint.pass( i ) } } ).set( 'text', '-' ).inject( cell ); - cell.inject( row ); - - row.inject( tables[i%tables.length].getElement( 'tbody' ) ); - } - // Sets up the SVG polygon - updateZoneImage(); -} - -// -// Imported from watch.js and modified for new zone edit view -// - -var alarmState = STATE_IDLE; -var lastAlarmState = STATE_IDLE; - -function setAlarmState( currentAlarmState ) { - alarmState = currentAlarmState; - - var stateString = "Unknown"; - var stateClass = ""; - if ( alarmState == STATE_ALARM ) - stateClass = "alarm"; - else if ( alarmState == STATE_ALERT ) - stateClass = "alert"; - $('stateValue').set( 'text', stateStrings[alarmState] ); - if ( stateClass ) - $('stateValue').setProperty( 'class', stateClass ); - else - $('stateValue').removeProperty( 'class' ); - - 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 - if ( !canPlayPauseAudio ) - $('alarmSound').removeClass( 'hidden' ); - else - $('MediaPlayer').Play(); - } - } - if ( SOUND_ON_ALARM ) - { - if ( oldAlarm ) - { - // Disable alarm sound - if ( !canPlayPauseAudio ) - $('alarmSound').addClass( 'hidden' ); - else - $('MediaPlayer').Stop(); - } - } - lastAlarmState = alarmState; -} - -var streamCmdParms = "view=request&request=stream&connkey="+connKey; -var streamCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getStreamCmdResponse } ); -var streamCmdTimer = null; - -var streamStatus; - -function getStreamCmdResponse( respObj, respText ) { - watchdogOk("stream"); - if ( streamCmdTimer ) - streamCmdTimer = clearTimeout( streamCmdTimer ); - - if ( respObj.result == 'Ok' ) { - streamStatus = respObj.status; - $('fpsValue').set( 'text', streamStatus.fps ); - - setAlarmState( streamStatus.state ); - - var delayString = secsToTime( streamStatus.delay ); - - if ( streamStatus.paused == true ) - { - streamCmdPause( false ); - } else if ( streamStatus.delayed == true && streamStatus.rate == 1 ) { - streamCmdPlay( false ); - } - } else { - checkStreamForErrors("getStreamCmdResponse", respObj);//log them - // Try to reload the image stream. - var streamImg = document.getElementById('liveStream'); - if ( streamImg ) - streamImg.src = streamImg.src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) )); - } - - var streamCmdTimeout = statusRefreshTimeout; - if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) - streamCmdTimeout = streamCmdTimeout/5; - streamCmdTimer = streamCmdQuery.delay( streamCmdTimeout ); -} - -var streamPause = false; - -function streamCmdPauseToggle() { - if ( streamPause == true ) { - streamCmdPlay( true ); - streamPause = false; - document.getElementById("pauseBtn").value = pauseString; - } else { - streamCmdPause( true ); - streamPause = true; - document.getElementById("pauseBtn").value = playString; - } -} - -function streamCmdPause( action ) { - if ( action ) - streamCmdReq.send( streamCmdParms+"&command="+CMD_PAUSE ); -} - -function streamCmdPlay( action ) -{ - if ( action ) - streamCmdReq.send( streamCmdParms+"&command="+CMD_PLAY ); -} - -function streamCmdStop( action ) { - if ( action ) - streamCmdReq.send( streamCmdParms+"&command="+CMD_STOP ); -} - -function streamCmdQuery() { - streamCmdReq.send( streamCmdParms+"&command="+CMD_QUERY ); -} - -var statusCmdParms = "view=request&request=status&entity=monitor&id="+monitorId+"&element[]=Status&element[]=FrameRate"; -var statusCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', data: statusCmdParms, timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getStatusCmdResponse } ); -var statusCmdTimer = null; - -function getStatusCmdResponse( respObj, respText ) { - watchdogOk("status"); - if ( statusCmdTimer ) - statusCmdTimer = clearTimeout( statusCmdTimer ); - - if ( respObj.result == 'Ok' ) - { - $('fpsValue').set( 'text', respObj.monitor.FrameRate ); - setAlarmState( respObj.monitor.Status ); - } - else - checkStreamForErrors("getStatusCmdResponse", respObj); - - var statusCmdTimeout = statusRefreshTimeout; - if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) - statusCmdTimeout = statusCmdTimeout/5; - statusCmdTimer = statusCmdQuery.delay( statusCmdTimeout ); -} - -function statusCmdQuery() { - statusCmdReq.send(); -} - -function fetchImage( streamImage ) { - streamImage.src = streamImage.src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) )); -} - -function appletRefresh() { - if ( streamStatus && (!streamStatus.paused && !streamStatus.delayed) ) { - var streamImg = $('liveStream'); - var parent = streamImg.getParent(); - streamImg.dispose(); - streamImg.inject( parent ); - if ( appletRefreshTime ) - appletRefresh.delay( appletRefreshTime*1000 ); - } else { - appletRefresh.delay( 15*1000 ); //if we are paused or delayed check every 15 seconds if we are live yet... - } -} - -var watchdogInactive = { - 'stream': false, - 'status': false -}; - -var watchdogFunctions = { - 'stream': streamCmdQuery, - 'status': statusCmdQuery -}; - -//Make sure the various refreshes are still taking effect -function watchdogCheck( type ) { - if ( watchdogInactive[type] ) { - console.log( "Detected streamWatch of type: " + type + " stopped, restarting" ); - watchdogFunctions[type](); - watchdogInactive[type] = false; - } else { - watchdogInactive[type] = true; - } -} - -function watchdogOk( type ) { - watchdogInactive[type] = false; -} - -function initPage() { - var form = document.zoneForm; - - //form.elements['newZone[Name]'].disabled = true; - //form.elements['newZone[Type]'].disabled = true; + var form = document.zoneForm; + if ( form.elements['newZone[Type]'].value == 'Inactive' || form.elements['newZone[Type]'].value == 'Privacy' ) { form.presetSelector.disabled = true; - //form.elements['newZone[Units]'].disabled = true; form.newAlarmRgbR.disabled = true; form.newAlarmRgbG.disabled = true; form.newAlarmRgbB.disabled = true; @@ -645,40 +84,588 @@ function initPage() { form.elements['newZone[MinBlobs]'].disabled = true; form.elements['newZone[MaxBlobs]'].disabled = true; form.elements['newZone[OverloadFrames]'].disabled = true; + form.elements['newZone[ExtendAlarmFrames]'].disabled = true; + } else if ( form.elements['newZone[Type]'].value == 'Preclusive' ) { + form.presetSelector.disabled = false; + form.newAlarmRgbR.disabled = true; + form.newAlarmRgbG.disabled = true; + form.newAlarmRgbB.disabled = true; + form.elements['newZone[CheckMethod]'].disabled = false; + form.elements['newZone[MinPixelThreshold]'].disabled = false; + form.elements['newZone[MaxPixelThreshold]'].disabled = false; + form.elements['newZone[MinAlarmPixels]'].disabled = false; + form.elements['newZone[MaxAlarmPixels]'].disabled = false; + form.elements['newZone[OverloadFrames]'].disabled = false; + form.elements['newZone[ExtendAlarmFrames]'].disabled = false; + applyCheckMethod(); + } else { + form.presetSelector.disabled = false; + form.newAlarmRgbR.disabled = false; + form.newAlarmRgbG.disabled = false; + form.newAlarmRgbB.disabled = false; + form.elements['newZone[CheckMethod]'].disabled = false; + form.elements['newZone[MinPixelThreshold]'].disabled = false; + form.elements['newZone[MaxPixelThreshold]'].disabled = false; + form.elements['newZone[MinAlarmPixels]'].disabled = false; + form.elements['newZone[MaxAlarmPixels]'].disabled = false; + form.elements['newZone[OverloadFrames]'].disabled = false; + form.elements['newZone[ExtendAlarmFrames]'].disabled = true; + applyCheckMethod(); + } +} - applyZoneType(); +function applyCheckMethod() { + var form = document.zoneForm; + if ( form.elements['newZone[CheckMethod]'].value == 'AlarmedPixels' ) { + form.elements['newZone[FilterX]'].disabled = true; + form.elements['newZone[FilterY]'].disabled = true; + form.elements['newZone[MinFilterPixels]'].disabled = true; + form.elements['newZone[MaxFilterPixels]'].disabled = true; + form.elements['newZone[MinBlobPixels]'].disabled = true; + form.elements['newZone[MaxBlobPixels]'].disabled = true; + form.elements['newZone[MinBlobs]'].disabled = true; + form.elements['newZone[MaxBlobs]'].disabled = true; + } else if ( form.elements['newZone[CheckMethod]'].value == 'FilteredPixels' ) { + form.elements['newZone[FilterX]'].disabled = false; + form.elements['newZone[FilterY]'].disabled = false; + form.elements['newZone[MinFilterPixels]'].disabled = false; + form.elements['newZone[MaxFilterPixels]'].disabled = false; + form.elements['newZone[MinBlobPixels]'].disabled = true; + form.elements['newZone[MaxBlobPixels]'].disabled = true; + form.elements['newZone[MinBlobs]'].disabled = true; + form.elements['newZone[MaxBlobs]'].disabled = true; + } else { + form.elements['newZone[FilterX]'].disabled = false; + form.elements['newZone[FilterY]'].disabled = false; + form.elements['newZone[MinFilterPixels]'].disabled = false; + form.elements['newZone[MaxFilterPixels]'].disabled = false; + form.elements['newZone[MinBlobPixels]'].disabled = false; + form.elements['newZone[MaxBlobPixels]'].disabled = false; + form.elements['newZone[MinBlobs]'].disabled = false; + form.elements['newZone[MaxBlobs]'].disabled = false; + } +} - if ( form.elements['newZone[Units]'].value == 'Percent' ) { - applyZoneUnits(); - } +function applyPreset() { + var form = document.zoneForm; + var presetId = $('presetSelector').get('value'); + + if ( presets[presetId] ) { + var preset = presets[presetId]; + + form.elements['newZone[Units]'].selectedIndex = preset['UnitsIndex']; + form.elements['newZone[CheckMethod]'].selectedIndex = preset['CheckMethodIndex']; + form.elements['newZone[MinPixelThreshold]'].value = preset['MinPixelThreshold']; + form.elements['newZone[MaxPixelThreshold]'].value = preset['MaxPixelThreshold']; + form.elements['newZone[FilterX]'].value = preset['FilterX']; + form.elements['newZone[FilterY]'].value = preset['FilterY']; + form.elements['newZone[MinAlarmPixels]'].value = preset['MinAlarmPixels']; + form.elements['newZone[MaxAlarmPixels]'].value = preset['MaxAlarmPixels']; + form.elements['newZone[MinFilterPixels]'].value = preset['MinFilterPixels']; + form.elements['newZone[MaxFilterPixels]'].value = preset['MaxFilterPixels']; + form.elements['newZone[MinBlobPixels]'].value = preset['MinBlobPixels']; + form.elements['newZone[MaxBlobPixels]'].value = preset['MaxBlobPixels']; + form.elements['newZone[MinBlobs]'].value = preset['MinBlobs']; + form.elements['newZone[MaxBlobs]'].value = preset['MaxBlobs']; + form.elements['newZone[OverloadFrames]'].value = preset['OverloadFrames']; + form.elements['newZone[ExtendAlarmFrames]'].value = preset['ExtendAlarmFrames']; applyCheckMethod(); - drawZonePoints(); + form.elements['newZone[TempArea]'].value = 100; + } +} + +function toPixels( field, maxValue ) { + if ( field.value != '' ) + field.value = Math.round((field.value*maxValue)/100); +} + +function toPercent( field, maxValue ) { + if ( field.value != '' ) + field.value = Math.round((100*100*field.value)/maxValue)/100; +} + +function applyZoneUnits() { + var area = zone.Area; + + var form = document.zoneForm; + if ( form.elements['newZone[Units]'].value == 'Pixels' ) { + form.elements['newZone[TempArea]'].value = area; + toPixels( form.elements['newZone[MinAlarmPixels]'], area ); + toPixels( form.elements['newZone[MaxAlarmPixels]'], area ); + toPixels( form.elements['newZone[MinFilterPixels]'], area ); + toPixels( form.elements['newZone[MaxFilterPixels]'], area ); + toPixels( form.elements['newZone[MinBlobPixels]'], area ); + toPixels( form.elements['newZone[MaxBlobPixels]'], area ); + } else { + form.elements['newZone[TempArea]'].value = Math.round( area/monitorArea * 100 ); + toPercent( form.elements['newZone[MinAlarmPixels]'], area ); + toPercent( form.elements['newZone[MaxAlarmPixels]'], area ); + toPercent( form.elements['newZone[MinFilterPixels]'], area ); + toPercent( form.elements['newZone[MaxFilterPixels]'], area ); + toPercent( form.elements['newZone[MinBlobPixels]'], area ); + toPercent( form.elements['newZone[MaxBlobPixels]'], area ); + } +} + +function limitRange( field, minValue, maxValue ) { + if ( field.value != '' ) + field.value = constrainValue( parseInt(field.value), parseInt(minValue), parseInt(maxValue) ); +} + +function limitFilter( field ) { + field.value = (Math.floor((field.value-1)/2)*2) + 1; + field.value = constrainValue(parseInt(field.value), 3, 15); +} + +function limitArea( field ) { + var minValue = 0; + var maxValue = zone.Area; + if ( document.zoneForm.elements['newZone[Units]'].value == "Percent" ) { + maxValue = 100; + } + limitRange( field, minValue, maxValue ); +} + +function highlightOn( index ) { + $('row'+index).addClass( 'highlight' ); + $('point'+index).addClass( 'highlight' ); +} + +function highlightOff( index ) { + $('row'+index).removeClass( 'highlight' ); + $('point'+index).removeClass( 'highlight' ); +} + +function setActivePoint( index ) { + highlightOff( index ); + $('row'+index).addClass( 'active' ); + $('point'+index).addClass( 'active' ); +} + +function unsetActivePoint( index ) { + $('row'+index).removeClass( 'active' ); + $('point'+index).removeClass( 'active' ); +} + +function getCoordString() { + var coords = new Array(); + for ( var i = 0; i < zone['Points'].length; i++ ) + coords[coords.length] = zone['Points'][i].x+','+zone['Points'][i].y; + return( coords.join( " " ) ); +} + +function updateZoneImage() { + var SVG = $('zoneSVG'); + var Poly = $('zonePoly'); + Poly.points.clear(); + for ( var i = 0; i < zone['Points'].length; i++ ) { + var Point = SVG.createSVGPoint(); + Point.x = zone['Points'][i].x; + Point.y = zone['Points'][i].y; + Poly.points.appendItem( Point ); + } +} + +function fixActivePoint( index ) { + updateActivePoint( index ); + unsetActivePoint( index ); + updateZoneImage(); +} + +function constrainValue( value, loVal, hiVal ) { + if ( value < loVal ) { + return loVal; + } + if ( value > hiVal ) { + return hiVal; + } + return value; +} + +function updateActivePoint( index ) { + var point = $('point'+index); + var x = constrainValue( point.getStyle( 'left' ).toInt(), 0, maxX ); + var y = constrainValue( point.getStyle( 'top' ).toInt(), 0, maxY ); + + $('newZone[Points]['+index+'][x]').value = x; + $('newZone[Points]['+index+'][y]').value = y; + zone['Points'][index].x = x; + zone['Points'][index].y = y; + var Point = $('zonePoly').points.getItem(index); + Point.x =x; + Point.y =y; + updateArea(); +} + +function addPoint( index ) { + var nextIndex = index+1; + if ( index >= (zone['Points'].length-1) ) + nextIndex = 0; + var newX = parseInt(Math.round((zone['Points'][index]['x']+zone['Points'][nextIndex]['x'])/2)); + var newY = parseInt(Math.round((zone['Points'][index]['y']+zone['Points'][nextIndex]['y'])/2)); + if ( nextIndex == 0 ) + zone['Points'][zone['Points'].length] = { 'x': newX, 'y': newY }; + else + zone['Points'].splice( nextIndex, 0, { 'x': newX, 'y': newY } ); + drawZonePoints(); + // drawZonePoints calls updateZoneImage + //updateZoneImage(); + //setActivePoint( nextIndex ); +} + +function delPoint( index ) { + zone['Points'].splice( index, 1 ); + drawZonePoints(); +} + +function limitPointValue( point, loVal, hiVal ) { + point.value = constrainValue(point.value, loVal, hiVal); +} + +function updateArea( ) { + area = Polygon_calcArea( zone['Points'] ); + zone.Area = area; + var form = $('zoneForm'); + form.elements['newZone[Area]'].value = area; + if ( form.elements['newZone[Units]'].value == 'Percent' ) { + form.elements['newZone[TempArea]'].value = Math.round( area/monitorArea*100 ); + } else if ( form.elements['newZone[Units]'].value == 'Pixels' ) { + form.elements['newZone[TempArea]'].value = area; + } else { + alert("Unknown units: " + form.elements['newZone[Units]'].value ); + } +} + +function updateX( index ) { + limitPointValue( $('newZone[Points]['+index+'][x]'), 0, maxX ); + + var point = $('point'+index); + var x = $('newZone[Points]['+index+'][x]').get('value'); + + point.setStyle( 'left', x+'px' ); + zone['Points'][index].x = x; + var Point = $('zonePoly').points.getItem(index); + Point.x = x; +} + +function updateY( index ) { + limitPointValue( $('newZone[Points]['+index+'][y]'), 0, maxY ); + + var point = $('point'+index); + var y = $('newZone[Points]['+index+'][y]').get('value'); + + point.setStyle( 'top', y+'px' ); + zone['Points'][index].y = y; + var Point = $('zonePoly').points.getItem(index); + Point.y = y; +} + +function saveChanges( element ) { + var form = element.form; + if ( validateForm( form ) ) { + submitForm( form ); + if ( form.elements['newZone[Type]'].value == 'Privacy' ) { + alert( 'Capture process for this monitor will be restarted for the Privacy zone changes to take effect.' ); + } + return( true ); + } + return( false ); +} + +function drawZonePoints() { + $('imageFrame').getElements( 'div.zonePoint' ).each( function( element ) { element.destroy(); } ); + for ( var i = 0; i < zone['Points'].length; i++ ) { + var div = new Element( 'div', { 'id': 'point'+i, 'class': 'zonePoint', 'title': 'Point '+(i+1), 'styles': { 'left': zone['Points'][i].x, 'top': zone['Points'][i].y } } ); + div.addEvent( 'mouseover', highlightOn.pass( i ) ); + div.addEvent( 'mouseout', highlightOff.pass( i ) ); + div.inject( $('imageFrame') ); + div.makeDraggable( { + 'container': $('imageFrame'), + 'onStart': setActivePoint.pass( i ), + 'onComplete': fixActivePoint.pass( i ), + 'onDrag': updateActivePoint.pass( i ) + } ); + } + + var tables = $('zonePoints').getElements( 'table' ); + tables.each( function( table ) { table.getElement( 'tbody' ).empty(); } ); + for ( var i = 0; i < zone['Points'].length; i++ ) { + var row = new Element( 'tr', { 'id': 'row'+i } ); + row.addEvents( { 'mouseover': highlightOn.pass( i ), 'mouseout': highlightOff.pass( i ) } ); + var cell = new Element( 'td' ); + cell.set( 'text', i+1 ); + cell.inject( row ); + + cell = new Element( 'td' ); + var input = new Element( 'input', { 'id': 'newZone[Points]['+i+'][x]', 'name': 'newZone[Points]['+i+'][x]', 'value': zone['Points'][i].x, 'size': 5 } ); + input.addEvent( 'input', updateX.pass( i ) ); + input.inject( cell ); + cell.inject( row ); + + cell = new Element( 'td' ); + input = new Element( 'input', { 'id': 'newZone[Points]['+i+'][y]', 'name': 'newZone[Points]['+i+'][y]', 'value': zone['Points'][i].y, 'size': 5 } ); + input.addEvent( 'input', updateY.pass( i ) ); + input.inject( cell ); + cell.inject( row ); + + cell = new Element( 'td' ); + new Element( 'a', { 'href': '#', 'events': { 'click': addPoint.pass( i ) } } ).set( 'text', '+' ).inject( cell ); + if ( zone['Points'].length > 3 ) + new Element( 'a', { 'id': 'delete'+i, 'href': '#', 'events': { 'click': delPoint.pass( i ) } } ).set( 'text', '-' ).inject( cell ); + cell.inject( row ); + + row.inject( tables[i%tables.length].getElement( 'tbody' ) ); + } + // Sets up the SVG polygon + updateZoneImage(); +} // // Imported from watch.js and modified for new zone edit view // +var alarmState = STATE_IDLE; +var lastAlarmState = STATE_IDLE; + +function setAlarmState( currentAlarmState ) { + alarmState = currentAlarmState; + + var stateString = "Unknown"; + var stateClass = ""; + if ( alarmState == STATE_ALARM ) + stateClass = "alarm"; + else if ( alarmState == STATE_ALERT ) + stateClass = "alert"; + $('stateValue').set( 'text', stateStrings[alarmState] ); + if ( stateClass ) + $('stateValue').setProperty( 'class', stateClass ); + else + $('stateValue').removeProperty( 'class' ); + + 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 + if ( !canPlayPauseAudio ) + $('alarmSound').removeClass( 'hidden' ); + else + $('MediaPlayer').Play(); + } + } + if ( SOUND_ON_ALARM ) { + if ( oldAlarm ) { + // Disable alarm sound + if ( !canPlayPauseAudio ) + $('alarmSound').addClass( 'hidden' ); + else + $('MediaPlayer').Stop(); + } + } + lastAlarmState = alarmState; +} + +var streamCmdParms = "view=request&request=stream&connkey="+connKey; +var streamCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getStreamCmdResponse } ); +var streamCmdTimer = null; + +var streamStatus; + +function getStreamCmdResponse( respObj, respText ) { + watchdogOk("stream"); + if ( streamCmdTimer ) + streamCmdTimer = clearTimeout( streamCmdTimer ); + + if ( respObj.result == 'Ok' ) { + streamStatus = respObj.status; + $('fpsValue').set( 'text', streamStatus.fps ); + + setAlarmState( streamStatus.state ); + + var delayString = secsToTime( streamStatus.delay ); + + if ( streamStatus.paused == true ) { + streamCmdPause( false ); + } else if ( streamStatus.delayed == true && streamStatus.rate == 1 ) { + streamCmdPlay( false ); + } + } else { + checkStreamForErrors("getStreamCmdResponse", respObj);//log them + // Try to reload the image stream. + var streamImg = document.getElementById('liveStream'); + if ( streamImg ) + streamImg.src = streamImg.src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) )); + } + + var streamCmdTimeout = statusRefreshTimeout; + if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) + streamCmdTimeout = streamCmdTimeout/5; + streamCmdTimer = streamCmdQuery.delay( streamCmdTimeout ); +} + +var streamPause = false; + +function streamCmdPauseToggle() { + if ( streamPause == true ) { + streamCmdPlay( true ); + streamPause = false; + document.getElementById("pauseBtn").value = pauseString; + } else { + streamCmdPause( true ); + streamPause = true; + document.getElementById("pauseBtn").value = playString; + } +} + +function streamCmdPause( action ) { + if ( action ) + streamCmdReq.send( streamCmdParms+"&command="+CMD_PAUSE ); +} + +function streamCmdPlay( action ) { + if ( action ) + streamCmdReq.send( streamCmdParms+"&command="+CMD_PLAY ); +} + +function streamCmdStop( action ) { + if ( action ) + streamCmdReq.send( streamCmdParms+"&command="+CMD_STOP ); +} + +function streamCmdQuery() { + streamCmdReq.send( streamCmdParms+"&command="+CMD_QUERY ); +} + +var statusCmdParms = "view=request&request=status&entity=monitor&id="+monitorId+"&element[]=Status&element[]=FrameRate"; +var statusCmdReq = new Request.JSON( { url: monitorUrl+thisUrl, method: 'post', data: statusCmdParms, timeout: AJAX_TIMEOUT, link: 'cancel', onSuccess: getStatusCmdResponse } ); +var statusCmdTimer = null; + +function getStatusCmdResponse( respObj, respText ) { + watchdogOk("status"); + if ( statusCmdTimer ) + statusCmdTimer = clearTimeout( statusCmdTimer ); + + if ( respObj.result == 'Ok' ) { + $('fpsValue').set( 'text', respObj.monitor.FrameRate ); + setAlarmState( respObj.monitor.Status ); + } else + checkStreamForErrors("getStatusCmdResponse", respObj); + + var statusCmdTimeout = statusRefreshTimeout; + if ( alarmState == STATE_ALARM || alarmState == STATE_ALERT ) + statusCmdTimeout = statusCmdTimeout/5; + statusCmdTimer = statusCmdQuery.delay( statusCmdTimeout ); +} + +function statusCmdQuery() { + statusCmdReq.send(); +} + +function fetchImage( streamImage ) { + streamImage.src = streamImage.src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) )); +} + +function appletRefresh() { + if ( streamStatus && (!streamStatus.paused && !streamStatus.delayed) ) { + var streamImg = $('liveStream'); + var parent = streamImg.getParent(); + streamImg.dispose(); + streamImg.inject( parent ); + if ( appletRefreshTime ) + appletRefresh.delay( appletRefreshTime*1000 ); + } else { + appletRefresh.delay( 15*1000 ); //if we are paused or delayed check every 15 seconds if we are live yet... + } +} + +var watchdogInactive = { + 'stream': false, + 'status': false +}; + +var watchdogFunctions = { + 'stream': streamCmdQuery, + 'status': statusCmdQuery +}; + +//Make sure the various refreshes are still taking effect +function watchdogCheck( type ) { + if ( watchdogInactive[type] ) { + console.log( "Detected streamWatch of type: " + type + " stopped, restarting" ); + watchdogFunctions[type](); + watchdogInactive[type] = false; + } else { + watchdogInactive[type] = true; + } +} + +function watchdogOk( type ) { + watchdogInactive[type] = false; +} + +function initPage() { + var form = document.zoneForm; + + //form.elements['newZone[Name]'].disabled = true; + //form.elements['newZone[Type]'].disabled = true; + form.presetSelector.disabled = true; + //form.elements['newZone[Units]'].disabled = true; + form.newAlarmRgbR.disabled = true; + form.newAlarmRgbG.disabled = true; + form.newAlarmRgbB.disabled = true; + form.elements['newZone[CheckMethod]'].disabled = true; + form.elements['newZone[MinPixelThreshold]'].disabled = true; + form.elements['newZone[MaxPixelThreshold]'].disabled = true; + form.elements['newZone[MinAlarmPixels]'].disabled = true; + form.elements['newZone[MaxAlarmPixels]'].disabled = true; + form.elements['newZone[FilterX]'].disabled = true; + form.elements['newZone[FilterY]'].disabled = true; + form.elements['newZone[MinFilterPixels]'].disabled = true; + form.elements['newZone[MaxFilterPixels]'].disabled = true; + form.elements['newZone[MinBlobPixels]'].disabled = true; + form.elements['newZone[MaxBlobPixels]'].disabled = true; + form.elements['newZone[MinBlobs]'].disabled = true; + form.elements['newZone[MaxBlobs]'].disabled = true; + form.elements['newZone[OverloadFrames]'].disabled = true; + + applyZoneType(); + + if ( form.elements['newZone[Units]'].value == 'Percent' ) { + applyZoneUnits(); + } + + applyCheckMethod(); + drawZonePoints(); + + // + // Imported from watch.js and modified for new zone edit view + // + + if ( streamMode == "single" ) { + statusCmdTimer = statusCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout ); + watchdogCheck.pass('status').periodical(statusRefreshTimeout*2); + } else { + streamCmdTimer = streamCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout ); + watchdogCheck.pass('stream').periodical(statusRefreshTimeout*2); + } + + if ( canStreamNative || streamMode == "single" ) { + var streamImg = $('imageFrame').getElement('img'); + if ( !streamImg ) + streamImg = $('imageFrame').getElement('object'); if ( streamMode == "single" ) { - statusCmdTimer = statusCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout ); - watchdogCheck.pass('status').periodical(statusRefreshTimeout*2); - } else { - streamCmdTimer = streamCmdQuery.delay( (Math.random()+0.1)*statusRefreshTimeout ); - watchdogCheck.pass('stream').periodical(statusRefreshTimeout*2); + streamImg.addEvent( 'click', fetchImage.pass( streamImg ) ); + fetchImage.pass( streamImg ).periodical( imageRefreshTimeout ); } + } - if ( canStreamNative || streamMode == "single" ) { - var streamImg = $('imageFrame').getElement('img'); - if ( !streamImg ) - streamImg = $('imageFrame').getElement('object'); - if ( streamMode == "single" ) { - streamImg.addEvent( 'click', fetchImage.pass( streamImg ) ); - fetchImage.pass( streamImg ).periodical( imageRefreshTimeout ); - } - } - - if ( refreshApplet && appletRefreshTime ) - appletRefresh.delay( appletRefreshTime*1000 ); + if ( refreshApplet && appletRefreshTime ) + appletRefresh.delay( appletRefreshTime*1000 ); } function Polygon_calcArea( coords ) { diff --git a/web/skins/classic/views/js/zone.js.php b/web/skins/classic/views/js/zone.js.php index e7f368085..49946f767 100644 --- a/web/skins/classic/views/js/zone.js.php +++ b/web/skins/classic/views/js/zone.js.php @@ -1,7 +1,6 @@ var presets = new Object(); presets[] = { 'UnitsIndex': , @@ -38,8 +37,7 @@ var zone = { zone['Points'] = new Array(); zone['Points'][] = { 'x': , 'y': }; 700, "height"=>460, "image" => array( - "width"=>264, - "height"=>220, - "topOffset"=>20, - ), + "width"=>264, + "height"=>220, + "topOffset"=>20, + ), "imageText" => array( - "width"=>400, - "height"=>30, - "topOffset"=>20, - ), + "width"=>400, + "height"=>30, + "topOffset"=>20, + ), "graph" => array( - "width"=>600, - "height"=>160, - "topOffset"=>30, - ), + "width"=>600, + "height"=>160, + "topOffset"=>30, + ), "title" => array( - "topOffset"=>50 - ), + "topOffset"=>50 + ), "key" => array( "topOffset"=>50 - ), + ), "axes" => array( "x" => array( - "height" => 20, - ), + "height" => 20, + ), "y" => array( - "width" => 30, + "width" => 30, + ), ), - ), "grid" => array( "x" => array( - "major" => array( - "max" => 12, - "min" => 4, + "major" => array( + "max" => 12, + "min" => 4, ), - "minor" => array( - "max" => 48, - "min" => 12, + "minor" => array( + "max" => 48, + "min" => 12, ), - ), + ), "y" => array( - "major" => array( - "max" => 8, - "min" => 1, + "major" => array( + "max" => 8, + "min" => 1, ), - "minor" => array( - "max" => 0, - "min" => 0, + "minor" => array( + "max" => 0, + "min" => 0, ), + ), ), - ), ); $monitors = array(); -$monitorsSql = "select * from Monitors order by Sequence asc"; +$monitorsSql = 'SELECT * FROM Monitors ORDER BY Sequence ASC'; //srand( 97981 ); foreach( dbFetchAll( $monitorsSql ) as $row ) { //if ( empty($row['WebColour']) ) //{ - //$row['WebColour'] = sprintf( "#%02x%02x%02x", rand( 0, 255 ), rand( 0, 255), rand( 0, 255 ) ); + //$row['WebColour'] = sprintf( "#%02x%02x%02x", rand( 0, 255 ), rand( 0, 255), rand( 0, 255 ) ); //} $monitors[$row['Id']] = $row; } -$rangeSql = 'SELECT min(StartTime) AS MinTime, max(EndTime) AS MaxTime FROM Events WHERE NOT isnull(StartTime) AND NOT isnull(EndTime)'; -$eventsSql = 'SELECT * FROM Events WHERE NOT isnull(StartTime)'; +# The as E, and joining with Monitors is required for the filterSQL filters. +$rangeSql = 'SELECT min(E.StartTime) AS MinTime, max(E.EndTime) AS MaxTime FROM Events AS E INNER JOIN Monitors AS M ON (E.MonitorId = M.Id) WHERE NOT isnull(E.StartTime) AND NOT isnull(E.EndTime)'; +$eventsSql = 'SELECT * FROM Events AS E WHERE NOT isnull(StartTime)'; if ( !empty($user['MonitorIds']) ) { - $monFilterSql = ' AND MonitorId IN ('.$user['MonitorIds'].')'; + $monFilterSql = ' AND MonitorId IN ('.$user['MonitorIds'].')'; $rangeSql .= $monFilterSql; $eventsSql .= $monFilterSql; @@ -351,12 +352,12 @@ foreach( dbFetchAll( $eventsSql ) as $event ) { } if ( $event['MaxScore'] > 0 ) { if ( $startIndex == $endIndex ) { - $framesSql = "select FrameId,Score from Frames where EventId = ? and Score > 0 order by Score desc limit 1"; + $framesSql = 'SELECT FrameId,Score FROM Frames WHERE EventId = ? AND Score > 0 ORDER BY Score DESC LIMIT 1'; $frame = dbFetchOne( $framesSql, NULL, array($event['Id']) ); $i = $startIndex; if ( !isset($currFrameSlots[$i]) ) { - $currFrameSlots[$i] = array( "count"=>1, "value"=>$event['MaxScore'], "event"=>$event, "frame"=>$frame ); + $currFrameSlots[$i] = array( 'count'=>1, 'value'=>$event['MaxScore'], 'event'=>$event, 'frame'=>$frame ); } else { $currFrameSlots[$i]['count']++; if ( $event['MaxScore'] > $currFrameSlots[$i]['value'] ) { @@ -369,7 +370,7 @@ foreach( dbFetchAll( $eventsSql ) as $event ) { $chart['data']['y']['hi'] = $event['MaxScore']; } } else { - $framesSql = "select FrameId,Delta,unix_timestamp(TimeStamp) as TimeT,Score from Frames where EventId = ? and Score > 0"; + $framesSql = 'SELECT FrameId,Delta,unix_timestamp(TimeStamp) AS TimeT,Score FROM Frames WHERE EventId = ? AND Score > 0'; $result = dbQuery( $framesSql, array( $event['Id'] ) ); while( $frame = dbFetchNext( $result ) ) { if ( $frame['Score'] == 0 ) @@ -383,7 +384,7 @@ foreach( dbFetchAll( $eventsSql ) as $event ) { continue; if ( !isset($currFrameSlots[$frameIndex]) ) { - $currFrameSlots[$frameIndex] = array( "count"=>1, "value"=>$frame['Score'], "event"=>$event, "frame"=>$frame ); + $currFrameSlots[$frameIndex] = array( 'count'=>1, 'value'=>$frame['Score'], 'event'=>$event, 'frame'=>$frame ); } else { $currFrameSlots[$frameIndex]['count']++; if ( $frame['Score'] > $currFrameSlots[$frameIndex]['value'] ) { @@ -496,7 +497,7 @@ for ( $i = 0; $i < $chart['graph']['width']; $i++ ) { $frameSlots[$i][] = &$currFrameSlots[$i]; } } - } + } # end foreach MonitorId } //print_r( $monEventSlots ); @@ -505,7 +506,7 @@ for ( $i = 0; $i < $chart['graph']['width']; $i++ ) { $graphHeight = $chart['graph']['height']; -if ( $mode == "overlay" ) { +if ( $mode == 'overlay' ) { $minEventBarHeight = 10; $maxEventBarHeight = 40; @@ -527,7 +528,7 @@ if ( $mode == "overlay" ) { $chart['eventBars'][$monitorId] = array( 'top' => $top ); $top += $chart['graph']['eventBarHeight']+1; } -} elseif ( $mode == "split" ) { +} else if ( $mode == 'split' ) { $minActivityBarHeight = 30; $minEventBarHeight = 10; $maxEventBarHeight = 40; @@ -547,14 +548,11 @@ if ( $mode == "overlay" ) { } $chart['data']['y']['density'] = $chart['data']['y']['range']/$chart['graph']['activityBarHeight']; - ?> - $top ); $chart['eventBars'][$monitorId] = array( 'top' => $top+$chart['graph']['activityBarHeight']+1 ); $top += $chart['graph']['activityBarHeight']+1+$chart['graph']['eventBarHeight']+1; @@ -565,123 +563,124 @@ preg_match( '/^(\d+)-(\d+)-(\d+) (\d+):(\d+)/', $minTime, $startMatches ); preg_match( '/^(\d+)-(\d+)-(\d+) (\d+):(\d+)/', $maxTime, $endMatches ); if ( $startMatches[1] != $endMatches[1] ) { - // Different years - $title = strftime( STRF_TL_AXIS_RANGE_YEAR1, $chart['data']['x']['lo'] )." - ".strftime( STRF_TL_AXIS_RANGE_YEAR2, $chart['data']['x']['hi'] ); + // Different years + $title = strftime( STRF_TL_AXIS_RANGE_YEAR1, $chart['data']['x']['lo'] )." - ".strftime( STRF_TL_AXIS_RANGE_YEAR2, $chart['data']['x']['hi'] ); } elseif ( $startMatches[2] != $endMatches[2] ) { - // Different months - $title = strftime( STRF_TL_AXIS_RANGE_MONTH1, $chart['data']['x']['lo'] )." - ".strftime( STRF_TL_AXIS_RANGE_MONTH2, $chart['data']['x']['hi'] ); + // Different months + $title = strftime( STRF_TL_AXIS_RANGE_MONTH1, $chart['data']['x']['lo'] )." - ".strftime( STRF_TL_AXIS_RANGE_MONTH2, $chart['data']['x']['hi'] ); } elseif ( $startMatches[3] != $endMatches[3] ) { - // Different dates - $title = strftime( STRF_TL_AXIS_RANGE_DAY1, $chart['data']['x']['lo'] )." - ".strftime( STRF_TL_AXIS_RANGE_DAY2, $chart['data']['x']['hi'] ); + // Different dates + $title = strftime( STRF_TL_AXIS_RANGE_DAY1, $chart['data']['x']['lo'] )." - ".strftime( STRF_TL_AXIS_RANGE_DAY2, $chart['data']['x']['hi'] ); } else { - // Different times - $title = strftime( STRF_TL_AXIS_RANGE_TIME1, $chart['data']['x']['lo'] )." - ".strftime( STRF_TL_AXIS_RANGE_TIME2, $chart['data']['x']['hi'] ); + // Different times + $title = strftime( STRF_TL_AXIS_RANGE_TIME1, $chart['data']['x']['lo'] )." - ".strftime( STRF_TL_AXIS_RANGE_TIME2, $chart['data']['x']['hi'] ); } function drawXGrid( $chart, $scale, $labelClass, $tickClass, $gridClass, $zoomClass=false ) { - ob_start(); - $labelCount = 0; - $lastTick = 0; - unset( $lastLabel ); - $labelCheck = isset($scale['labelCheck'])?$scale['labelCheck']:$scale['label']; + $html = ''; + ob_start(); + $labelCount = 0; + $lastTick = 0; + unset( $lastLabel ); + $labelCheck = isset($scale['labelCheck'])?$scale['labelCheck']:$scale['label']; ?>