whitespace, get rid of redundant ajax startup
This commit is contained in:
parent
c2af380e29
commit
b0078fb1d9
|
@ -1,4 +1,7 @@
|
||||||
var requestQueue = new Request.Queue( { concurrent: monitorData.length, stopOnFailure: false } );
|
var requestQueue = new Request.Queue({
|
||||||
|
concurrent: monitorData.length,
|
||||||
|
stopOnFailure: false
|
||||||
|
});
|
||||||
|
|
||||||
function Monitor(monitorData) {
|
function Monitor(monitorData) {
|
||||||
this.id = monitorData.id;
|
this.id = monitorData.id;
|
||||||
|
@ -21,7 +24,6 @@ function Monitor( monitorData ) {
|
||||||
console.log("No streamCmdQuery");
|
console.log("No streamCmdQuery");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.setStateClass = function(element, stateClass) {
|
this.setStateClass = function(element, stateClass) {
|
||||||
if ( !element.hasClass(stateClass) ) {
|
if ( !element.hasClass(stateClass) ) {
|
||||||
if ( stateClass != 'alarm' )
|
if ( stateClass != 'alarm' )
|
||||||
|
@ -37,7 +39,7 @@ function Monitor( monitorData ) {
|
||||||
this.onError = function(text, error) {
|
this.onError = function(text, error) {
|
||||||
console.log('onerror: ' + text + ' error:'+error);
|
console.log('onerror: ' + text + ' error:'+error);
|
||||||
// Requeue, but want to wait a while.
|
// Requeue, but want to wait a while.
|
||||||
var streamCmdTimeout = 1000*statusRefreshTimeout;
|
var streamCmdTimeout = 10*statusRefreshTimeout;
|
||||||
this.streamCmdTimer = this.streamCmdQuery.delay(streamCmdTimeout, this);
|
this.streamCmdTimer = this.streamCmdQuery.delay(streamCmdTimeout, this);
|
||||||
};
|
};
|
||||||
this.onFailure = function(xhr) {
|
this.onFailure = function(xhr) {
|
||||||
|
@ -132,7 +134,9 @@ function Monitor( monitorData ) {
|
||||||
}
|
}
|
||||||
} // end if Ok or not
|
} // end if Ok or not
|
||||||
var streamCmdTimeout = statusRefreshTimeout;
|
var streamCmdTimeout = statusRefreshTimeout;
|
||||||
// The idea here is if we are alarmed, do updates faster. However, there is a timeout in the php side which isn't getting modified, so this may cause a problem. Also the server may only be able to update so fast.
|
// The idea here is if we are alarmed, do updates faster.
|
||||||
|
// However, there is a timeout in the php side which isn't getting modified,
|
||||||
|
// so this may cause a problem. Also the server may only be able to update so fast.
|
||||||
//if ( this.alarmState == STATE_ALARM || this.alarmState == STATE_ALERT ) {
|
//if ( this.alarmState == STATE_ALARM || this.alarmState == STATE_ALERT ) {
|
||||||
//streamCmdTimeout = streamCmdTimeout/5;
|
//streamCmdTimeout = streamCmdTimeout/5;
|
||||||
//}
|
//}
|
||||||
|
@ -142,7 +146,7 @@ function Monitor( monitorData ) {
|
||||||
|
|
||||||
this.streamCmdQuery = function(resent) {
|
this.streamCmdQuery = function(resent) {
|
||||||
if ( resent ) {
|
if ( resent ) {
|
||||||
console.log( this.connKey+": Resending" );
|
console.log(this.connKey+": timeout: Resending");
|
||||||
this.streamCmdReq.cancel();
|
this.streamCmdReq.cancel();
|
||||||
}
|
}
|
||||||
//console.log("Starting CmdQuery for " + this.connKey );
|
//console.log("Starting CmdQuery for " + this.connKey );
|
||||||
|
@ -155,18 +159,17 @@ function Monitor( monitorData ) {
|
||||||
this.streamCmdReq = new Request.JSON( {
|
this.streamCmdReq = new Request.JSON( {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
timeout: 1000+AJAX_TIMEOUT,
|
timeout: AJAX_TIMEOUT,
|
||||||
onSuccess: this.getStreamCmdResponse.bind(this),
|
onSuccess: this.getStreamCmdResponse.bind(this),
|
||||||
onTimeout: this.streamCmdQuery.bind(this, true),
|
onTimeout: this.streamCmdQuery.bind(this, true),
|
||||||
onError: this.onError.bind(this),
|
onError: this.onError.bind(this),
|
||||||
onFailure: this.onFailure.bind(this),
|
onFailure: this.onFailure.bind(this),
|
||||||
link: 'cancel'
|
link: 'cancel'
|
||||||
} );
|
} );
|
||||||
console.log("queueing for " + this.id + " " + this.connKey );
|
console.log("queueing for " + this.id + " " + this.connKey + " timeout is: " + AJAX_TIMEOUT);
|
||||||
requestQueue.addRequest("cmdReq"+this.id, this.streamCmdReq);
|
requestQueue.addRequest("cmdReq"+this.id, this.streamCmdReq);
|
||||||
}
|
}
|
||||||
|
} // end function Monitor
|
||||||
}
|
|
||||||
|
|
||||||
function selectLayout(element) {
|
function selectLayout(element) {
|
||||||
layout = $j(element).val();
|
layout = $j(element).val();
|
||||||
|
@ -175,7 +178,7 @@ function selectLayout( element ) {
|
||||||
layout = layouts[layout];
|
layout = layouts[layout];
|
||||||
console.log(layout);
|
console.log(layout);
|
||||||
|
|
||||||
for ( var i = 0; i < monitors.length; i++ ) {
|
for ( var i = 0, length = monitors.length; i < length; i++ ) {
|
||||||
monitor = monitors[i];
|
monitor = monitors[i];
|
||||||
// Need to clear the current positioning, and apply the new
|
// Need to clear the current positioning, and apply the new
|
||||||
|
|
||||||
|
@ -214,9 +217,8 @@ function selectLayout( element ) {
|
||||||
Cookie.write( 'zmMontageScale', '', { duration: 10*365 } );
|
Cookie.write( 'zmMontageScale', '', { duration: 10*365 } );
|
||||||
$('scale').set('value', '');
|
$('scale').set('value', '');
|
||||||
$('width').set('value', '');
|
$('width').set('value', '');
|
||||||
if ( 1 ) {
|
for ( var i = 0, length = monitors.length; i < length; i++ ) {
|
||||||
for ( var x = 0; x < monitors.length; x++ ) {
|
var monitor = monitors[i];
|
||||||
var monitor = monitors[x];
|
|
||||||
var streamImg = $('liveStream'+monitor.id);
|
var streamImg = $('liveStream'+monitor.id);
|
||||||
if ( streamImg ) {
|
if ( streamImg ) {
|
||||||
if ( streamImg.nodeName == 'IMG' ) {
|
if ( streamImg.nodeName == 'IMG' ) {
|
||||||
|
@ -237,15 +239,14 @@ if ( 1 ) {
|
||||||
}
|
}
|
||||||
} // end foreach monitor
|
} // end foreach monitor
|
||||||
}
|
}
|
||||||
}
|
} // end function selectLayout(element)
|
||||||
}
|
|
||||||
|
|
||||||
function changeSize() {
|
function changeSize() {
|
||||||
var width = $('width').get('value');
|
var width = $('width').get('value');
|
||||||
var height = $('height').get('value');
|
var height = $('height').get('value');
|
||||||
|
|
||||||
for ( var x = 0; x < monitors.length; x++ ) {
|
for ( var i = 0, length = monitors.length; i < length; i++ ) {
|
||||||
var monitor = monitors[x];
|
var monitor = monitors[i];
|
||||||
|
|
||||||
// Scale the frame
|
// Scale the frame
|
||||||
monitor_frame = $j('#monitorFrame'+monitor.id);
|
monitor_frame = $j('#monitorFrame'+monitor.id);
|
||||||
|
@ -253,8 +254,11 @@ function changeSize() {
|
||||||
console.log("Error finding frame for " + monitor.id);
|
console.log("Error finding frame for " + monitor.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
monitor_frame.css('width',width?width+'px':'');
|
if ( width )
|
||||||
monitor_frame.css('height',height?height+'px':'');
|
monitor_frame.css('width', width+'px');
|
||||||
|
if ( height )
|
||||||
|
monitor_frame.css('height', height+'px');
|
||||||
|
|
||||||
/*Stream could be an applet so can't use moo tools*/
|
/*Stream could be an applet so can't use moo tools*/
|
||||||
var streamImg = $('liveStream'+monitor.id);
|
var streamImg = $('liveStream'+monitor.id);
|
||||||
if ( streamImg ) {
|
if ( streamImg ) {
|
||||||
|
@ -294,10 +298,10 @@ function changeScale() {
|
||||||
selectLayout('#zmMontageLayout');
|
selectLayout('#zmMontageLayout');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for ( var x = 0; x < monitors.length; x++ ) {
|
for ( var i = 0, length = monitors.length; i < length; i++ ) {
|
||||||
var monitor = monitors[x];
|
var monitor = monitors[i];
|
||||||
var newWidth = ( monitorData[x].width * scale ) / SCALE_BASE;
|
var newWidth = ( monitorData[i].width * scale ) / SCALE_BASE;
|
||||||
var newHeight = ( monitorData[x].height * scale ) / SCALE_BASE;
|
var newHeight = ( monitorData[i].height * scale ) / SCALE_BASE;
|
||||||
|
|
||||||
// Scale the frame
|
// Scale the frame
|
||||||
monitor_frame = $j('#monitorFrame'+monitor.id);
|
monitor_frame = $j('#monitorFrame'+monitor.id);
|
||||||
|
@ -342,10 +346,10 @@ function edit_layout(button) {
|
||||||
|
|
||||||
// Turn off the onclick on the image.
|
// Turn off the onclick on the image.
|
||||||
|
|
||||||
for ( var i = 0; i < monitors.length; i++ ) {
|
for ( var i = 0, length = monitors.length; i < length; i++ ) {
|
||||||
var monitor = monitors[i];
|
var monitor = monitors[i];
|
||||||
monitor_feed = $j('#imageFeed'+monitor.id)[0];
|
monitor_feed = $j('#imageFeed'+monitor.id)[0];
|
||||||
monitor_feed.click('');
|
monitor_feed.onclick = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
$j('#monitors .monitorFrame').draggable({
|
$j('#monitors .monitorFrame').draggable({
|
||||||
|
@ -360,7 +364,7 @@ function save_layout(button) {
|
||||||
var form = button.form;
|
var form = button.form;
|
||||||
// In fixed positioning, order doesn't matter. In floating positioning, it does.
|
// In fixed positioning, order doesn't matter. In floating positioning, it does.
|
||||||
var Positions = {};
|
var Positions = {};
|
||||||
for ( var i = 0; i < monitors.length; i++ ) {
|
for ( var i = 0, length = monitors.length; i < lenth; i++ ) {
|
||||||
var monitor = monitors[i];
|
var monitor = monitors[i];
|
||||||
monitor_frame = $j('#monitorFrame'+monitor.id);
|
monitor_frame = $j('#monitorFrame'+monitor.id);
|
||||||
|
|
||||||
|
@ -377,11 +381,12 @@ function save_layout(button) {
|
||||||
} // end foreach monitor
|
} // end foreach monitor
|
||||||
form.Positions.value = JSON.stringify(Positions);
|
form.Positions.value = JSON.stringify(Positions);
|
||||||
form.submit();
|
form.submit();
|
||||||
}
|
} // end function save_layout
|
||||||
|
|
||||||
function cancel_layout(button) {
|
function cancel_layout(button) {
|
||||||
$j('#SaveLayout').hide();
|
$j('#SaveLayout').hide();
|
||||||
$j('#EditLayout').show();
|
$j('#EditLayout').show();
|
||||||
for ( var i = 0; i < monitors.length; i++ ) {
|
for ( var i = 0, length = monitors.length; i < length; i++ ) {
|
||||||
var monitor = monitors[i];
|
var monitor = monitors[i];
|
||||||
monitor_feed = $j('#imageFeed'+monitor.id);
|
monitor_feed = $j('#imageFeed'+monitor.id);
|
||||||
monitor_feed.click(monitor.onclick);
|
monitor_feed.click(monitor.onclick);
|
||||||
|
@ -409,25 +414,19 @@ function initPage() {
|
||||||
jQuery("#hdrbutton").toggleClass('glyphicon-menu-down').toggleClass('glyphicon-menu-up');
|
jQuery("#hdrbutton").toggleClass('glyphicon-menu-down').toggleClass('glyphicon-menu-up');
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( var i = 0; i < monitorData.length; i++ ) {
|
for ( var i = 0, length = monitorData.length; i < length; i++ ) {
|
||||||
monitors[i] = new Monitor(monitorData[i]);
|
monitors[i] = new Monitor(monitorData[i]);
|
||||||
|
|
||||||
|
// Start the fps and status updates. give a random delay so that we don't assault the server
|
||||||
var delay = Math.round( (Math.random()+0.5)*statusRefreshTimeout );
|
var delay = Math.round( (Math.random()+0.5)*statusRefreshTimeout );
|
||||||
var interval = monitors[i].refresh;
|
|
||||||
monitors[i].start(delay);
|
monitors[i].start(delay);
|
||||||
|
|
||||||
|
var interval = monitors[i].refresh;
|
||||||
if ( monitors[i].type == 'WebSite' && interval > 0 ) {
|
if ( monitors[i].type == 'WebSite' && interval > 0 ) {
|
||||||
setInterval(reloadWebSite, interval*1000, i);
|
setInterval(reloadWebSite, interval*1000, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectLayout('#zmMontageLayout');
|
selectLayout('#zmMontageLayout');
|
||||||
|
|
||||||
for ( var i = 0; i < monitorData.length; i++ ) {
|
|
||||||
if ( monitors[i].type == 'WebSite' )
|
|
||||||
continue;
|
|
||||||
var delay = Math.round( (Math.random()+0.75)*statusRefreshTimeout );
|
|
||||||
console.log("Delay for monitor " + monitorData[i].id + " is " + delay );
|
|
||||||
monitors[i].streamCmdQuery.delay( delay, monitors[i] );
|
|
||||||
//monitors[i].zm_startup(delay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Kick everything off
|
// Kick everything off
|
||||||
window.addEvent('domready', initPage);
|
window.addEvent('domready', initPage);
|
||||||
|
|
Loading…
Reference in New Issue