2015-10-02 13:41:31 +08:00
var events = { } ;
2014-05-29 23:47:52 +08:00
function showEvent ( eid , fid , width , height )
2014-05-12 06:08:23 +08:00
{
2014-05-29 23:47:52 +08:00
var url = '?view=event&eid=' + eid + '&fid=' + fid ;
url += filterQuery ;
2014-05-12 06:08:23 +08:00
var pop = createPopup ( url , 'zmEvent' , 'event' , width , height ) ;
pop . vid = $ ( 'preview' ) ;
//video element is blocking video elements elsewhere in chrome possible interaction with mouseover event?
//FIXME unless an exact cause can be determined should store all video controls and do something to the other controls when we want to load a new video seek etc or whatever may block
/ * v a r v i d = $ ( ' p r e v i e w ' ) ;
vid . oncanplay = null ;
// vid.currentTime=vid.currentTime-0.1;
vid . pause ( ) ; * /
2014-05-29 23:47:52 +08:00
}
function createEventHtml ( event , frame )
{
var eventHtml = new Element ( 'div' ) ;
if ( event . Archived > 0 )
eventHtml . addClass ( 'archived' ) ;
2015-10-03 11:04:10 +08:00
new Element ( 'p' ) . inject ( eventHtml ) . set ( 'text' , monitors [ event . MonitorId ] . Name ) ;
2014-05-29 23:47:52 +08:00
new Element ( 'p' ) . inject ( eventHtml ) . set ( 'text' , event . Name + ( frame ? ( "(" + frame . FrameId + ")" ) : "" ) ) ;
new Element ( 'p' ) . inject ( eventHtml ) . set ( 'text' , event . StartTime + " - " + event . Length + "s" ) ;
new Element ( 'p' ) . inject ( eventHtml ) . set ( 'text' , event . Cause ) ;
if ( event . Notes )
new Element ( 'p' ) . inject ( eventHtml ) . set ( 'text' , event . Notes ) ;
if ( event . Archived > 0 )
new Element ( 'p' ) . inject ( eventHtml ) . set ( 'text' , archivedString ) ;
return ( eventHtml ) ;
}
function showEventDetail ( eventHtml )
{
$ ( 'instruction' ) . addClass ( 'hidden' ) ;
$ ( 'eventData' ) . empty ( ) ;
$ ( 'eventData' ) . adopt ( eventHtml ) ;
$ ( 'eventData' ) . removeClass ( 'hidden' ) ;
}
function eventDataResponse ( respObj , respText )
{
var event = respObj . event ;
if ( ! event )
{
console . log ( "Null event" ) ;
return ;
}
events [ event . Id ] = event ;
if ( respObj . loopback )
{
requestFrameData ( event . Id , respObj . loopback ) ;
}
}
function frameDataResponse ( respObj , respText )
{
var frame = respObj . frameimage ;
if ( ! frame . FrameId )
{
console . log ( "Null frame" ) ;
return ;
}
var event = events [ frame . EventId ] ;
if ( ! event )
{
console . error ( "No event " + frame . eventId + " found" ) ;
return ;
}
if ( ! event [ 'frames' ] )
event [ 'frames' ] = new Object ( ) ;
event [ 'frames' ] [ frame . FrameId ] = frame ;
event [ 'frames' ] [ frame . FrameId ] [ 'html' ] = createEventHtml ( event , frame ) ;
2015-10-02 13:41:31 +08:00
previewEvent ( frame . EventId , frame . FrameId ) ;
2014-05-29 23:47:52 +08:00
}
2014-07-30 04:15:31 +08:00
var eventQuery = new Request . JSON ( { url : thisUrl , method : 'get' , timeout : AJAX _TIMEOUT , link : 'cancel' , onSuccess : eventDataResponse } ) ;
var frameQuery = new Request . JSON ( { url : thisUrl , method : 'get' , timeout : AJAX _TIMEOUT , link : 'cancel' , onSuccess : frameDataResponse } ) ;
2014-05-29 23:47:52 +08:00
function requestFrameData ( eventId , frameId )
{
if ( ! events [ eventId ] )
{
eventQuery . options . data = "view=request&request=status&entity=event&id=" + eventId + "&loopback=" + frameId ;
eventQuery . send ( ) ;
}
else
{
frameQuery . options . data = "view=request&request=status&entity=frameimage&id[0]=" + eventId + "&id[1]=" + frameId ;
frameQuery . send ( ) ;
}
}
function previewEvent ( eventId , frameId )
{
2015-10-02 13:41:31 +08:00
2014-05-29 23:47:52 +08:00
if ( events [ eventId ] )
{
2015-11-19 13:21:56 +08:00
var event = events [ eventId ] ;
if ( event [ 'frames' ] )
2014-05-29 23:47:52 +08:00
{
2015-11-19 13:21:56 +08:00
if ( event [ 'frames' ] [ frameId ] )
2014-05-29 23:47:52 +08:00
{
2015-11-19 13:21:56 +08:00
showEventDetail ( event [ 'frames' ] [ frameId ] [ 'html' ] ) ;
var imagePath = event . frames [ frameId ] . Image . imagePath ;
var videoName = event . DefaultVideo ;
loadEventImage ( imagePath , eventId , frameId , event . Width , event . Height , event . Frames / event . Length , videoName , event . Length , event . StartTime , monitors [ event . MonitorId ] ) ;
2014-05-29 23:47:52 +08:00
return ;
}
}
}
requestFrameData ( eventId , frameId ) ;
}
2015-11-19 13:21:56 +08:00
function loadEventImage ( imagePath , eid , fid , width , height , fps , videoName , duration , startTime , Monitor )
2014-05-29 23:47:52 +08:00
{
2014-05-12 06:08:23 +08:00
var vid = $ ( 'preview' ) ;
2015-10-02 13:41:31 +08:00
var imageSrc = $ ( 'imageSrc' ) ;
2015-10-25 13:20:08 +08:00
if ( videoName )
2014-05-12 06:08:23 +08:00
{
2015-10-02 13:41:31 +08:00
vid . show ( ) ;
imageSrc . hide ( ) ;
2015-10-25 13:20:08 +08:00
var newsource = imagePrefix + imagePath . slice ( 0 , imagePath . lastIndexOf ( '/' ) ) + "/" + videoName ;
2015-10-02 13:41:31 +08:00
//console.log(newsource);
//console.log(sources[0].src.slice(-newsource.length));
if ( newsource != vid . currentSrc . slice ( - newsource . length ) || vid . readyState == 0 )
{
//console.log("loading new");
//it is possible to set a long source list here will that be unworkable?
var sources = vid . getElementsByTagName ( 'source' ) ;
sources [ 0 ] . src = newsource ;
2015-11-19 13:21:56 +08:00
var tracks = vid . getElementsByTagName ( 'track' ) ;
if ( tracks . length ) {
tracks [ 0 ] . parentNode . removeChild ( tracks [ 0 ] ) ;
}
2015-10-02 13:41:31 +08:00
vid . load ( ) ;
2015-11-19 13:21:56 +08:00
addVideoTimingTrack ( vid , Monitor . LabelFormat , Monitor . Name , duration , startTime )
vid . currentTime = fid / fps ;
2015-10-02 13:41:31 +08:00
}
else
{
if ( ! vid . seeking )
2015-11-19 13:21:56 +08:00
vid . currentTime = fid / fps ;
2015-10-02 13:41:31 +08:00
}
2014-05-12 06:08:23 +08:00
}
else
{
2015-10-02 13:41:31 +08:00
vid . hide ( ) ;
imageSrc . show ( ) ;
imageSrc . setProperty ( 'src' , imagePrefix + imagePath ) ;
imageSrc . removeEvent ( 'click' ) ;
imageSrc . addEvent ( 'click' , showEvent . pass ( [ eid , fid , width , height ] ) ) ;
2014-05-12 06:08:23 +08:00
}
2015-10-02 13:41:31 +08:00
2014-05-29 23:47:52 +08:00
var eventData = $ ( 'eventData' ) ;
eventData . removeEvent ( 'click' ) ;
2015-10-02 13:41:31 +08:00
eventData . addEvent ( 'click' , showEvent . pass ( [ eid , fid , width , height ] ) ) ;
2014-05-29 23:47:52 +08:00
}
function tlZoomBounds ( minTime , maxTime )
{
console . log ( "Zooming" ) ;
window . location = '?view=' + currentView + filterQuery + '&minTime=' + minTime + '&maxTime=' + maxTime ;
}
function tlZoomRange ( midTime , range )
{
window . location = '?view=' + currentView + filterQuery + '&midTime=' + midTime + '&range=' + range ;
}
function tlPan ( midTime , range )
{
window . location = '?view=' + currentView + filterQuery + '&midTime=' + midTime + '&range=' + range ;
}